@@ -466,33 +466,6 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
466466
467467 let mut place_ty = PlaceTy :: from_ty ( self . body . local_decls [ place. local ] . ty ) ;
468468
469- if place. projection . is_empty ( ) {
470- if let PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: Copy ) = context {
471- let tcx = self . tcx ( ) ;
472- let trait_ref = ty:: TraitRef {
473- def_id : tcx. lang_items ( ) . copy_trait ( ) . unwrap ( ) ,
474- substs : tcx. mk_substs_trait ( place_ty. ty , & [ ] ) ,
475- } ;
476-
477- // To have a `Copy` operand, the type `T` of the
478- // value must be `Copy`. Note that we prove that `T: Copy`,
479- // rather than using the `is_copy_modulo_regions`
480- // test. This is important because
481- // `is_copy_modulo_regions` ignores the resulting region
482- // obligations and assumes they pass. This can result in
483- // bounds from `Copy` impls being unsoundly ignored (e.g.,
484- // #29149). Note that we decide to use `Copy` before knowing
485- // whether the bounds fully apply: in effect, the rule is
486- // that if a value of some type could implement `Copy`, then
487- // it must.
488- self . cx . prove_trait_ref (
489- trait_ref,
490- location. to_locations ( ) ,
491- ConstraintCategory :: CopyBound ,
492- ) ;
493- }
494- }
495-
496469 for elem in place. projection . iter ( ) {
497470 if place_ty. variant_index . is_none ( ) {
498471 if place_ty. ty . references_error ( ) {
@@ -503,6 +476,31 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
503476 place_ty = self . sanitize_projection ( place_ty, elem, place, location)
504477 }
505478
479+ if let PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: Copy ) = context {
480+ let tcx = self . tcx ( ) ;
481+ let trait_ref = ty:: TraitRef {
482+ def_id : tcx. lang_items ( ) . copy_trait ( ) . unwrap ( ) ,
483+ substs : tcx. mk_substs_trait ( place_ty. ty , & [ ] ) ,
484+ } ;
485+
486+ // To have a `Copy` operand, the type `T` of the
487+ // value must be `Copy`. Note that we prove that `T: Copy`,
488+ // rather than using the `is_copy_modulo_regions`
489+ // test. This is important because
490+ // `is_copy_modulo_regions` ignores the resulting region
491+ // obligations and assumes they pass. This can result in
492+ // bounds from `Copy` impls being unsoundly ignored (e.g.,
493+ // #29149). Note that we decide to use `Copy` before knowing
494+ // whether the bounds fully apply: in effect, the rule is
495+ // that if a value of some type could implement `Copy`, then
496+ // it must.
497+ self . cx . prove_trait_ref (
498+ trait_ref,
499+ location. to_locations ( ) ,
500+ ConstraintCategory :: CopyBound ,
501+ ) ;
502+ }
503+
506504 place_ty
507505 }
508506
0 commit comments