@@ -310,6 +310,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
310
310
) ;
311
311
}
312
312
} else {
313
+ let tcx = self . tcx ( ) ;
313
314
if let ty:: ConstKind :: Unevaluated ( def_id, substs, promoted) = constant. literal . val {
314
315
if let Some ( promoted) = promoted {
315
316
let check_err = |verifier : & mut TypeVerifier < ' a , ' b , ' tcx > ,
@@ -359,10 +360,23 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
359
360
) ;
360
361
}
361
362
}
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
+ }
362
377
}
363
- if let ty:: FnDef ( def_id, substs) = constant. literal . ty . kind {
364
- let tcx = self . tcx ( ) ;
365
378
379
+ if let ty:: FnDef ( def_id, substs) = constant. literal . ty . kind {
366
380
let instantiated_predicates = tcx. predicates_of ( def_id) . instantiate ( tcx, substs) ;
367
381
self . cx . normalize_and_prove_instantiated_predicates (
368
382
instantiated_predicates,
@@ -467,33 +481,6 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
467
481
468
482
let mut place_ty = PlaceTy :: from_ty ( self . body . local_decls [ place. local ] . ty ) ;
469
483
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
-
497
484
for elem in place. projection . iter ( ) {
498
485
if place_ty. variant_index . is_none ( ) {
499
486
if place_ty. ty . references_error ( ) {
@@ -504,6 +491,31 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
504
491
place_ty = self . sanitize_projection ( place_ty, elem, place, location)
505
492
}
506
493
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
+
507
519
place_ty
508
520
}
509
521
0 commit comments