@@ -64,13 +64,18 @@ bitflags! {
64
64
// pointer comparisons, ptr-to-int casts, etc.
65
65
const NOT_CONST = 1 << 6 ,
66
66
67
+ // Refers to temporaries which cannot be promoted as
68
+ // promote_consts decided they weren't simple enough.
69
+ const NOT_PROMOTABLE = 1 << 7 ,
70
+
67
71
// Borrows of temporaries can be promoted only
68
72
// if they have none of the above qualifications.
69
- const UNPROMOTABLE = !0 ,
73
+ const NEVER_PROMOTE = !0 ,
70
74
71
75
// Const items can only have MUTABLE_INTERIOR
72
- // without producing an error.
73
- const CONST_ERROR = !Qualif :: MUTABLE_INTERIOR . bits
76
+ // and NOT_PROMOTABLE without producing an error.
77
+ const CONST_ERROR = !Qualif :: MUTABLE_INTERIOR . bits &
78
+ !Qualif :: NOT_PROMOTABLE . bits
74
79
}
75
80
}
76
81
@@ -503,6 +508,10 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
503
508
self . add ( Qualif :: NOT_CONST ) ;
504
509
}
505
510
Lvalue :: Temp ( index) => {
511
+ if !self . temp_promotion_state [ index as usize ] . is_promotable ( ) {
512
+ self . add ( Qualif :: NOT_PROMOTABLE ) ;
513
+ }
514
+
506
515
if let Some ( qualif) = self . temp_qualif [ index as usize ] {
507
516
self . add ( qualif) ;
508
517
} else {
@@ -688,8 +697,11 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
688
697
// We might have a candidate for promotion.
689
698
let candidate = Candidate :: Ref ( self . location ) ;
690
699
if self . mode == Mode :: Fn || self . mode == Mode :: ConstFn {
691
- if !self . qualif . intersects ( Qualif :: UNPROMOTABLE ) {
692
- self . promotion_candidates . push ( candidate) ;
700
+ if !self . qualif . intersects ( Qualif :: NEVER_PROMOTE ) {
701
+ // We can only promote direct borrows of temps.
702
+ if let Lvalue :: Temp ( _) = * lvalue {
703
+ self . promotion_candidates . push ( candidate) ;
704
+ }
693
705
}
694
706
}
695
707
}
@@ -781,7 +793,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
781
793
this. visit_operand ( arg) ;
782
794
if is_shuffle && i == 2 && this. mode == Mode :: Fn {
783
795
let candidate = Candidate :: ShuffleIndices ( bb) ;
784
- if !this. qualif . intersects ( Qualif :: UNPROMOTABLE ) {
796
+ if !this. qualif . intersects ( Qualif :: NEVER_PROMOTE ) {
785
797
this. promotion_candidates . push ( candidate) ;
786
798
} else {
787
799
span_err ! ( this. tcx. sess, this. span, E0526 ,
0 commit comments