@@ -65,13 +65,18 @@ bitflags! {
65
65
// pointer comparisons, ptr-to-int casts, etc.
66
66
const NOT_CONST = 1 << 6 ,
67
67
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
+
68
72
// Borrows of temporaries can be promoted only
69
73
// if they have none of the above qualifications.
70
- const UNPROMOTABLE = !0 ,
74
+ const NEVER_PROMOTE = !0 ,
71
75
72
76
// 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
75
80
}
76
81
}
77
82
@@ -502,6 +507,10 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx> {
502
507
self . add ( Qualif :: NOT_CONST ) ;
503
508
}
504
509
Lvalue :: Temp ( index) => {
510
+ if !self . temp_promotion_state [ index as usize ] . is_promotable ( ) {
511
+ self . add ( Qualif :: NOT_PROMOTABLE ) ;
512
+ }
513
+
505
514
if let Some ( qualif) = self . temp_qualif [ index as usize ] {
506
515
self . add ( qualif) ;
507
516
} else {
@@ -687,8 +696,11 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx> {
687
696
// We might have a candidate for promotion.
688
697
let candidate = Candidate :: Ref ( self . location ) ;
689
698
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
+ }
692
704
}
693
705
}
694
706
}
@@ -780,7 +792,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx> {
780
792
this. visit_operand ( arg) ;
781
793
if is_shuffle && i == 2 && this. mode == Mode :: Fn {
782
794
let candidate = Candidate :: ShuffleIndices ( bb) ;
783
- if !this. qualif . intersects ( Qualif :: UNPROMOTABLE ) {
795
+ if !this. qualif . intersects ( Qualif :: NEVER_PROMOTE ) {
784
796
this. promotion_candidates . push ( candidate) ;
785
797
} else {
786
798
span_err ! ( this. tcx. sess, this. span, E0526 ,
0 commit comments