@@ -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 )
@@ -998,12 +995,18 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
998
995
ret
999
996
}
1000
997
1001
- fn cat_overloaded_place ( & self ,
1002
- expr : & hir:: Expr ,
1003
- base : & hir:: Expr ,
1004
- implicit : bool )
1005
- -> McResult < cmt_ < ' tcx > > {
1006
- debug ! ( "cat_overloaded_place: implicit={}" , implicit) ;
998
+ fn cat_overloaded_place (
999
+ & self ,
1000
+ expr : & hir:: Expr ,
1001
+ base : & hir:: Expr ,
1002
+ note : Note ,
1003
+ ) -> McResult < cmt_ < ' tcx > > {
1004
+ debug ! (
1005
+ "cat_overloaded_place(expr={:?}, base={:?}, note={:?})" ,
1006
+ expr,
1007
+ base,
1008
+ note,
1009
+ ) ;
1007
1010
1008
1011
// Reconstruct the output assuming it's a reference with the
1009
1012
// same region and mutability as the receiver. This holds for
@@ -1023,14 +1026,15 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1023
1026
} ) ;
1024
1027
1025
1028
let base_cmt = Rc :: new ( self . cat_rvalue_node ( expr. id , expr. span , ref_ty) ) ;
1026
- self . cat_deref ( expr, base_cmt, implicit )
1029
+ self . cat_deref ( expr, base_cmt, note )
1027
1030
}
1028
1031
1029
- pub fn cat_deref < N : ast_node > ( & self ,
1030
- node : & N ,
1031
- base_cmt : cmt < ' tcx > ,
1032
- implicit : bool )
1033
- -> McResult < cmt_ < ' tcx > > {
1032
+ pub fn cat_deref (
1033
+ & self ,
1034
+ node : & impl ast_node ,
1035
+ base_cmt : cmt < ' tcx > ,
1036
+ note : Note ,
1037
+ ) -> McResult < cmt_ < ' tcx > > {
1034
1038
debug ! ( "cat_deref: base_cmt={:?}" , base_cmt) ;
1035
1039
1036
1040
let base_cmt_ty = base_cmt. ty ;
@@ -1048,7 +1052,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1048
1052
ty:: TyRawPtr ( ref mt) => UnsafePtr ( mt. mutbl ) ,
1049
1053
ty:: TyRef ( r, mt) => {
1050
1054
let bk = ty:: BorrowKind :: from_mutbl ( mt. mutbl ) ;
1051
- if implicit { Implicit ( bk , r ) } else { BorrowedPtr ( bk, r) }
1055
+ BorrowedPtr ( bk, r)
1052
1056
}
1053
1057
ref ty => bug ! ( "unexpected type in cat_deref: {:?}" , ty)
1054
1058
} ;
@@ -1059,7 +1063,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1059
1063
mutbl : MutabilityCategory :: from_pointer_kind ( base_cmt. mutbl , ptr) ,
1060
1064
cat : Categorization :: Deref ( base_cmt, ptr) ,
1061
1065
ty : deref_ty,
1062
- note : NoteNone
1066
+ note : note ,
1063
1067
} ;
1064
1068
debug ! ( "cat_deref ret {:?}" , ret) ;
1065
1069
Ok ( ret)
@@ -1192,7 +1196,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1192
1196
// step out of sync again. So you'll see below that we always
1193
1197
// get the type of the *subpattern* and use that.
1194
1198
1195
- debug ! ( "cat_pattern: {:?} cmt={:?}" , pat, cmt) ;
1199
+ debug ! ( "cat_pattern(pat= {:?}, cmt={:?}) " , pat, cmt) ;
1196
1200
1197
1201
// If (pattern) adjustments are active for this pattern, adjust the `cmt` correspondingly.
1198
1202
// `cmt`s are constructed differently from patterns. For example, in
@@ -1230,10 +1234,13 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1230
1234
. pat_adjustments ( )
1231
1235
. get ( pat. hir_id )
1232
1236
. map ( |v| v. len ( ) )
1233
- . unwrap_or ( 0 ) {
1234
- cmt = Rc :: new ( self . cat_deref ( pat, cmt, true /* implicit */ ) ?) ;
1237
+ . unwrap_or ( 0 )
1238
+ {
1239
+ debug ! ( "cat_pattern: applying adjustment to cmt={:?}" , cmt) ;
1240
+ cmt = Rc :: new ( self . cat_deref ( pat, cmt, NoteNone ) ?) ;
1235
1241
}
1236
1242
let cmt = cmt; // lose mutability
1243
+ debug ! ( "cat_pattern: applied adjustment derefs to get cmt={:?}" , cmt) ;
1237
1244
1238
1245
// Invoke the callback, but only now, after the `cmt` has adjusted.
1239
1246
//
@@ -1329,7 +1336,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1329
1336
// box p1, &p1, &mut p1. we can ignore the mutability of
1330
1337
// PatKind::Ref since that information is already contained
1331
1338
// in the type.
1332
- let subcmt = Rc :: new ( self . cat_deref ( pat, cmt, false ) ?) ;
1339
+ let subcmt = Rc :: new ( self . cat_deref ( pat, cmt, NoteNone ) ?) ;
1333
1340
self . cat_pattern_ ( subcmt, & subpat, op) ?;
1334
1341
}
1335
1342
@@ -1390,7 +1397,6 @@ impl<'tcx> cmt_<'tcx> {
1390
1397
Categorization :: Local ( ..) |
1391
1398
Categorization :: Deref ( _, UnsafePtr ( ..) ) |
1392
1399
Categorization :: Deref ( _, BorrowedPtr ( ..) ) |
1393
- Categorization :: Deref ( _, Implicit ( ..) ) |
1394
1400
Categorization :: Upvar ( ..) => {
1395
1401
( * self ) . clone ( )
1396
1402
}
@@ -1410,9 +1416,7 @@ impl<'tcx> cmt_<'tcx> {
1410
1416
1411
1417
match self . cat {
1412
1418
Categorization :: Deref ( ref b, BorrowedPtr ( ty:: MutBorrow , _) ) |
1413
- Categorization :: Deref ( ref b, Implicit ( ty:: MutBorrow , _) ) |
1414
1419
Categorization :: Deref ( ref b, BorrowedPtr ( ty:: UniqueImmBorrow , _) ) |
1415
- Categorization :: Deref ( ref b, Implicit ( ty:: UniqueImmBorrow , _) ) |
1416
1420
Categorization :: Deref ( ref b, Unique ) |
1417
1421
Categorization :: Downcast ( ref b, _) |
1418
1422
Categorization :: Interior ( ref b, _) => {
@@ -1435,8 +1439,7 @@ impl<'tcx> cmt_<'tcx> {
1435
1439
}
1436
1440
}
1437
1441
1438
- Categorization :: Deref ( _, BorrowedPtr ( ty:: ImmBorrow , _) ) |
1439
- Categorization :: Deref ( _, Implicit ( ty:: ImmBorrow , _) ) => {
1442
+ Categorization :: Deref ( _, BorrowedPtr ( ty:: ImmBorrow , _) ) => {
1440
1443
FreelyAliasable ( AliasableBorrowed )
1441
1444
}
1442
1445
}
@@ -1459,7 +1462,7 @@ impl<'tcx> cmt_<'tcx> {
1459
1462
_ => bug ! ( )
1460
1463
} )
1461
1464
}
1462
- NoteNone => None
1465
+ NoteIndex | NoteNone => None
1463
1466
}
1464
1467
}
1465
1468
@@ -1486,17 +1489,17 @@ impl<'tcx> cmt_<'tcx> {
1486
1489
Some ( _) => bug ! ( ) ,
1487
1490
None => {
1488
1491
match pk {
1489
- Implicit ( ..) => {
1490
- format ! ( "indexed content" )
1491
- }
1492
1492
Unique => {
1493
1493
format ! ( "`Box` content" )
1494
1494
}
1495
1495
UnsafePtr ( ..) => {
1496
1496
format ! ( "dereference of raw pointer" )
1497
1497
}
1498
1498
BorrowedPtr ( ..) => {
1499
- format ! ( "borrowed content" )
1499
+ match self . note {
1500
+ NoteIndex => format ! ( "indexed content" ) ,
1501
+ _ => format ! ( "borrowed content" ) ,
1502
+ }
1500
1503
}
1501
1504
}
1502
1505
}
@@ -1524,12 +1527,9 @@ impl<'tcx> cmt_<'tcx> {
1524
1527
pub fn ptr_sigil ( ptr : PointerKind ) -> & ' static str {
1525
1528
match ptr {
1526
1529
Unique => "Box" ,
1527
- BorrowedPtr ( ty:: ImmBorrow , _) |
1528
- Implicit ( ty:: ImmBorrow , _) => "&" ,
1529
- BorrowedPtr ( ty:: MutBorrow , _) |
1530
- Implicit ( ty:: MutBorrow , _) => "&mut" ,
1531
- BorrowedPtr ( ty:: UniqueImmBorrow , _) |
1532
- Implicit ( ty:: UniqueImmBorrow , _) => "&unique" ,
1530
+ BorrowedPtr ( ty:: ImmBorrow , _) => "&" ,
1531
+ BorrowedPtr ( ty:: MutBorrow , _) => "&mut" ,
1532
+ BorrowedPtr ( ty:: UniqueImmBorrow , _) => "&unique" ,
1533
1533
UnsafePtr ( _) => "*" ,
1534
1534
}
1535
1535
}
0 commit comments