@@ -65,13 +65,18 @@ bitflags! {
6565 // pointer comparisons, ptr-to-int casts, etc.
6666 const NOT_CONST = 1 << 6 ,
6767
68+ // Refers to temporaries which cannot be promoted as
69+ // promote_consts decided they weren't simple enough.
70+ const NOT_PROMOTABLE = 1 << 7 ,
71+
6872 // Borrows of temporaries can be promoted only
6973 // if they have none of the above qualifications.
70- const UNPROMOTABLE = !0 ,
74+ const NEVER_PROMOTE = !0 ,
7175
7276 // Const items can only have MUTABLE_INTERIOR
73- // without producing an error.
74- const CONST_ERROR = !Qualif :: MUTABLE_INTERIOR . bits
77+ // and NOT_PROMOTABLE without producing an error.
78+ const CONST_ERROR = !Qualif :: MUTABLE_INTERIOR . bits &
79+ !Qualif :: NOT_PROMOTABLE . bits
7580 }
7681}
7782
@@ -502,6 +507,10 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx> {
502507 self . add ( Qualif :: NOT_CONST ) ;
503508 }
504509 Lvalue :: Temp ( index) => {
510+ if !self . temp_promotion_state [ index as usize ] . is_promotable ( ) {
511+ self . add ( Qualif :: NOT_PROMOTABLE ) ;
512+ }
513+
505514 if let Some ( qualif) = self . temp_qualif [ index as usize ] {
506515 self . add ( qualif) ;
507516 } else {
@@ -687,8 +696,11 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx> {
687696 // We might have a candidate for promotion.
688697 let candidate = Candidate :: Ref ( self . location ) ;
689698 if self . mode == Mode :: Fn || self . mode == Mode :: ConstFn {
690- if !self . qualif . intersects ( Qualif :: UNPROMOTABLE ) {
691- self . promotion_candidates . push ( candidate) ;
699+ if !self . qualif . intersects ( Qualif :: NEVER_PROMOTE ) {
700+ // We can only promote direct borrows of temps.
701+ if let Lvalue :: Temp ( _) = * lvalue {
702+ self . promotion_candidates . push ( candidate) ;
703+ }
692704 }
693705 }
694706 }
@@ -780,7 +792,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx> {
780792 this. visit_operand ( arg) ;
781793 if is_shuffle && i == 2 && this. mode == Mode :: Fn {
782794 let candidate = Candidate :: ShuffleIndices ( bb) ;
783- if !this. qualif . intersects ( Qualif :: UNPROMOTABLE ) {
795+ if !this. qualif . intersects ( Qualif :: NEVER_PROMOTE ) {
784796 this. promotion_candidates . push ( candidate) ;
785797 } else {
786798 span_err ! ( this. tcx. sess, this. span, E0526 ,
0 commit comments