@@ -310,6 +310,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
310310 ) ;
311311 }
312312 } else {
313+ let tcx = self . tcx ( ) ;
313314 if let ty:: ConstKind :: Unevaluated ( def_id, substs, promoted) = constant. literal . val {
314315 if let Some ( promoted) = promoted {
315316 let check_err = |verifier : & mut TypeVerifier < ' a , ' b , ' tcx > ,
@@ -359,10 +360,23 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
359360 ) ;
360361 }
361362 }
363+ } else if let Some ( static_def_id) = constant. check_static_ptr ( tcx) {
364+ let unnormalized_ty = tcx. type_of ( static_def_id) ;
365+ let locations = location. to_locations ( ) ;
366+ let normalized_ty = self . cx . normalize ( unnormalized_ty, locations) ;
367+ let literal_ty = constant. literal . ty . builtin_deref ( true ) . unwrap ( ) . ty ;
368+
369+ if let Err ( terr) = self . cx . eq_types (
370+ normalized_ty,
371+ literal_ty,
372+ locations,
373+ ConstraintCategory :: Boring ,
374+ ) {
375+ span_mirbug ! ( self , constant, "bad static type {:?} ({:?})" , constant, terr) ;
376+ }
362377 }
363- if let ty:: FnDef ( def_id, substs) = constant. literal . ty . kind {
364- let tcx = self . tcx ( ) ;
365378
379+ if let ty:: FnDef ( def_id, substs) = constant. literal . ty . kind {
366380 let instantiated_predicates = tcx. predicates_of ( def_id) . instantiate ( tcx, substs) ;
367381 self . cx . normalize_and_prove_instantiated_predicates (
368382 instantiated_predicates,
@@ -467,33 +481,6 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
467481
468482 let mut place_ty = PlaceTy :: from_ty ( self . body . local_decls [ place. local ] . ty ) ;
469483
470- if place. projection . is_empty ( ) {
471- if let PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: Copy ) = context {
472- let tcx = self . tcx ( ) ;
473- let trait_ref = ty:: TraitRef {
474- def_id : tcx. lang_items ( ) . copy_trait ( ) . unwrap ( ) ,
475- substs : tcx. mk_substs_trait ( place_ty. ty , & [ ] ) ,
476- } ;
477-
478- // To have a `Copy` operand, the type `T` of the
479- // value must be `Copy`. Note that we prove that `T: Copy`,
480- // rather than using the `is_copy_modulo_regions`
481- // test. This is important because
482- // `is_copy_modulo_regions` ignores the resulting region
483- // obligations and assumes they pass. This can result in
484- // bounds from `Copy` impls being unsoundly ignored (e.g.,
485- // #29149). Note that we decide to use `Copy` before knowing
486- // whether the bounds fully apply: in effect, the rule is
487- // that if a value of some type could implement `Copy`, then
488- // it must.
489- self . cx . prove_trait_ref (
490- trait_ref,
491- location. to_locations ( ) ,
492- ConstraintCategory :: CopyBound ,
493- ) ;
494- }
495- }
496-
497484 for elem in place. projection . iter ( ) {
498485 if place_ty. variant_index . is_none ( ) {
499486 if place_ty. ty . references_error ( ) {
@@ -504,6 +491,31 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
504491 place_ty = self . sanitize_projection ( place_ty, elem, place, location)
505492 }
506493
494+ if let PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: Copy ) = context {
495+ let tcx = self . tcx ( ) ;
496+ let trait_ref = ty:: TraitRef {
497+ def_id : tcx. lang_items ( ) . copy_trait ( ) . unwrap ( ) ,
498+ substs : tcx. mk_substs_trait ( place_ty. ty , & [ ] ) ,
499+ } ;
500+
501+ // To have a `Copy` operand, the type `T` of the
502+ // value must be `Copy`. Note that we prove that `T: Copy`,
503+ // rather than using the `is_copy_modulo_regions`
504+ // test. This is important because
505+ // `is_copy_modulo_regions` ignores the resulting region
506+ // obligations and assumes they pass. This can result in
507+ // bounds from `Copy` impls being unsoundly ignored (e.g.,
508+ // #29149). Note that we decide to use `Copy` before knowing
509+ // whether the bounds fully apply: in effect, the rule is
510+ // that if a value of some type could implement `Copy`, then
511+ // it must.
512+ self . cx . prove_trait_ref (
513+ trait_ref,
514+ location. to_locations ( ) ,
515+ ConstraintCategory :: CopyBound ,
516+ ) ;
517+ }
518+
507519 place_ty
508520 }
509521
0 commit comments