@@ -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
@@ -172,6 +169,7 @@ pub enum MutabilityCategory {
172
169
pub enum Note {
173
170
NoteClosureEnv ( ty:: UpvarId ) , // Deref through closure env
174
171
NoteUpvarRef ( ty:: UpvarId ) , // Deref through by-ref upvar
172
+ NoteIndex , // Deref as part of desugaring `x[]` into its two components
175
173
NoteNone // Nothing special
176
174
}
177
175
@@ -231,8 +229,7 @@ impl<'tcx> cmt_<'tcx> {
231
229
232
230
pub fn immutability_blame ( & self ) -> Option < ImmutabilityBlame < ' tcx > > {
233
231
match self . cat {
234
- Categorization :: Deref ( ref base_cmt, BorrowedPtr ( ty:: ImmBorrow , _) ) |
235
- Categorization :: Deref ( ref base_cmt, Implicit ( ty:: ImmBorrow , _) ) => {
232
+ Categorization :: Deref ( ref base_cmt, BorrowedPtr ( ty:: ImmBorrow , _) ) => {
236
233
// try to figure out where the immutable reference came from
237
234
match base_cmt. cat {
238
235
Categorization :: Local ( node_id) =>
@@ -328,7 +325,7 @@ impl MutabilityCategory {
328
325
Unique => {
329
326
base_mutbl. inherit ( )
330
327
}
331
- BorrowedPtr ( borrow_kind, _) | Implicit ( borrow_kind , _ ) => {
328
+ BorrowedPtr ( borrow_kind, _) => {
332
329
MutabilityCategory :: from_borrow_kind ( borrow_kind)
333
330
}
334
331
UnsafePtr ( m) => {
@@ -617,7 +614,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
617
614
} else {
618
615
previous ( ) ?
619
616
} ) ;
620
- self . cat_deref ( expr, base, false )
617
+ self . cat_deref ( expr, base, NoteNone )
621
618
}
622
619
623
620
adjustment:: Adjust :: NeverToAny |
@@ -640,10 +637,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
640
637
match expr. node {
641
638
hir:: ExprUnary ( hir:: UnDeref , ref e_base) => {
642
639
if self . tables . is_method_call ( expr) {
643
- self . cat_overloaded_place ( expr, e_base, false )
640
+ self . cat_overloaded_place ( expr, e_base, NoteNone )
644
641
} else {
645
642
let base_cmt = Rc :: new ( self . cat_expr ( & e_base) ?) ;
646
- self . cat_deref ( expr, base_cmt, false )
643
+ self . cat_deref ( expr, base_cmt, NoteNone )
647
644
}
648
645
}
649
646
@@ -664,7 +661,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
664
661
// The call to index() returns a `&T` value, which
665
662
// is an rvalue. That is what we will be
666
663
// dereferencing.
667
- self . cat_overloaded_place ( expr, base, true )
664
+ self . cat_overloaded_place ( expr, base, NoteIndex )
668
665
} else {
669
666
let base_cmt = Rc :: new ( self . cat_expr ( & base) ?) ;
670
667
self . cat_index ( expr, base_cmt, expr_ty, InteriorOffsetKind :: Index )
@@ -999,12 +996,18 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
999
996
ret
1000
997
}
1001
998
1002
- fn cat_overloaded_place ( & self ,
1003
- expr : & hir:: Expr ,
1004
- base : & hir:: Expr ,
1005
- implicit : bool )
1006
- -> McResult < cmt_ < ' tcx > > {
1007
- debug ! ( "cat_overloaded_place: implicit={}" , implicit) ;
999
+ fn cat_overloaded_place (
1000
+ & self ,
1001
+ expr : & hir:: Expr ,
1002
+ base : & hir:: Expr ,
1003
+ note : Note ,
1004
+ ) -> McResult < cmt_ < ' tcx > > {
1005
+ debug ! (
1006
+ "cat_overloaded_place(expr={:?}, base={:?}, note={:?})" ,
1007
+ expr,
1008
+ base,
1009
+ note,
1010
+ ) ;
1008
1011
1009
1012
// Reconstruct the output assuming it's a reference with the
1010
1013
// same region and mutability as the receiver. This holds for
@@ -1024,14 +1027,15 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1024
1027
} ) ;
1025
1028
1026
1029
let base_cmt = Rc :: new ( self . cat_rvalue_node ( expr. id , expr. span , ref_ty) ) ;
1027
- self . cat_deref ( expr, base_cmt, implicit )
1030
+ self . cat_deref ( expr, base_cmt, note )
1028
1031
}
1029
1032
1030
- pub fn cat_deref < N : ast_node > ( & self ,
1031
- node : & N ,
1032
- base_cmt : cmt < ' tcx > ,
1033
- implicit : bool )
1034
- -> McResult < cmt_ < ' tcx > > {
1033
+ pub fn cat_deref (
1034
+ & self ,
1035
+ node : & impl ast_node ,
1036
+ base_cmt : cmt < ' tcx > ,
1037
+ note : Note ,
1038
+ ) -> McResult < cmt_ < ' tcx > > {
1035
1039
debug ! ( "cat_deref: base_cmt={:?}" , base_cmt) ;
1036
1040
1037
1041
let base_cmt_ty = base_cmt. ty ;
@@ -1049,7 +1053,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1049
1053
ty:: TyRawPtr ( ref mt) => UnsafePtr ( mt. mutbl ) ,
1050
1054
ty:: TyRef ( r, _, mutbl) => {
1051
1055
let bk = ty:: BorrowKind :: from_mutbl ( mutbl) ;
1052
- if implicit { Implicit ( bk , r ) } else { BorrowedPtr ( bk, r) }
1056
+ BorrowedPtr ( bk, r)
1053
1057
}
1054
1058
ref ty => bug ! ( "unexpected type in cat_deref: {:?}" , ty)
1055
1059
} ;
@@ -1060,7 +1064,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1060
1064
mutbl : MutabilityCategory :: from_pointer_kind ( base_cmt. mutbl , ptr) ,
1061
1065
cat : Categorization :: Deref ( base_cmt, ptr) ,
1062
1066
ty : deref_ty,
1063
- note : NoteNone
1067
+ note : note ,
1064
1068
} ;
1065
1069
debug ! ( "cat_deref ret {:?}" , ret) ;
1066
1070
Ok ( ret)
@@ -1193,7 +1197,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1193
1197
// step out of sync again. So you'll see below that we always
1194
1198
// get the type of the *subpattern* and use that.
1195
1199
1196
- debug ! ( "cat_pattern: {:?} cmt={:?}" , pat, cmt) ;
1200
+ debug ! ( "cat_pattern(pat= {:?}, cmt={:?}) " , pat, cmt) ;
1197
1201
1198
1202
// If (pattern) adjustments are active for this pattern, adjust the `cmt` correspondingly.
1199
1203
// `cmt`s are constructed differently from patterns. For example, in
@@ -1231,10 +1235,13 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1231
1235
. pat_adjustments ( )
1232
1236
. get ( pat. hir_id )
1233
1237
. map ( |v| v. len ( ) )
1234
- . unwrap_or ( 0 ) {
1235
- cmt = Rc :: new ( self . cat_deref ( pat, cmt, true /* implicit */ ) ?) ;
1238
+ . unwrap_or ( 0 )
1239
+ {
1240
+ debug ! ( "cat_pattern: applying adjustment to cmt={:?}" , cmt) ;
1241
+ cmt = Rc :: new ( self . cat_deref ( pat, cmt, NoteNone ) ?) ;
1236
1242
}
1237
1243
let cmt = cmt; // lose mutability
1244
+ debug ! ( "cat_pattern: applied adjustment derefs to get cmt={:?}" , cmt) ;
1238
1245
1239
1246
// Invoke the callback, but only now, after the `cmt` has adjusted.
1240
1247
//
@@ -1330,7 +1337,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1330
1337
// box p1, &p1, &mut p1. we can ignore the mutability of
1331
1338
// PatKind::Ref since that information is already contained
1332
1339
// in the type.
1333
- let subcmt = Rc :: new ( self . cat_deref ( pat, cmt, false ) ?) ;
1340
+ let subcmt = Rc :: new ( self . cat_deref ( pat, cmt, NoteNone ) ?) ;
1334
1341
self . cat_pattern_ ( subcmt, & subpat, op) ?;
1335
1342
}
1336
1343
@@ -1391,7 +1398,6 @@ impl<'tcx> cmt_<'tcx> {
1391
1398
Categorization :: Local ( ..) |
1392
1399
Categorization :: Deref ( _, UnsafePtr ( ..) ) |
1393
1400
Categorization :: Deref ( _, BorrowedPtr ( ..) ) |
1394
- Categorization :: Deref ( _, Implicit ( ..) ) |
1395
1401
Categorization :: Upvar ( ..) => {
1396
1402
( * self ) . clone ( )
1397
1403
}
@@ -1411,9 +1417,7 @@ impl<'tcx> cmt_<'tcx> {
1411
1417
1412
1418
match self . cat {
1413
1419
Categorization :: Deref ( ref b, BorrowedPtr ( ty:: MutBorrow , _) ) |
1414
- Categorization :: Deref ( ref b, Implicit ( ty:: MutBorrow , _) ) |
1415
1420
Categorization :: Deref ( ref b, BorrowedPtr ( ty:: UniqueImmBorrow , _) ) |
1416
- Categorization :: Deref ( ref b, Implicit ( ty:: UniqueImmBorrow , _) ) |
1417
1421
Categorization :: Deref ( ref b, Unique ) |
1418
1422
Categorization :: Downcast ( ref b, _) |
1419
1423
Categorization :: Interior ( ref b, _) => {
@@ -1436,8 +1440,7 @@ impl<'tcx> cmt_<'tcx> {
1436
1440
}
1437
1441
}
1438
1442
1439
- Categorization :: Deref ( _, BorrowedPtr ( ty:: ImmBorrow , _) ) |
1440
- Categorization :: Deref ( _, Implicit ( ty:: ImmBorrow , _) ) => {
1443
+ Categorization :: Deref ( _, BorrowedPtr ( ty:: ImmBorrow , _) ) => {
1441
1444
FreelyAliasable ( AliasableBorrowed )
1442
1445
}
1443
1446
}
@@ -1460,7 +1463,7 @@ impl<'tcx> cmt_<'tcx> {
1460
1463
_ => bug ! ( )
1461
1464
} )
1462
1465
}
1463
- NoteNone => None
1466
+ NoteIndex | NoteNone => None
1464
1467
}
1465
1468
}
1466
1469
@@ -1487,17 +1490,17 @@ impl<'tcx> cmt_<'tcx> {
1487
1490
Some ( _) => bug ! ( ) ,
1488
1491
None => {
1489
1492
match pk {
1490
- Implicit ( ..) => {
1491
- format ! ( "indexed content" )
1492
- }
1493
1493
Unique => {
1494
1494
format ! ( "`Box` content" )
1495
1495
}
1496
1496
UnsafePtr ( ..) => {
1497
1497
format ! ( "dereference of raw pointer" )
1498
1498
}
1499
1499
BorrowedPtr ( ..) => {
1500
- format ! ( "borrowed content" )
1500
+ match self . note {
1501
+ NoteIndex => format ! ( "indexed content" ) ,
1502
+ _ => format ! ( "borrowed content" ) ,
1503
+ }
1501
1504
}
1502
1505
}
1503
1506
}
@@ -1525,12 +1528,9 @@ impl<'tcx> cmt_<'tcx> {
1525
1528
pub fn ptr_sigil ( ptr : PointerKind ) -> & ' static str {
1526
1529
match ptr {
1527
1530
Unique => "Box" ,
1528
- BorrowedPtr ( ty:: ImmBorrow , _) |
1529
- Implicit ( ty:: ImmBorrow , _) => "&" ,
1530
- BorrowedPtr ( ty:: MutBorrow , _) |
1531
- Implicit ( ty:: MutBorrow , _) => "&mut" ,
1532
- BorrowedPtr ( ty:: UniqueImmBorrow , _) |
1533
- Implicit ( ty:: UniqueImmBorrow , _) => "&unique" ,
1531
+ BorrowedPtr ( ty:: ImmBorrow , _) => "&" ,
1532
+ BorrowedPtr ( ty:: MutBorrow , _) => "&mut" ,
1533
+ BorrowedPtr ( ty:: UniqueImmBorrow , _) => "&unique" ,
1534
1534
UnsafePtr ( _) => "*" ,
1535
1535
}
1536
1536
}
0 commit comments