@@ -167,12 +167,12 @@ struct ValidityVisitor<'rt, 'a: 'rt, 'mir: 'rt, 'tcx: 'a+'rt+'mir, M: Machine<'a
167
167
}
168
168
169
169
impl < ' rt , ' a , ' mir , ' tcx , M : Machine < ' a , ' mir , ' tcx > > ValidityVisitor < ' rt , ' a , ' mir , ' tcx , M > {
170
- fn push_aggregate_field_path_elem (
170
+ fn aggregate_field_path_elem (
171
171
& mut self ,
172
172
layout : TyLayout < ' tcx > ,
173
173
field : usize ,
174
- ) {
175
- let elem = match layout. ty . sty {
174
+ ) -> PathElem {
175
+ match layout. ty . sty {
176
176
// generators and closures.
177
177
ty:: Closure ( def_id, _) | ty:: Generator ( def_id, _, _) => {
178
178
if let Some ( upvar) = self . ecx . tcx . optimized_mir ( def_id) . upvar_decls . get ( field) {
@@ -194,11 +194,7 @@ impl<'rt, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> ValidityVisitor<'rt, 'a, '
194
194
layout:: Variants :: Single { index } =>
195
195
// Inside a variant
196
196
PathElem :: Field ( def. variants [ index] . fields [ field] . ident . name ) ,
197
- _ => {
198
- // Enums have no fields other than their tag
199
- assert_eq ! ( field, 0 ) ;
200
- PathElem :: Tag
201
- }
197
+ _ => bug ! ( ) ,
202
198
}
203
199
}
204
200
@@ -213,8 +209,22 @@ impl<'rt, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> ValidityVisitor<'rt, 'a, '
213
209
214
210
// nothing else has an aggregate layout
215
211
_ => bug ! ( "aggregate_field_path_elem: got non-aggregate type {:?}" , layout. ty) ,
216
- } ;
212
+ }
213
+ }
214
+
215
+ fn visit_elem (
216
+ & mut self ,
217
+ new_op : OpTy < ' tcx , M :: PointerTag > ,
218
+ elem : PathElem ,
219
+ ) -> EvalResult < ' tcx > {
220
+ // Remember the old state
221
+ let path_len = self . path . len ( ) ;
222
+ // Perform operation
217
223
self . path . push ( elem) ;
224
+ self . visit_value ( new_op) ?;
225
+ // Undo changes
226
+ self . path . truncate ( path_len) ;
227
+ Ok ( ( ) )
218
228
}
219
229
}
220
230
@@ -235,14 +245,8 @@ impl<'rt, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>>
235
245
field : usize ,
236
246
new_op : OpTy < ' tcx , M :: PointerTag >
237
247
) -> EvalResult < ' tcx > {
238
- // Remember the old state
239
- let path_len = self . path . len ( ) ;
240
- // Perform operation
241
- self . push_aggregate_field_path_elem ( old_op. layout , field) ;
242
- self . visit_value ( new_op) ?;
243
- // Undo changes
244
- self . path . truncate ( path_len) ;
245
- Ok ( ( ) )
248
+ let elem = self . aggregate_field_path_elem ( old_op. layout , field) ;
249
+ self . visit_elem ( new_op, elem)
246
250
}
247
251
248
252
#[ inline]
@@ -252,15 +256,8 @@ impl<'rt, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>>
252
256
variant_id : VariantIdx ,
253
257
new_op : OpTy < ' tcx , M :: PointerTag >
254
258
) -> EvalResult < ' tcx > {
255
- // Remember the old state
256
- let path_len = self . path . len ( ) ;
257
- // Perform operation
258
259
let name = old_op. layout . ty . ty_adt_def ( ) . unwrap ( ) . variants [ variant_id] . name ;
259
- self . path . push ( PathElem :: Variant ( name) ) ;
260
- self . visit_value ( new_op) ?;
261
- // Undo changes
262
- self . path . truncate ( path_len) ;
263
- Ok ( ( ) )
260
+ self . visit_elem ( new_op, PathElem :: Variant ( name) )
264
261
}
265
262
266
263
#[ inline]
0 commit comments