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