@@ -95,7 +95,7 @@ pub enum Categorization<'tcx> {
95
95
StaticItem ,
96
96
Upvar ( Upvar ) , // upvar referenced by closure env
97
97
Local ( ast:: NodeId ) , // local variable
98
- Deref ( cmt < ' tcx > , PointerKind < ' tcx > ) , // deref of a ptr
98
+ Deref ( cmt < ' tcx > , PointerKind < ' tcx > ) , // deref of a ptr
99
99
Interior ( cmt < ' tcx > , InteriorKind ) , // something interior: field, tuple, etc
100
100
Downcast ( cmt < ' tcx > , DefId ) , // selects a particular enum variant (*1)
101
101
@@ -120,9 +120,6 @@ pub enum PointerKind<'tcx> {
120
120
121
121
/// `*T`
122
122
UnsafePtr ( hir:: Mutability ) ,
123
-
124
- /// Implicit deref of the `&T` that results from an overloaded index `[]`.
125
- Implicit ( ty:: BorrowKind , ty:: Region < ' tcx > ) ,
126
123
}
127
124
128
125
// We use the term "interior" to mean "something reachable from the
@@ -161,6 +158,7 @@ pub enum MutabilityCategory {
161
158
pub enum Note {
162
159
NoteClosureEnv ( ty:: UpvarId ) , // Deref through closure env
163
160
NoteUpvarRef ( ty:: UpvarId ) , // Deref through by-ref upvar
161
+ NoteIndex , // Deref as part of desugaring `x[]` into its two components
164
162
NoteNone // Nothing special
165
163
}
166
164
@@ -224,8 +222,7 @@ impl<'tcx> cmt_<'tcx> {
224
222
225
223
pub fn immutability_blame ( & self ) -> Option < ImmutabilityBlame < ' tcx > > {
226
224
match self . cat {
227
- Categorization :: Deref ( ref base_cmt, BorrowedPtr ( ty:: ImmBorrow , _) ) |
228
- Categorization :: Deref ( ref base_cmt, Implicit ( ty:: ImmBorrow , _) ) => {
225
+ Categorization :: Deref ( ref base_cmt, BorrowedPtr ( ty:: ImmBorrow , _) ) => {
229
226
// try to figure out where the immutable reference came from
230
227
match base_cmt. cat {
231
228
Categorization :: Local ( node_id) =>
@@ -321,7 +318,7 @@ impl MutabilityCategory {
321
318
Unique => {
322
319
base_mutbl. inherit ( )
323
320
}
324
- BorrowedPtr ( borrow_kind, _) | Implicit ( borrow_kind , _ ) => {
321
+ BorrowedPtr ( borrow_kind, _) => {
325
322
MutabilityCategory :: from_borrow_kind ( borrow_kind)
326
323
}
327
324
UnsafePtr ( m) => {
@@ -610,7 +607,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
610
607
} else {
611
608
previous ( ) ?
612
609
} ;
613
- self . cat_deref ( expr, base, false )
610
+ self . cat_deref ( expr, base, NoteNone )
614
611
}
615
612
616
613
adjustment:: Adjust :: NeverToAny |
@@ -633,10 +630,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
633
630
match expr. node {
634
631
hir:: ExprUnary ( hir:: UnDeref , ref e_base) => {
635
632
if self . tables . is_method_call ( expr) {
636
- self . cat_overloaded_place ( expr, e_base, false )
633
+ self . cat_overloaded_place ( expr, e_base, NoteNone )
637
634
} else {
638
635
let base_cmt = self . cat_expr ( & e_base) ?;
639
- self . cat_deref ( expr, base_cmt, false )
636
+ self . cat_deref ( expr, base_cmt, NoteNone )
640
637
}
641
638
}
642
639
@@ -661,7 +658,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
661
658
// The call to index() returns a `&T` value, which
662
659
// is an rvalue. That is what we will be
663
660
// dereferencing.
664
- self . cat_overloaded_place ( expr, base, true )
661
+ self . cat_overloaded_place ( expr, base, NoteIndex )
665
662
} else {
666
663
let base_cmt = self . cat_expr ( & base) ?;
667
664
self . cat_index ( expr, base_cmt, expr_ty, InteriorOffsetKind :: Index )
@@ -1012,12 +1009,18 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1012
1009
ret
1013
1010
}
1014
1011
1015
- fn cat_overloaded_place ( & self ,
1016
- expr : & hir:: Expr ,
1017
- base : & hir:: Expr ,
1018
- implicit : bool )
1019
- -> McResult < cmt < ' tcx > > {
1020
- debug ! ( "cat_overloaded_place: implicit={}" , implicit) ;
1012
+ fn cat_overloaded_place (
1013
+ & self ,
1014
+ expr : & hir:: Expr ,
1015
+ base : & hir:: Expr ,
1016
+ note : Note ,
1017
+ ) -> McResult < cmt < ' tcx > > {
1018
+ debug ! (
1019
+ "cat_overloaded_place(expr={:?}, base={:?}, note={:?})" ,
1020
+ expr,
1021
+ base,
1022
+ note,
1023
+ ) ;
1021
1024
1022
1025
// Reconstruct the output assuming it's a reference with the
1023
1026
// same region and mutability as the receiver. This holds for
@@ -1037,14 +1040,15 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1037
1040
} ) ;
1038
1041
1039
1042
let base_cmt = self . cat_rvalue_node ( expr. id , expr. span , ref_ty) ;
1040
- self . cat_deref ( expr, base_cmt, implicit )
1043
+ self . cat_deref ( expr, base_cmt, note )
1041
1044
}
1042
1045
1043
- pub fn cat_deref < N : ast_node > ( & self ,
1044
- node : & N ,
1045
- base_cmt : cmt < ' tcx > ,
1046
- implicit : bool )
1047
- -> McResult < cmt < ' tcx > > {
1046
+ pub fn cat_deref (
1047
+ & self ,
1048
+ node : & impl ast_node ,
1049
+ base_cmt : cmt < ' tcx > ,
1050
+ note : Note ,
1051
+ ) -> McResult < cmt < ' tcx > > {
1048
1052
debug ! ( "cat_deref: base_cmt={:?}" , base_cmt) ;
1049
1053
1050
1054
let base_cmt_ty = base_cmt. ty ;
@@ -1060,9 +1064,9 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1060
1064
let ptr = match base_cmt. ty . sty {
1061
1065
ty:: TyAdt ( def, ..) if def. is_box ( ) => Unique ,
1062
1066
ty:: TyRawPtr ( ref mt) => UnsafePtr ( mt. mutbl ) ,
1063
- ty:: TyRef ( r, mt ) => {
1064
- let bk = ty:: BorrowKind :: from_mutbl ( mt . mutbl ) ;
1065
- if implicit { Implicit ( bk , r ) } else { BorrowedPtr ( bk, r) }
1067
+ ty:: TyRef ( r, ty ) => {
1068
+ let bk = ty:: BorrowKind :: from_mutbl ( ty . mutbl ) ;
1069
+ BorrowedPtr ( bk, r)
1066
1070
}
1067
1071
ref ty => bug ! ( "unexpected type in cat_deref: {:?}" , ty)
1068
1072
} ;
@@ -1073,7 +1077,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1073
1077
mutbl : MutabilityCategory :: from_pointer_kind ( base_cmt. mutbl , ptr) ,
1074
1078
cat : Categorization :: Deref ( base_cmt, ptr) ,
1075
1079
ty : deref_ty,
1076
- note : NoteNone
1080
+ note : note ,
1077
1081
} ) ;
1078
1082
debug ! ( "cat_deref ret {:?}" , ret) ;
1079
1083
Ok ( ret)
@@ -1207,7 +1211,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1207
1211
// step out of sync again. So you'll see below that we always
1208
1212
// get the type of the *subpattern* and use that.
1209
1213
1210
- debug ! ( "cat_pattern: {:?} cmt={:?}" , pat, cmt) ;
1214
+ debug ! ( "cat_pattern(pat= {:?}, cmt={:?}) " , pat, cmt) ;
1211
1215
1212
1216
// If (pattern) adjustments are active for this pattern, adjust the `cmt` correspondingly.
1213
1217
// `cmt`s are constructed differently from patterns. For example, in
@@ -1245,10 +1249,13 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1245
1249
. pat_adjustments ( )
1246
1250
. get ( pat. hir_id )
1247
1251
. map ( |v| v. len ( ) )
1248
- . unwrap_or ( 0 ) {
1249
- cmt = self . cat_deref ( pat, cmt, true /* implicit */ ) ?;
1252
+ . unwrap_or ( 0 )
1253
+ {
1254
+ debug ! ( "cat_pattern: applying adjustment to cmt={:?}" , cmt) ;
1255
+ cmt = self . cat_deref ( pat, cmt, NoteNone ) ?;
1250
1256
}
1251
1257
let cmt = cmt; // lose mutability
1258
+ debug ! ( "cat_pattern: applied adjustment derefs to get cmt={:?}" , cmt) ;
1252
1259
1253
1260
// Invoke the callback, but only now, after the `cmt` has adjusted.
1254
1261
//
@@ -1342,7 +1349,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1342
1349
// box p1, &p1, &mut p1. we can ignore the mutability of
1343
1350
// PatKind::Ref since that information is already contained
1344
1351
// in the type.
1345
- let subcmt = self . cat_deref ( pat, cmt, false ) ?;
1352
+ let subcmt = self . cat_deref ( pat, cmt, NoteNone ) ?;
1346
1353
self . cat_pattern_ ( subcmt, & subpat, op) ?;
1347
1354
}
1348
1355
@@ -1403,7 +1410,6 @@ impl<'tcx> cmt_<'tcx> {
1403
1410
Categorization :: Local ( ..) |
1404
1411
Categorization :: Deref ( _, UnsafePtr ( ..) ) |
1405
1412
Categorization :: Deref ( _, BorrowedPtr ( ..) ) |
1406
- Categorization :: Deref ( _, Implicit ( ..) ) |
1407
1413
Categorization :: Upvar ( ..) => {
1408
1414
Rc :: new ( ( * self ) . clone ( ) )
1409
1415
}
@@ -1423,9 +1429,7 @@ impl<'tcx> cmt_<'tcx> {
1423
1429
1424
1430
match self . cat {
1425
1431
Categorization :: Deref ( ref b, BorrowedPtr ( ty:: MutBorrow , _) ) |
1426
- Categorization :: Deref ( ref b, Implicit ( ty:: MutBorrow , _) ) |
1427
1432
Categorization :: Deref ( ref b, BorrowedPtr ( ty:: UniqueImmBorrow , _) ) |
1428
- Categorization :: Deref ( ref b, Implicit ( ty:: UniqueImmBorrow , _) ) |
1429
1433
Categorization :: Deref ( ref b, Unique ) |
1430
1434
Categorization :: Downcast ( ref b, _) |
1431
1435
Categorization :: Interior ( ref b, _) => {
@@ -1448,8 +1452,7 @@ impl<'tcx> cmt_<'tcx> {
1448
1452
}
1449
1453
}
1450
1454
1451
- Categorization :: Deref ( _, BorrowedPtr ( ty:: ImmBorrow , _) ) |
1452
- Categorization :: Deref ( _, Implicit ( ty:: ImmBorrow , _) ) => {
1455
+ Categorization :: Deref ( _, BorrowedPtr ( ty:: ImmBorrow , _) ) => {
1453
1456
FreelyAliasable ( AliasableBorrowed )
1454
1457
}
1455
1458
}
@@ -1471,7 +1474,7 @@ impl<'tcx> cmt_<'tcx> {
1471
1474
_ => bug ! ( )
1472
1475
} )
1473
1476
}
1474
- NoteNone => None
1477
+ NoteIndex | NoteNone => None
1475
1478
}
1476
1479
}
1477
1480
@@ -1500,17 +1503,17 @@ impl<'tcx> cmt_<'tcx> {
1500
1503
Some ( _) => bug ! ( ) ,
1501
1504
None => {
1502
1505
match pk {
1503
- Implicit ( ..) => {
1504
- format ! ( "indexed content" )
1505
- }
1506
1506
Unique => {
1507
1507
format ! ( "`Box` content" )
1508
1508
}
1509
1509
UnsafePtr ( ..) => {
1510
1510
format ! ( "dereference of raw pointer" )
1511
1511
}
1512
1512
BorrowedPtr ( ..) => {
1513
- format ! ( "borrowed content" )
1513
+ match self . note {
1514
+ NoteIndex => format ! ( "indexed content" ) ,
1515
+ _ => format ! ( "borrowed content" ) ,
1516
+ }
1514
1517
}
1515
1518
}
1516
1519
}
@@ -1541,12 +1544,9 @@ impl<'tcx> cmt_<'tcx> {
1541
1544
pub fn ptr_sigil ( ptr : PointerKind ) -> & ' static str {
1542
1545
match ptr {
1543
1546
Unique => "Box" ,
1544
- BorrowedPtr ( ty:: ImmBorrow , _) |
1545
- Implicit ( ty:: ImmBorrow , _) => "&" ,
1546
- BorrowedPtr ( ty:: MutBorrow , _) |
1547
- Implicit ( ty:: MutBorrow , _) => "&mut" ,
1548
- BorrowedPtr ( ty:: UniqueImmBorrow , _) |
1549
- Implicit ( ty:: UniqueImmBorrow , _) => "&unique" ,
1547
+ BorrowedPtr ( ty:: ImmBorrow , _) => "&" ,
1548
+ BorrowedPtr ( ty:: MutBorrow , _) => "&mut" ,
1549
+ BorrowedPtr ( ty:: UniqueImmBorrow , _) => "&unique" ,
1550
1550
UnsafePtr ( _) => "*" ,
1551
1551
}
1552
1552
}
0 commit comments