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