/// Checks that the constant's `ty` field matches up with what
/// would be expected from its literal.
Checks that the constant's `ty` field matches up with what
would be expected from its literal.
Checks that the constant ' s ` ty ` field matches up with what would be expected from its literal .
fn sanitize_constant(&mut self, constant: &Constant<'tcx>, location: Location) {
        debug!(
            "sanitize_constant(constant={:?}, location={:?})",
            constant, location
        );
        // FIXME(#46702) -- We need some way to get the predicates
        // associated with the "pre-evaluated" form of the
        // constant. For example, consider that the constant
        // may have associated constant projections (`<Foo as
        // Trait<'a, 'b>>::SOME_CONST`) that impose
        // constraints on `'a` and `'b`. These constraints
        // would be lost if we just look at the normalized
        // value.
        if let ty::TyFnDef(def_id, substs) = constant.literal.ty.sty {
            let tcx = self.tcx();
            let type_checker = &mut self.cx;
            // FIXME -- For now, use the substitutions from
            // `value.ty` rather than `value.val`. The
            // renumberer will rewrite them to independent
            // sets of regions; in principle, we ought to
            // derive the type of the `value.val` from "first
            // principles" and equate with value.ty, but as we
            // are transitioning to the miri-based system, we
            // don't have a handy function for that, so for
            // now we just ignore `value.val` regions.
            let instantiated_predicates = tcx.predicates_of(def_id).instantiate(tcx, substs);
            type_checker.normalize_and_prove_instantiated_predicates(
                instantiated_predicates,
                location.boring(),
            );
        }
        debug!("sanitize_constant: expected_ty={:?}", constant.literal.ty);
        if let Err(terr) = self
            .cx
            .eq_types(constant.literal.ty, constant.ty, location.boring())
        {
            span_mirbug!(
                self,
                constant,
                "constant {:?} should have type {:?} but has {:?} ({:?})",
                constant,
                constant.literal.ty,
                constant.ty,
                terr,
            );
        }
    }
fn sanitize_constant ( & mut self , constant : & Constant < ' tcx > , location : Location ) { debug ! ( " " constant location ) ; // FIXME(#46702) -- We need some way to get the predicates // associated with the "pre-evaluated" form of the // constant. For example, consider that the constant // may have associated constant projections (`<Foo as // Trait<'a, 'b>>::SOME_CONST`) that impose // constraints on `'a` and `'b`. These constraints // would be lost if we just look at the normalized // value. if let ty :: TyFnDef ( def_id , substs ) = constant . literal . ty . sty { let tcx = self . tcx ( ) ; let type_checker = & mut self . cx ; // FIXME -- For now, use the substitutions from // `value.ty` rather than `value.val`. The // renumberer will rewrite them to independent // sets of regions; in principle, we ought to // derive the type of the `value.val` from "first // principles" and equate with value.ty, but as we // are transitioning to the miri-based system, we // don't have a handy function for that, so for // now we just ignore `value.val` regions. let instantiated_predicates = tcx . predicates_of ( def_id ) . instantiate ( tcx , substs ) ; type_checker . normalize_and_prove_instantiated_predicates ( instantiated_predicates , location . boring ( ) , ) ; } debug ! ( " " constant literal ty ) ; if let Err ( terr ) = self . cx . eq_types ( constant . literal . ty , constant . ty , location . boring ( ) ) { span_mirbug ! ( self constant " " constant constant literal ty constant ty terr ) ; } }
Checks that the constant's `ty` field matches up with what
would be expected from its literal.
Checks that the constant ' s ` ty ` field matches up with what would be expected from its literal .
&mut self
constant
&Constant<'tcx>
location
Location