62
62
63
63
pub use self :: PointerKind :: * ;
64
64
pub use self :: InteriorKind :: * ;
65
- pub use self :: FieldName :: * ;
66
65
pub use self :: MutabilityCategory :: * ;
67
66
pub use self :: AliasableReason :: * ;
68
67
pub use self :: Note :: * ;
@@ -81,7 +80,7 @@ use ty::fold::TypeFoldable;
81
80
use hir:: { MutImmutable , MutMutable , PatKind } ;
82
81
use hir:: pat_util:: EnumerateAndAdjustIterator ;
83
82
use hir;
84
- use syntax:: ast;
83
+ use syntax:: ast:: { self , Name } ;
85
84
use syntax_pos:: Span ;
86
85
87
86
use std:: fmt;
@@ -129,15 +128,13 @@ pub enum PointerKind<'tcx> {
129
128
// base without a pointer dereference", e.g. a field
130
129
#[ derive( Clone , Copy , PartialEq , Eq , Hash ) ]
131
130
pub enum InteriorKind {
132
- InteriorField ( FieldName ) ,
131
+ InteriorField ( FieldIndex ) ,
133
132
InteriorElement ( InteriorOffsetKind ) ,
134
133
}
135
134
136
- #[ derive( Clone , Copy , PartialEq , Eq , Hash , Debug ) ]
137
- pub enum FieldName {
138
- NamedField ( ast:: Name ) ,
139
- PositionalField ( usize )
140
- }
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 ) ;
141
138
142
139
#[ derive( Clone , Copy , PartialEq , Eq , Hash , Debug ) ]
143
140
pub enum InteriorOffsetKind {
@@ -198,7 +195,7 @@ pub enum ImmutabilityBlame<'tcx> {
198
195
}
199
196
200
197
impl < ' tcx > cmt_ < ' tcx > {
201
- fn resolve_field ( & self , field_name : FieldName ) -> Option < ( & ' tcx ty:: AdtDef , & ' tcx ty:: FieldDef ) >
198
+ fn resolve_field ( & self , field_name : Name ) -> Option < ( & ' tcx ty:: AdtDef , & ' tcx ty:: FieldDef ) >
202
199
{
203
200
let adt_def = match self . ty . sty {
204
201
ty:: TyAdt ( def, _) => def,
@@ -215,11 +212,7 @@ impl<'tcx> cmt_<'tcx> {
215
212
& adt_def. variants [ 0 ]
216
213
}
217
214
} ;
218
- let field_def = match field_name {
219
- NamedField ( name) => variant_def. field_named ( name) ,
220
- PositionalField ( idx) => & variant_def. fields [ idx]
221
- } ;
222
- Some ( ( adt_def, field_def) )
215
+ Some ( ( adt_def, variant_def. field_named ( field_name) ) )
223
216
}
224
217
225
218
pub fn immutability_blame ( & self ) -> Option < ImmutabilityBlame < ' tcx > > {
@@ -230,8 +223,8 @@ impl<'tcx> cmt_<'tcx> {
230
223
match base_cmt. cat {
231
224
Categorization :: Local ( node_id) =>
232
225
Some ( ImmutabilityBlame :: LocalDeref ( node_id) ) ,
233
- Categorization :: Interior ( ref base_cmt, InteriorField ( field_name ) ) => {
234
- base_cmt. resolve_field ( field_name ) . map ( |( adt_def, field_def) | {
226
+ Categorization :: Interior ( ref base_cmt, InteriorField ( field_index ) ) => {
227
+ base_cmt. resolve_field ( field_index . 0 ) . map ( |( adt_def, field_def) | {
235
228
ImmutabilityBlame :: AdtFieldDeref ( adt_def, field_def)
236
229
} )
237
230
}
@@ -649,11 +642,6 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
649
642
Ok ( self . cat_field ( expr, base_cmt, f_name. node , expr_ty) )
650
643
}
651
644
652
- hir:: ExprTupField ( ref base, idx) => {
653
- let base_cmt = self . cat_expr ( & base) ?;
654
- Ok ( self . cat_tup_field ( expr, base_cmt, idx. node , expr_ty) )
655
- }
656
-
657
645
hir:: ExprIndex ( ref base, _) => {
658
646
if self . tables . is_method_call ( expr) {
659
647
// If this is an index implemented by a method call, then it
@@ -979,39 +967,21 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
979
967
pub fn cat_field < N : ast_node > ( & self ,
980
968
node : & N ,
981
969
base_cmt : cmt < ' tcx > ,
982
- f_name : ast :: Name ,
970
+ f_name : Name ,
983
971
f_ty : Ty < ' tcx > )
984
972
-> cmt < ' tcx > {
985
973
let ret = Rc :: new ( cmt_ {
986
974
id : node. id ( ) ,
987
975
span : node. span ( ) ,
988
976
mutbl : base_cmt. mutbl . inherit ( ) ,
989
- cat : Categorization :: Interior ( base_cmt, InteriorField ( NamedField ( f_name) ) ) ,
977
+ cat : Categorization :: Interior ( base_cmt, InteriorField ( FieldIndex ( f_name) ) ) ,
990
978
ty : f_ty,
991
979
note : NoteNone
992
980
} ) ;
993
981
debug ! ( "cat_field ret {:?}" , ret) ;
994
982
ret
995
983
}
996
984
997
- pub fn cat_tup_field < N : ast_node > ( & self ,
998
- node : & N ,
999
- base_cmt : cmt < ' tcx > ,
1000
- f_idx : usize ,
1001
- f_ty : Ty < ' tcx > )
1002
- -> cmt < ' tcx > {
1003
- let ret = Rc :: new ( cmt_ {
1004
- id : node. id ( ) ,
1005
- span : node. span ( ) ,
1006
- mutbl : base_cmt. mutbl . inherit ( ) ,
1007
- cat : Categorization :: Interior ( base_cmt, InteriorField ( PositionalField ( f_idx) ) ) ,
1008
- ty : f_ty,
1009
- note : NoteNone
1010
- } ) ;
1011
- debug ! ( "cat_tup_field ret {:?}" , ret) ;
1012
- ret
1013
- }
1014
-
1015
985
fn cat_overloaded_place ( & self ,
1016
986
expr : & hir:: Expr ,
1017
987
base : & hir:: Expr ,
@@ -1292,8 +1262,8 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1292
1262
1293
1263
for ( i, subpat) in subpats. iter ( ) . enumerate_and_adjust ( expected_len, ddpos) {
1294
1264
let subpat_ty = self . pat_ty ( & subpat) ?; // see (*2)
1295
- let subcmt = self . cat_imm_interior ( pat , cmt . clone ( ) , subpat_ty ,
1296
- InteriorField ( PositionalField ( i ) ) ) ;
1265
+ let interior = InteriorField ( FieldIndex ( Name :: intern ( & i . to_string ( ) ) ) ) ;
1266
+ let subcmt = self . cat_imm_interior ( pat , cmt . clone ( ) , subpat_ty , interior ) ;
1297
1267
self . cat_pattern_ ( subcmt, & subpat, op) ?;
1298
1268
}
1299
1269
}
@@ -1332,8 +1302,8 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1332
1302
} ;
1333
1303
for ( i, subpat) in subpats. iter ( ) . enumerate_and_adjust ( expected_len, ddpos) {
1334
1304
let subpat_ty = self . pat_ty ( & subpat) ?; // see (*2)
1335
- let subcmt = self . cat_imm_interior ( pat , cmt . clone ( ) , subpat_ty ,
1336
- InteriorField ( PositionalField ( i ) ) ) ;
1305
+ let interior = InteriorField ( FieldIndex ( Name :: intern ( & i . to_string ( ) ) ) ) ;
1306
+ let subcmt = self . cat_imm_interior ( pat , cmt . clone ( ) , subpat_ty , interior ) ;
1337
1307
self . cat_pattern_ ( subcmt, & subpat, op) ?;
1338
1308
}
1339
1309
}
@@ -1516,12 +1486,9 @@ impl<'tcx> cmt_<'tcx> {
1516
1486
}
1517
1487
}
1518
1488
}
1519
- Categorization :: Interior ( _, InteriorField ( NamedField ( _ ) ) ) => {
1489
+ Categorization :: Interior ( _, InteriorField ( .. ) ) => {
1520
1490
"field" . to_string ( )
1521
1491
}
1522
- Categorization :: Interior ( _, InteriorField ( PositionalField ( _) ) ) => {
1523
- "anonymous field" . to_string ( )
1524
- }
1525
1492
Categorization :: Interior ( _, InteriorElement ( InteriorOffsetKind :: Index ) ) => {
1526
1493
"indexed content" . to_string ( )
1527
1494
}
@@ -1554,8 +1521,7 @@ pub fn ptr_sigil(ptr: PointerKind) -> &'static str {
1554
1521
impl fmt:: Debug for InteriorKind {
1555
1522
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1556
1523
match * self {
1557
- InteriorField ( NamedField ( fld) ) => write ! ( f, "{}" , fld) ,
1558
- InteriorField ( PositionalField ( i) ) => write ! ( f, "#{}" , i) ,
1524
+ InteriorField ( FieldIndex ( name) ) => write ! ( f, "{}" , name) ,
1559
1525
InteriorElement ( ..) => write ! ( f, "[]" ) ,
1560
1526
}
1561
1527
}
0 commit comments