@@ -22,7 +22,7 @@ use rustc_middle::ty::cast::CastTy;
2222use rustc_middle:: ty:: subst:: InternalSubsts ;
2323use rustc_middle:: ty:: { self , List , TyCtxt , TypeFoldable } ;
2424use rustc_span:: symbol:: sym;
25- use rustc_span:: { Span , DUMMY_SP } ;
25+ use rustc_span:: Span ;
2626
2727use rustc_index:: vec:: { Idx , IndexVec } ;
2828use rustc_target:: spec:: abi:: Abi ;
@@ -326,41 +326,16 @@ impl<'tcx> Validator<'_, 'tcx> {
326326 if place. projection . contains ( & ProjectionElem :: Deref ) {
327327 return Err ( Unpromotable ) ;
328328 }
329-
330- let mut has_mut_interior =
331- self . qualif_local :: < qualifs:: HasMutInterior > ( place. local ) ;
332- // HACK(eddyb) this should compute the same thing as
333- // `<HasMutInterior as Qualif>::in_projection` from
334- // `check_consts::qualifs` but without recursion.
335- if has_mut_interior {
336- // This allows borrowing fields which don't have
337- // `HasMutInterior`, from a type that does, e.g.:
338- // `let _: &'static _ = &(Cell::new(1), 2).1;`
339- let mut place_projection = & place. projection [ ..] ;
340- // FIXME(eddyb) use a forward loop instead of a reverse one.
341- while let & [ ref proj_base @ .., elem] = place_projection {
342- // FIXME(eddyb) this is probably excessive, with
343- // the exception of `union` member accesses.
344- let ty =
345- Place :: ty_from ( place. local , proj_base, self . body , self . tcx )
346- . projection_ty ( self . tcx , elem)
347- . ty ;
348- if ty. is_freeze ( self . tcx . at ( DUMMY_SP ) , self . param_env ) {
349- has_mut_interior = false ;
350- break ;
351- }
352-
353- place_projection = proj_base;
354- }
329+ if self . qualif_local :: < qualifs:: NeedsDrop > ( place. local ) {
330+ return Err ( Unpromotable ) ;
355331 }
356332
357333 // FIXME(eddyb) this duplicates part of `validate_rvalue`.
334+ let has_mut_interior =
335+ self . qualif_local :: < qualifs:: HasMutInterior > ( place. local ) ;
358336 if has_mut_interior {
359337 return Err ( Unpromotable ) ;
360338 }
361- if self . qualif_local :: < qualifs:: NeedsDrop > ( place. local ) {
362- return Err ( Unpromotable ) ;
363- }
364339
365340 if let BorrowKind :: Mut { .. } = kind {
366341 let ty = place. ty ( self . body , self . tcx ) . ty ;
@@ -692,28 +667,7 @@ impl<'tcx> Validator<'_, 'tcx> {
692667
693668 self . validate_place ( place) ?;
694669
695- // HACK(eddyb) this should compute the same thing as
696- // `<HasMutInterior as Qualif>::in_projection` from
697- // `check_consts::qualifs` but without recursion.
698- let mut has_mut_interior =
699- self . qualif_local :: < qualifs:: HasMutInterior > ( place. local ) ;
700- if has_mut_interior {
701- let mut place_projection = place. projection ;
702- // FIXME(eddyb) use a forward loop instead of a reverse one.
703- while let & [ ref proj_base @ .., elem] = place_projection {
704- // FIXME(eddyb) this is probably excessive, with
705- // the exception of `union` member accesses.
706- let ty = Place :: ty_from ( place. local , proj_base, self . body , self . tcx )
707- . projection_ty ( self . tcx , elem)
708- . ty ;
709- if ty. is_freeze ( self . tcx . at ( DUMMY_SP ) , self . param_env ) {
710- has_mut_interior = false ;
711- break ;
712- }
713-
714- place_projection = proj_base;
715- }
716- }
670+ let has_mut_interior = self . qualif_local :: < qualifs:: HasMutInterior > ( place. local ) ;
717671 if has_mut_interior {
718672 return Err ( Unpromotable ) ;
719673 }
0 commit comments