@@ -110,48 +110,46 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> {
110110                // we must make sure that all `target as Variant#i` are `Top`. 
111111                state. flood ( target. as_ref ( ) ,  self . map ( ) ) ; 
112112
113-                 if  let  Some ( target_idx)  = self . map ( ) . find ( target. as_ref ( ) )  { 
114-                     let  ( variant_target,  variant_index)  = match  * * kind { 
115-                         AggregateKind :: Tuple  | AggregateKind :: Closure ( ..)  => { 
116-                             ( Some ( target_idx) ,  None ) 
117-                         } 
118-                         AggregateKind :: Adt ( def_id,  variant_index,  ..)  => { 
119-                             match  self . tcx . def_kind ( def_id)  { 
120-                                 DefKind :: Struct  => ( Some ( target_idx) ,  None ) , 
121-                                 DefKind :: Enum  => ( 
122-                                     self . map . apply ( target_idx,  TrackElem :: Variant ( variant_index) ) , 
123-                                     Some ( variant_index) , 
124-                                 ) , 
125-                                 _ => ( None ,  None ) , 
126-                             } 
127-                         } 
128-                         _ => ( None ,  None ) , 
129-                     } ; 
130-                     if  let  Some ( variant_target_idx)  = variant_target { 
131-                         for  ( field_index,  operand)  in  operands. iter ( ) . enumerate ( )  { 
132-                             if  let  Some ( field)  = self . map ( ) . apply ( 
133-                                 variant_target_idx, 
134-                                 TrackElem :: Field ( FieldIdx :: from_usize ( field_index) ) , 
135-                             )  { 
136-                                 let  result = self . handle_operand ( operand,  state) ; 
137-                                 state. insert_idx ( field,  result,  self . map ( ) ) ; 
138-                             } 
113+                 let  Some ( target_idx)  = self . map ( ) . find ( target. as_ref ( ) )  else  {  return  } ; 
114+ 
115+                 let  ( variant_target,  variant_index)  = match  * * kind { 
116+                     AggregateKind :: Tuple  | AggregateKind :: Closure ( ..)  => ( Some ( target_idx) ,  None ) , 
117+                     AggregateKind :: Adt ( def_id,  variant_index,  ..)  => { 
118+                         match  self . tcx . def_kind ( def_id)  { 
119+                             DefKind :: Struct  => ( Some ( target_idx) ,  None ) , 
120+                             DefKind :: Enum  => ( 
121+                                 self . map . apply ( target_idx,  TrackElem :: Variant ( variant_index) ) , 
122+                                 Some ( variant_index) , 
123+                             ) , 
124+                             _ => return , 
139125                        } 
140126                    } 
141-                     if  let  Some ( variant_index)  = variant_index
142-                         && let  Some ( discr_idx)  = self . map ( ) . apply ( target_idx,  TrackElem :: Discriminant ) 
143-                     { 
144-                         // We are assigning the discriminant as part of an aggregate. 
145-                         // This discriminant can only alias a variant field's value if the operand 
146-                         // had an invalid value for that type. 
147-                         // Using invalid values is UB, so we are allowed to perform the assignment 
148-                         // without extra flooding. 
149-                         let  enum_ty = target. ty ( self . local_decls ,  self . tcx ) . ty ; 
150-                         if  let  Some ( discr_val)  = self . eval_discriminant ( enum_ty,  variant_index)  { 
151-                             state. insert_value_idx ( discr_idx,  FlatSet :: Elem ( discr_val) ,  & self . map ) ; 
127+                     _ => return , 
128+                 } ; 
129+                 if  let  Some ( variant_target_idx)  = variant_target { 
130+                     for  ( field_index,  operand)  in  operands. iter ( ) . enumerate ( )  { 
131+                         if  let  Some ( field)  = self . map ( ) . apply ( 
132+                             variant_target_idx, 
133+                             TrackElem :: Field ( FieldIdx :: from_usize ( field_index) ) , 
134+                         )  { 
135+                             let  result = self . handle_operand ( operand,  state) ; 
136+                             state. insert_idx ( field,  result,  self . map ( ) ) ; 
152137                        } 
153138                    } 
154139                } 
140+                 if  let  Some ( variant_index)  = variant_index
141+                     && let  Some ( discr_idx)  = self . map ( ) . apply ( target_idx,  TrackElem :: Discriminant ) 
142+                 { 
143+                     // We are assigning the discriminant as part of an aggregate. 
144+                     // This discriminant can only alias a variant field's value if the operand 
145+                     // had an invalid value for that type. 
146+                     // Using invalid values is UB, so we are allowed to perform the assignment 
147+                     // without extra flooding. 
148+                     let  enum_ty = target. ty ( self . local_decls ,  self . tcx ) . ty ; 
149+                     if  let  Some ( discr_val)  = self . eval_discriminant ( enum_ty,  variant_index)  { 
150+                         state. insert_value_idx ( discr_idx,  FlatSet :: Elem ( discr_val) ,  & self . map ) ; 
151+                     } 
152+                 } 
155153            } 
156154            Rvalue :: CheckedBinaryOp ( op,  box ( left,  right) )  => { 
157155                // Flood everything now, so we can use `insert_value_idx` directly later. 
0 commit comments