pub fn mir_to_const<'tcx>(
tcx: TyCtxt<'tcx>,
val: ConstValue,
ty: Ty<'tcx>,
) -> Option<Constant>Expand description
Converts a [ConstValue] to a Constant, if possible.
- If
tyis anAdtdescribing a struct, returns aConstant::Adtcontainingval. - If
valis aInt,tydetermines the variant of the returned constant:Bool→Constant::BoolUint/Int→Constant::IntFloat→Constant::F16/Constant::F32/Constant::F64/Constant::F128, depending on widthRawPtr→Constant::RawPtr- any other
ty→None
- If
tyis aRefreferring to aStr(i.e. a&str), returns aConstant::Str. - If
valis a [ConstValue::Indirect] andtyis anArrayofFloat, returns aConstant::Vec
Otherwise, returns None.