@@ -77,21 +77,14 @@ pub enum TempState {
7777 /// One direct assignment and any number of direct uses.
7878 /// A borrow of this temp is promotable if the assigned
7979 /// value is qualified as constant.
80- Defined { location : Location , uses : usize , valid : Valid } ,
80+ Defined { location : Location , uses : usize , valid : Result < ( ) , ( ) > } ,
8181 /// Any other combination of assignments/uses.
8282 Unpromotable ,
8383 /// This temp was part of an rvalue which got extracted
8484 /// during promotion and needs cleanup.
8585 PromotedOut ,
8686}
8787
88- #[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
89- pub enum Valid {
90- Unknown ,
91- InValid ,
92- Validated ,
93- }
94-
9588impl TempState {
9689 pub fn is_promotable ( & self ) -> bool {
9790 debug ! ( "is_promotable: self={:?}" , self ) ;
@@ -140,7 +133,7 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {
140133 match context {
141134 PlaceContext :: MutatingUse ( MutatingUseContext :: Store )
142135 | PlaceContext :: MutatingUse ( MutatingUseContext :: Call ) => {
143- * temp = TempState :: Defined { location, uses : 0 , valid : Valid :: Unknown } ;
136+ * temp = TempState :: Defined { location, uses : 0 , valid : Err ( ( ) ) } ;
144137 return ;
145138 }
146139 _ => { /* mark as unpromotable below */ }
@@ -281,54 +274,42 @@ impl<'tcx> Validator<'_, 'tcx> {
281274
282275 fn validate_local ( & mut self , local : Local ) -> Result < ( ) , Unpromotable > {
283276 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+ ) ;
303292 }
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) ;
318303 }
319304 }
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+ } )
332313 } else {
333314 Err ( Unpromotable )
334315 }
0 commit comments