@@ -22,7 +22,7 @@ use rustc_middle::ty::cast::CastTy;
22
22
use rustc_middle:: ty:: subst:: InternalSubsts ;
23
23
use rustc_middle:: ty:: { self , List , TyCtxt , TypeFoldable } ;
24
24
use rustc_span:: symbol:: sym;
25
- use rustc_span:: { Span , DUMMY_SP } ;
25
+ use rustc_span:: Span ;
26
26
27
27
use rustc_index:: vec:: { Idx , IndexVec } ;
28
28
use rustc_target:: spec:: abi:: Abi ;
@@ -326,41 +326,16 @@ impl<'tcx> Validator<'_, 'tcx> {
326
326
if place. projection . contains ( & ProjectionElem :: Deref ) {
327
327
return Err ( Unpromotable ) ;
328
328
}
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 ) ;
355
331
}
356
332
357
333
// FIXME(eddyb) this duplicates part of `validate_rvalue`.
334
+ let has_mut_interior =
335
+ self . qualif_local :: < qualifs:: HasMutInterior > ( place. local ) ;
358
336
if has_mut_interior {
359
337
return Err ( Unpromotable ) ;
360
338
}
361
- if self . qualif_local :: < qualifs:: NeedsDrop > ( place. local ) {
362
- return Err ( Unpromotable ) ;
363
- }
364
339
365
340
if let BorrowKind :: Mut { .. } = kind {
366
341
let ty = place. ty ( self . body , self . tcx ) . ty ;
@@ -692,28 +667,7 @@ impl<'tcx> Validator<'_, 'tcx> {
692
667
693
668
self . validate_place ( place) ?;
694
669
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 ) ;
717
671
if has_mut_interior {
718
672
return Err ( Unpromotable ) ;
719
673
}
0 commit comments