@@ -83,52 +83,49 @@ struct TempCollector<'tcx> {
83
83
}
84
84
85
85
impl < ' tcx > Visitor < ' tcx > for TempCollector < ' tcx > {
86
- fn visit_lvalue ( & mut self ,
87
- lvalue : & Lvalue < ' tcx > ,
88
- context : LvalueContext < ' tcx > ,
89
- location : Location ) {
90
- self . super_lvalue ( lvalue, context, location) ;
91
- if let Lvalue :: Local ( index) = * lvalue {
92
- // We're only interested in temporaries
93
- if self . mir . local_kind ( index) != LocalKind :: Temp {
94
- return ;
95
- }
86
+ fn visit_local ( & mut self ,
87
+ & index: & Local ,
88
+ context : LvalueContext < ' tcx > ,
89
+ location : Location ) {
90
+ // We're only interested in temporaries
91
+ if self . mir . local_kind ( index) != LocalKind :: Temp {
92
+ return ;
93
+ }
96
94
97
- // Ignore drops, if the temp gets promoted,
98
- // then it's constant and thus drop is noop.
99
- // Storage live ranges are also irrelevant.
100
- if context. is_drop ( ) || context. is_storage_marker ( ) {
101
- return ;
102
- }
95
+ // Ignore drops, if the temp gets promoted,
96
+ // then it's constant and thus drop is noop.
97
+ // Storage live ranges are also irrelevant.
98
+ if context. is_drop ( ) || context. is_storage_marker ( ) {
99
+ return ;
100
+ }
103
101
104
- let temp = & mut self . temps [ index] ;
105
- if * temp == TempState :: Undefined {
106
- match context {
107
- LvalueContext :: Store |
108
- LvalueContext :: Call => {
109
- * temp = TempState :: Defined {
110
- location,
111
- uses : 0
112
- } ;
113
- return ;
114
- }
115
- _ => { /* mark as unpromotable below */ }
116
- }
117
- } else if let TempState :: Defined { ref mut uses, .. } = * temp {
118
- // We always allow borrows, even mutable ones, as we need
119
- // to promote mutable borrows of some ZSTs e.g. `&mut []`.
120
- let allowed_use = match context {
121
- LvalueContext :: Borrow { ..} => true ,
122
- _ => context. is_nonmutating_use ( )
123
- } ;
124
- if allowed_use {
125
- * uses += 1 ;
102
+ let temp = & mut self . temps [ index] ;
103
+ if * temp == TempState :: Undefined {
104
+ match context {
105
+ LvalueContext :: Store |
106
+ LvalueContext :: Call => {
107
+ * temp = TempState :: Defined {
108
+ location,
109
+ uses : 0
110
+ } ;
126
111
return ;
127
112
}
128
- /* mark as unpromotable below */
113
+ _ => { /* mark as unpromotable below */ }
129
114
}
130
- * temp = TempState :: Unpromotable ;
115
+ } else if let TempState :: Defined { ref mut uses, .. } = * temp {
116
+ // We always allow borrows, even mutable ones, as we need
117
+ // to promote mutable borrows of some ZSTs e.g. `&mut []`.
118
+ let allowed_use = match context {
119
+ LvalueContext :: Borrow { ..} => true ,
120
+ _ => context. is_nonmutating_use ( )
121
+ } ;
122
+ if allowed_use {
123
+ * uses += 1 ;
124
+ return ;
125
+ }
126
+ /* mark as unpromotable below */
131
127
}
128
+ * temp = TempState :: Unpromotable ;
132
129
}
133
130
134
131
fn visit_source_info ( & mut self , source_info : & SourceInfo ) {
@@ -326,16 +323,13 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
326
323
327
324
/// Replaces all temporaries with their promoted counterparts.
328
325
impl < ' a , ' tcx > MutVisitor < ' tcx > for Promoter < ' a , ' tcx > {
329
- fn visit_lvalue ( & mut self ,
330
- lvalue : & mut Lvalue < ' tcx > ,
331
- context : LvalueContext < ' tcx > ,
332
- location : Location ) {
333
- if let Lvalue :: Local ( ref mut temp) = * lvalue {
334
- if self . source . local_kind ( * temp) == LocalKind :: Temp {
335
- * temp = self . promote_temp ( * temp) ;
336
- }
326
+ fn visit_local ( & mut self ,
327
+ local : & mut Local ,
328
+ _: LvalueContext < ' tcx > ,
329
+ _: Location ) {
330
+ if self . source . local_kind ( * local) == LocalKind :: Temp {
331
+ * local = self . promote_temp ( * local) ;
337
332
}
338
- self . super_lvalue ( lvalue, context, location) ;
339
333
}
340
334
}
341
335
0 commit comments