@@ -1721,7 +1721,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17211721 let ident = tcx. adjust_ident ( field. ident , variant. def_id ) ;
17221722 let field_type = if let Some ( ( i, v_field) ) = remaining_fields. remove ( & ident) {
17231723 seen_fields. insert ( ident, field. span ) ;
1724- self . write_field_index ( field. hir_id , i) ;
1724+ // FIXME: handle nested fields
1725+ self . write_field_index ( field. hir_id , i, Vec :: new ( ) ) ;
17251726
17261727 // We don't look at stability attributes on
17271728 // struct-like enums (yet...), but it's definitely not
@@ -2367,24 +2368,39 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23672368 let body_hir_id = self . tcx . local_def_id_to_hir_id ( self . body_id ) ;
23682369 let ( ident, def_scope) =
23692370 self . tcx . adjust_ident_and_get_scope ( field, base_def. did ( ) , body_hir_id) ;
2370- let fields = & base_def. non_enum_variant ( ) . fields ;
2371- if let Some ( ( index, field) ) = fields
2372- . iter_enumerated ( )
2373- . find ( |( _, f) | f. ident ( self . tcx ) . normalize_to_macros_2_0 ( ) == ident)
2374- {
2371+ let mut adt_def = * base_def;
2372+ let mut last_ty = None ;
2373+ let mut nested_fields = Vec :: new ( ) ;
2374+ let mut index = None ;
2375+ while let Some ( idx) = self . tcx . find_field ( ( adt_def. did ( ) , ident) ) {
2376+ let & mut first_idx = index. get_or_insert ( idx) ;
2377+ let field = & adt_def. non_enum_variant ( ) . fields [ idx] ;
23752378 let field_ty = self . field_ty ( expr. span , field, args) ;
2376- // Save the index of all fields regardless of their visibility in case
2377- // of error recovery.
2378- self . write_field_index ( expr. hir_id , index) ;
2379- let adjustments = self . adjust_steps ( & autoderef) ;
2380- if field. vis . is_accessible_from ( def_scope, self . tcx ) {
2381- self . apply_adjustments ( base, adjustments) ;
2382- self . register_predicates ( autoderef. into_obligations ( ) ) ;
2379+ if let Some ( ty) = last_ty {
2380+ nested_fields. push ( ( ty, idx) ) ;
2381+ }
2382+ if field. ident ( self . tcx ) . normalize_to_macros_2_0 ( ) == ident {
2383+ // Save the index of all fields regardless of their visibility in case
2384+ // of error recovery.
2385+ self . write_field_index ( expr. hir_id , first_idx, nested_fields) ;
2386+ let adjustments = self . adjust_steps ( & autoderef) ;
2387+ if field. vis . is_accessible_from ( def_scope, self . tcx ) {
2388+ self . apply_adjustments ( base, adjustments) ;
2389+ self . register_predicates ( autoderef. into_obligations ( ) ) ;
23832390
2384- self . tcx . check_stability ( field. did , Some ( expr. hir_id ) , expr. span , None ) ;
2385- return field_ty;
2391+ self . tcx . check_stability (
2392+ field. did ,
2393+ Some ( expr. hir_id ) ,
2394+ expr. span ,
2395+ None ,
2396+ ) ;
2397+ return field_ty;
2398+ }
2399+ private_candidate = Some ( ( adjustments, base_def. did ( ) ) ) ;
2400+ break ;
23862401 }
2387- private_candidate = Some ( ( adjustments, base_def. did ( ) ) ) ;
2402+ last_ty = Some ( field_ty) ;
2403+ adt_def = field_ty. ty_adt_def ( ) . expect ( "expect Adt for unnamed field" ) ;
23882404 }
23892405 }
23902406 ty:: Tuple ( tys) => {
@@ -2395,7 +2411,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23952411 self . apply_adjustments ( base, adjustments) ;
23962412 self . register_predicates ( autoderef. into_obligations ( ) ) ;
23972413
2398- self . write_field_index ( expr. hir_id , FieldIdx :: from_usize ( index) ) ;
2414+ self . write_field_index (
2415+ expr. hir_id ,
2416+ FieldIdx :: from_usize ( index) ,
2417+ Vec :: new ( ) ,
2418+ ) ;
23992419 return field_ty;
24002420 }
24012421 }
0 commit comments