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