@@ -50,6 +50,7 @@ use rustc_span::edit_distance::find_best_match_for_name;
50
50
use rustc_span:: hygiene:: DesugaringKind ;
51
51
use rustc_span:: source_map:: { Span , Spanned } ;
52
52
use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
53
+ use rustc_target:: abi:: FieldIdx ;
53
54
use rustc_target:: spec:: abi:: Abi :: RustIntrinsic ;
54
55
use rustc_trait_selection:: infer:: InferCtxtExt ;
55
56
use rustc_trait_selection:: traits:: { self , ObligationCauseCode } ;
@@ -1561,8 +1562,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1561
1562
1562
1563
let mut remaining_fields = variant
1563
1564
. fields
1564
- . iter ( )
1565
- . enumerate ( )
1565
+ . iter_enumerated ( )
1566
1566
. map ( |( i, field) | ( field. ident ( tcx) . normalize_to_macros_2_0 ( ) , ( i, field) ) )
1567
1567
. collect :: < FxHashMap < _ , _ > > ( ) ;
1568
1568
@@ -1815,7 +1815,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1815
1815
& self ,
1816
1816
adt_ty : Ty < ' tcx > ,
1817
1817
span : Span ,
1818
- remaining_fields : FxHashMap < Ident , ( usize , & ty:: FieldDef ) > ,
1818
+ remaining_fields : FxHashMap < Ident , ( FieldIdx , & ty:: FieldDef ) > ,
1819
1819
variant : & ' tcx ty:: VariantDef ,
1820
1820
ast_fields : & ' tcx [ hir:: ExprField < ' tcx > ] ,
1821
1821
substs : SubstsRef < ' tcx > ,
@@ -2209,11 +2209,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2209
2209
let ( ident, def_scope) =
2210
2210
self . tcx . adjust_ident_and_get_scope ( field, base_def. did ( ) , body_hir_id) ;
2211
2211
let fields = & base_def. non_enum_variant ( ) . fields ;
2212
- if let Some ( index) = fields
2213
- . iter ( )
2214
- . position ( |f | f. ident ( self . tcx ) . normalize_to_macros_2_0 ( ) == ident)
2212
+ if let Some ( ( index, field ) ) = fields
2213
+ . iter_enumerated ( )
2214
+ . find ( | ( _ , f ) | f. ident ( self . tcx ) . normalize_to_macros_2_0 ( ) == ident)
2215
2215
{
2216
- let field = & fields[ index] ;
2217
2216
let field_ty = self . field_ty ( expr. span , field, substs) ;
2218
2217
// Save the index of all fields regardless of their visibility in case
2219
2218
// of error recovery.
@@ -2230,15 +2229,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2230
2229
}
2231
2230
}
2232
2231
ty:: Tuple ( tys) => {
2233
- let fstr = field. as_str ( ) ;
2234
- if let Ok ( index) = fstr. parse :: < usize > ( ) {
2235
- if fstr == index. to_string ( ) {
2232
+ if let Ok ( index) = field. as_str ( ) . parse :: < usize > ( ) {
2233
+ if field. name == sym:: integer ( index) {
2236
2234
if let Some ( & field_ty) = tys. get ( index) {
2237
2235
let adjustments = self . adjust_steps ( & autoderef) ;
2238
2236
self . apply_adjustments ( base, adjustments) ;
2239
2237
self . register_predicates ( autoderef. into_obligations ( ) ) ;
2240
2238
2241
- self . write_field_index ( expr. hir_id , index) ;
2239
+ self . write_field_index ( expr. hir_id , FieldIdx :: from_usize ( index) ) ;
2242
2240
return field_ty;
2243
2241
}
2244
2242
}
0 commit comments