@@ -84,6 +84,7 @@ use syntax::ast::{self, Name};
84
84
use syntax_pos:: Span ;
85
85
86
86
use std:: fmt;
87
+ use std:: hash:: { Hash , Hasher } ;
87
88
use rustc_data_structures:: sync:: Lrc ;
88
89
use std:: rc:: Rc ;
89
90
use util:: nodemap:: ItemLocalSet ;
@@ -132,9 +133,22 @@ pub enum InteriorKind {
132
133
InteriorElement ( InteriorOffsetKind ) ,
133
134
}
134
135
135
- // FIXME: Use actual index instead of `ast::Name` with questionable hygiene
136
- #[ derive( Clone , Copy , PartialEq , Eq , Hash ) ]
137
- pub struct FieldIndex ( pub ast:: Name ) ;
136
+ // Contains index of a field that is actually used for loan path comparisons and
137
+ // string representation of the field that should be used only for diagnostics.
138
+ #[ derive( Clone , Copy , Eq ) ]
139
+ pub struct FieldIndex ( pub usize , pub Name ) ;
140
+
141
+ impl PartialEq for FieldIndex {
142
+ fn eq ( & self , rhs : & Self ) -> bool {
143
+ self . 0 == rhs. 0
144
+ }
145
+ }
146
+
147
+ impl Hash for FieldIndex {
148
+ fn hash < H : Hasher > ( & self , h : & mut H ) {
149
+ self . 0 . hash ( h)
150
+ }
151
+ }
138
152
139
153
#[ derive( Clone , Copy , PartialEq , Eq , Hash , Debug ) ]
140
154
pub enum InteriorOffsetKind {
@@ -195,7 +209,7 @@ pub enum ImmutabilityBlame<'tcx> {
195
209
}
196
210
197
211
impl < ' tcx > cmt_ < ' tcx > {
198
- fn resolve_field ( & self , field_name : Name ) -> Option < ( & ' tcx ty:: AdtDef , & ' tcx ty:: FieldDef ) >
212
+ fn resolve_field ( & self , field_index : usize ) -> Option < ( & ' tcx ty:: AdtDef , & ' tcx ty:: FieldDef ) >
199
213
{
200
214
let adt_def = match self . ty . sty {
201
215
ty:: TyAdt ( def, _) => def,
@@ -212,7 +226,7 @@ impl<'tcx> cmt_<'tcx> {
212
226
& adt_def. variants [ 0 ]
213
227
}
214
228
} ;
215
- Some ( ( adt_def, variant_def. field_named ( field_name ) ) )
229
+ Some ( ( adt_def, & variant_def. fields [ field_index ] ) )
216
230
}
217
231
218
232
pub fn immutability_blame ( & self ) -> Option < ImmutabilityBlame < ' tcx > > {
@@ -639,7 +653,8 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
639
653
expr. id,
640
654
expr,
641
655
base_cmt) ;
642
- Ok ( self . cat_field ( expr, base_cmt, f_name. node , expr_ty) )
656
+ let f_index = self . tcx . field_index ( expr. id , self . tables ) ;
657
+ Ok ( self . cat_field ( expr, base_cmt, f_index, f_name. node , expr_ty) )
643
658
}
644
659
645
660
hir:: ExprIndex ( ref base, _) => {
@@ -967,14 +982,15 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
967
982
pub fn cat_field < N : ast_node > ( & self ,
968
983
node : & N ,
969
984
base_cmt : cmt < ' tcx > ,
985
+ f_index : usize ,
970
986
f_name : Name ,
971
987
f_ty : Ty < ' tcx > )
972
988
-> cmt < ' tcx > {
973
989
let ret = Rc :: new ( cmt_ {
974
990
id : node. id ( ) ,
975
991
span : node. span ( ) ,
976
992
mutbl : base_cmt. mutbl . inherit ( ) ,
977
- cat : Categorization :: Interior ( base_cmt, InteriorField ( FieldIndex ( f_name) ) ) ,
993
+ cat : Categorization :: Interior ( base_cmt, InteriorField ( FieldIndex ( f_index , f_name) ) ) ,
978
994
ty : f_ty,
979
995
note : NoteNone
980
996
} ) ;
@@ -1262,7 +1278,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1262
1278
1263
1279
for ( i, subpat) in subpats. iter ( ) . enumerate_and_adjust ( expected_len, ddpos) {
1264
1280
let subpat_ty = self . pat_ty ( & subpat) ?; // see (*2)
1265
- let interior = InteriorField ( FieldIndex ( Name :: intern ( & i. to_string ( ) ) ) ) ;
1281
+ let interior = InteriorField ( FieldIndex ( i , Name :: intern ( & i. to_string ( ) ) ) ) ;
1266
1282
let subcmt = self . cat_imm_interior ( pat, cmt. clone ( ) , subpat_ty, interior) ;
1267
1283
self . cat_pattern_ ( subcmt, & subpat, op) ?;
1268
1284
}
@@ -1285,7 +1301,8 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1285
1301
1286
1302
for fp in field_pats {
1287
1303
let field_ty = self . pat_ty ( & fp. node . pat ) ?; // see (*2)
1288
- let cmt_field = self . cat_field ( pat, cmt. clone ( ) , fp. node . name , field_ty) ;
1304
+ let f_index = self . tcx . field_index ( fp. node . id , self . tables ) ;
1305
+ let cmt_field = self . cat_field ( pat, cmt. clone ( ) , f_index, fp. node . name , field_ty) ;
1289
1306
self . cat_pattern_ ( cmt_field, & fp. node . pat , op) ?;
1290
1307
}
1291
1308
}
@@ -1302,7 +1319,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1302
1319
} ;
1303
1320
for ( i, subpat) in subpats. iter ( ) . enumerate_and_adjust ( expected_len, ddpos) {
1304
1321
let subpat_ty = self . pat_ty ( & subpat) ?; // see (*2)
1305
- let interior = InteriorField ( FieldIndex ( Name :: intern ( & i. to_string ( ) ) ) ) ;
1322
+ let interior = InteriorField ( FieldIndex ( i , Name :: intern ( & i. to_string ( ) ) ) ) ;
1306
1323
let subcmt = self . cat_imm_interior ( pat, cmt. clone ( ) , subpat_ty, interior) ;
1307
1324
self . cat_pattern_ ( subcmt, & subpat, op) ?;
1308
1325
}
@@ -1521,7 +1538,7 @@ pub fn ptr_sigil(ptr: PointerKind) -> &'static str {
1521
1538
impl fmt:: Debug for InteriorKind {
1522
1539
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1523
1540
match * self {
1524
- InteriorField ( FieldIndex ( name ) ) => write ! ( f, "{}" , name ) ,
1541
+ InteriorField ( FieldIndex ( _ , info ) ) => write ! ( f, "{}" , info ) ,
1525
1542
InteriorElement ( ..) => write ! ( f, "[]" ) ,
1526
1543
}
1527
1544
}
0 commit comments