@@ -1708,7 +1708,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1708
1708
let ident = tcx. adjust_ident ( field. ident , variant. def_id ) ;
1709
1709
let field_type = if let Some ( ( i, v_field) ) = remaining_fields. remove ( & ident) {
1710
1710
seen_fields. insert ( ident, field. span ) ;
1711
- self . write_field_index ( field. hir_id , i) ;
1711
+ // FIXME: handle nested fields
1712
+ self . write_field_index ( field. hir_id , i, Vec :: new ( ) ) ;
1712
1713
1713
1714
// We don't look at stability attributes on
1714
1715
// struct-like enums (yet...), but it's definitely not
@@ -2352,24 +2353,39 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2352
2353
let body_hir_id = self . tcx . local_def_id_to_hir_id ( self . body_id ) ;
2353
2354
let ( ident, def_scope) =
2354
2355
self . tcx . adjust_ident_and_get_scope ( field, base_def. did ( ) , body_hir_id) ;
2355
- let fields = & base_def. non_enum_variant ( ) . fields ;
2356
- if let Some ( ( index, field) ) = fields
2357
- . iter_enumerated ( )
2358
- . find ( |( _, f) | f. ident ( self . tcx ) . normalize_to_macros_2_0 ( ) == ident)
2359
- {
2356
+ let mut adt_def = * base_def;
2357
+ let mut last_ty = None ;
2358
+ let mut nested_fields = Vec :: new ( ) ;
2359
+ let mut index = None ;
2360
+ while let Some ( idx) = self . tcx . find_field ( ( adt_def. did ( ) , ident) ) {
2361
+ let & mut first_idx = index. get_or_insert ( idx) ;
2362
+ let field = & adt_def. non_enum_variant ( ) . fields [ idx] ;
2360
2363
let field_ty = self . field_ty ( expr. span , field, args) ;
2361
- // Save the index of all fields regardless of their visibility in case
2362
- // of error recovery.
2363
- self . write_field_index ( expr. hir_id , index) ;
2364
- let adjustments = self . adjust_steps ( & autoderef) ;
2365
- if field. vis . is_accessible_from ( def_scope, self . tcx ) {
2366
- self . apply_adjustments ( base, adjustments) ;
2367
- self . register_predicates ( autoderef. into_obligations ( ) ) ;
2364
+ if let Some ( ty) = last_ty {
2365
+ nested_fields. push ( ( ty, idx) ) ;
2366
+ }
2367
+ if field. ident ( self . tcx ) . normalize_to_macros_2_0 ( ) == ident {
2368
+ // Save the index of all fields regardless of their visibility in case
2369
+ // of error recovery.
2370
+ self . write_field_index ( expr. hir_id , first_idx, nested_fields) ;
2371
+ let adjustments = self . adjust_steps ( & autoderef) ;
2372
+ if field. vis . is_accessible_from ( def_scope, self . tcx ) {
2373
+ self . apply_adjustments ( base, adjustments) ;
2374
+ self . register_predicates ( autoderef. into_obligations ( ) ) ;
2368
2375
2369
- self . tcx . check_stability ( field. did , Some ( expr. hir_id ) , expr. span , None ) ;
2370
- return field_ty;
2376
+ self . tcx . check_stability (
2377
+ field. did ,
2378
+ Some ( expr. hir_id ) ,
2379
+ expr. span ,
2380
+ None ,
2381
+ ) ;
2382
+ return field_ty;
2383
+ }
2384
+ private_candidate = Some ( ( adjustments, base_def. did ( ) ) ) ;
2385
+ break ;
2371
2386
}
2372
- private_candidate = Some ( ( adjustments, base_def. did ( ) ) ) ;
2387
+ last_ty = Some ( field_ty) ;
2388
+ adt_def = field_ty. ty_adt_def ( ) . expect ( "expect Adt for unnamed field" ) ;
2373
2389
}
2374
2390
}
2375
2391
ty:: Tuple ( tys) => {
@@ -2380,7 +2396,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2380
2396
self . apply_adjustments ( base, adjustments) ;
2381
2397
self . register_predicates ( autoderef. into_obligations ( ) ) ;
2382
2398
2383
- self . write_field_index ( expr. hir_id , FieldIdx :: from_usize ( index) ) ;
2399
+ self . write_field_index (
2400
+ expr. hir_id ,
2401
+ FieldIdx :: from_usize ( index) ,
2402
+ Vec :: new ( ) ,
2403
+ ) ;
2384
2404
return field_ty;
2385
2405
}
2386
2406
}
0 commit comments