@@ -77,21 +77,14 @@ pub enum TempState {
77
77
/// One direct assignment and any number of direct uses.
78
78
/// A borrow of this temp is promotable if the assigned
79
79
/// value is qualified as constant.
80
- Defined { location : Location , uses : usize , valid : Valid } ,
80
+ Defined { location : Location , uses : usize , valid : Result < ( ) , ( ) > } ,
81
81
/// Any other combination of assignments/uses.
82
82
Unpromotable ,
83
83
/// This temp was part of an rvalue which got extracted
84
84
/// during promotion and needs cleanup.
85
85
PromotedOut ,
86
86
}
87
87
88
- #[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
89
- pub enum Valid {
90
- Unknown ,
91
- InValid ,
92
- Validated ,
93
- }
94
-
95
88
impl TempState {
96
89
pub fn is_promotable ( & self ) -> bool {
97
90
debug ! ( "is_promotable: self={:?}" , self ) ;
@@ -140,7 +133,7 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {
140
133
match context {
141
134
PlaceContext :: MutatingUse ( MutatingUseContext :: Store )
142
135
| PlaceContext :: MutatingUse ( MutatingUseContext :: Call ) => {
143
- * temp = TempState :: Defined { location, uses : 0 , valid : Valid :: Unknown } ;
136
+ * temp = TempState :: Defined { location, uses : 0 , valid : Err ( ( ) ) } ;
144
137
return ;
145
138
}
146
139
_ => { /* mark as unpromotable below */ }
@@ -281,54 +274,42 @@ impl<'tcx> Validator<'_, 'tcx> {
281
274
282
275
fn validate_local ( & mut self , local : Local ) -> Result < ( ) , Unpromotable > {
283
276
if let TempState :: Defined { location : loc, uses, valid } = self . temps [ local] {
284
- match valid {
285
- Valid :: InValid => Err ( Unpromotable ) ,
286
- Valid :: Validated => Ok ( ( ) ) ,
287
- Valid :: Unknown => {
288
- let ok = {
289
- let block = & self . body [ loc. block ] ;
290
- let num_stmts = block. statements . len ( ) ;
291
-
292
- if loc. statement_index < num_stmts {
293
- let statement = & block. statements [ loc. statement_index ] ;
294
- match & statement. kind {
295
- StatementKind :: Assign ( box ( _, rhs) ) => self . validate_rvalue ( rhs) ,
296
- _ => {
297
- span_bug ! (
298
- statement. source_info. span,
299
- "{:?} is not an assignment" ,
300
- statement
301
- ) ;
302
- }
277
+ valid. or_else ( |_| {
278
+ let ok = {
279
+ let block = & self . body [ loc. block ] ;
280
+ let num_stmts = block. statements . len ( ) ;
281
+
282
+ if loc. statement_index < num_stmts {
283
+ let statement = & block. statements [ loc. statement_index ] ;
284
+ match & statement. kind {
285
+ StatementKind :: Assign ( box ( _, rhs) ) => self . validate_rvalue ( rhs) ,
286
+ _ => {
287
+ span_bug ! (
288
+ statement. source_info. span,
289
+ "{:?} is not an assignment" ,
290
+ statement
291
+ ) ;
303
292
}
304
- } else {
305
- let terminator = block. terminator ( ) ;
306
- match & terminator. kind {
307
- TerminatorKind :: Call { func, args, .. } => {
308
- self . validate_call ( func, args)
309
- }
310
- TerminatorKind :: Yield { .. } => Err ( Unpromotable ) ,
311
- kind => {
312
- span_bug ! (
313
- terminator. source_info. span,
314
- "{:?} not promotable" ,
315
- kind
316
- ) ;
317
- }
293
+ }
294
+ } else {
295
+ let terminator = block. terminator ( ) ;
296
+ match & terminator. kind {
297
+ TerminatorKind :: Call { func, args, .. } => {
298
+ self . validate_call ( func, args)
299
+ }
300
+ TerminatorKind :: Yield { .. } => Err ( Unpromotable ) ,
301
+ kind => {
302
+ span_bug ! ( terminator. source_info. span, "{:?} not promotable" , kind) ;
318
303
}
319
304
}
320
- } ;
321
- self . temps [ local] = TempState :: Defined {
322
- location : loc,
323
- uses,
324
- valid : match ok {
325
- Ok ( ( ) ) => Valid :: Validated ,
326
- Err ( _) => Valid :: InValid ,
327
- } ,
328
- } ;
329
- ok
330
- }
331
- }
305
+ }
306
+ } ;
307
+ self . temps [ local] = match ok {
308
+ Ok ( ( ) ) => TempState :: Defined { location : loc, uses, valid : Ok ( ( ) ) } ,
309
+ Err ( _) => TempState :: Unpromotable ,
310
+ } ;
311
+ ok
312
+ } )
332
313
} else {
333
314
Err ( Unpromotable )
334
315
}
0 commit comments