@@ -95,7 +95,7 @@ pub enum Categorization<'tcx> {
9595 StaticItem ,
9696 Upvar ( Upvar ) , // upvar referenced by closure env
9797 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
9999 Interior ( cmt < ' tcx > , InteriorKind ) , // something interior: field, tuple, etc
100100 Downcast ( cmt < ' tcx > , DefId ) , // selects a particular enum variant (*1)
101101
@@ -120,9 +120,6 @@ pub enum PointerKind<'tcx> {
120120
121121 /// `*T`
122122 UnsafePtr ( hir:: Mutability ) ,
123-
124- /// Implicit deref of the `&T` that results from an overloaded index `[]`.
125- Implicit ( ty:: BorrowKind , ty:: Region < ' tcx > ) ,
126123}
127124
128125// We use the term "interior" to mean "something reachable from the
@@ -161,6 +158,7 @@ pub enum MutabilityCategory {
161158pub enum Note {
162159 NoteClosureEnv ( ty:: UpvarId ) , // Deref through closure env
163160 NoteUpvarRef ( ty:: UpvarId ) , // Deref through by-ref upvar
161+ NoteIndex , // Deref as part of desugaring `x[]` into its two components
164162 NoteNone // Nothing special
165163}
166164
@@ -224,8 +222,7 @@ impl<'tcx> cmt_<'tcx> {
224222
225223 pub fn immutability_blame ( & self ) -> Option < ImmutabilityBlame < ' tcx > > {
226224 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 , _) ) => {
229226 // try to figure out where the immutable reference came from
230227 match base_cmt. cat {
231228 Categorization :: Local ( node_id) =>
@@ -321,7 +318,7 @@ impl MutabilityCategory {
321318 Unique => {
322319 base_mutbl. inherit ( )
323320 }
324- BorrowedPtr ( borrow_kind, _) | Implicit ( borrow_kind , _ ) => {
321+ BorrowedPtr ( borrow_kind, _) => {
325322 MutabilityCategory :: from_borrow_kind ( borrow_kind)
326323 }
327324 UnsafePtr ( m) => {
@@ -610,7 +607,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
610607 } else {
611608 previous ( ) ?
612609 } ;
613- self . cat_deref ( expr, base, false )
610+ self . cat_deref ( expr, base, NoteNone )
614611 }
615612
616613 adjustment:: Adjust :: NeverToAny |
@@ -633,10 +630,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
633630 match expr. node {
634631 hir:: ExprUnary ( hir:: UnDeref , ref e_base) => {
635632 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 )
637634 } else {
638635 let base_cmt = self . cat_expr ( & e_base) ?;
639- self . cat_deref ( expr, base_cmt, false )
636+ self . cat_deref ( expr, base_cmt, NoteNone )
640637 }
641638 }
642639
@@ -661,7 +658,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
661658 // The call to index() returns a `&T` value, which
662659 // is an rvalue. That is what we will be
663660 // dereferencing.
664- self . cat_overloaded_place ( expr, base, true )
661+ self . cat_overloaded_place ( expr, base, NoteIndex )
665662 } else {
666663 let base_cmt = self . cat_expr ( & base) ?;
667664 self . cat_index ( expr, base_cmt, expr_ty, InteriorOffsetKind :: Index )
@@ -1012,12 +1009,18 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
10121009 ret
10131010 }
10141011
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+ ) ;
10211024
10221025 // Reconstruct the output assuming it's a reference with the
10231026 // same region and mutability as the receiver. This holds for
@@ -1037,14 +1040,15 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
10371040 } ) ;
10381041
10391042 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 )
10411044 }
10421045
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 > > {
10481052 debug ! ( "cat_deref: base_cmt={:?}" , base_cmt) ;
10491053
10501054 let base_cmt_ty = base_cmt. ty ;
@@ -1060,9 +1064,9 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
10601064 let ptr = match base_cmt. ty . sty {
10611065 ty:: TyAdt ( def, ..) if def. is_box ( ) => Unique ,
10621066 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)
10661070 }
10671071 ref ty => bug ! ( "unexpected type in cat_deref: {:?}" , ty)
10681072 } ;
@@ -1073,7 +1077,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
10731077 mutbl : MutabilityCategory :: from_pointer_kind ( base_cmt. mutbl , ptr) ,
10741078 cat : Categorization :: Deref ( base_cmt, ptr) ,
10751079 ty : deref_ty,
1076- note : NoteNone
1080+ note : note ,
10771081 } ) ;
10781082 debug ! ( "cat_deref ret {:?}" , ret) ;
10791083 Ok ( ret)
@@ -1207,7 +1211,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
12071211 // step out of sync again. So you'll see below that we always
12081212 // get the type of the *subpattern* and use that.
12091213
1210- debug ! ( "cat_pattern: {:?} cmt={:?}" , pat, cmt) ;
1214+ debug ! ( "cat_pattern(pat= {:?}, cmt={:?}) " , pat, cmt) ;
12111215
12121216 // If (pattern) adjustments are active for this pattern, adjust the `cmt` correspondingly.
12131217 // `cmt`s are constructed differently from patterns. For example, in
@@ -1245,10 +1249,13 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
12451249 . pat_adjustments ( )
12461250 . get ( pat. hir_id )
12471251 . 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 ) ?;
12501256 }
12511257 let cmt = cmt; // lose mutability
1258+ debug ! ( "cat_pattern: applied adjustment derefs to get cmt={:?}" , cmt) ;
12521259
12531260 // Invoke the callback, but only now, after the `cmt` has adjusted.
12541261 //
@@ -1342,7 +1349,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
13421349 // box p1, &p1, &mut p1. we can ignore the mutability of
13431350 // PatKind::Ref since that information is already contained
13441351 // in the type.
1345- let subcmt = self . cat_deref ( pat, cmt, false ) ?;
1352+ let subcmt = self . cat_deref ( pat, cmt, NoteNone ) ?;
13461353 self . cat_pattern_ ( subcmt, & subpat, op) ?;
13471354 }
13481355
@@ -1403,7 +1410,6 @@ impl<'tcx> cmt_<'tcx> {
14031410 Categorization :: Local ( ..) |
14041411 Categorization :: Deref ( _, UnsafePtr ( ..) ) |
14051412 Categorization :: Deref ( _, BorrowedPtr ( ..) ) |
1406- Categorization :: Deref ( _, Implicit ( ..) ) |
14071413 Categorization :: Upvar ( ..) => {
14081414 Rc :: new ( ( * self ) . clone ( ) )
14091415 }
@@ -1423,9 +1429,7 @@ impl<'tcx> cmt_<'tcx> {
14231429
14241430 match self . cat {
14251431 Categorization :: Deref ( ref b, BorrowedPtr ( ty:: MutBorrow , _) ) |
1426- Categorization :: Deref ( ref b, Implicit ( ty:: MutBorrow , _) ) |
14271432 Categorization :: Deref ( ref b, BorrowedPtr ( ty:: UniqueImmBorrow , _) ) |
1428- Categorization :: Deref ( ref b, Implicit ( ty:: UniqueImmBorrow , _) ) |
14291433 Categorization :: Deref ( ref b, Unique ) |
14301434 Categorization :: Downcast ( ref b, _) |
14311435 Categorization :: Interior ( ref b, _) => {
@@ -1448,8 +1452,7 @@ impl<'tcx> cmt_<'tcx> {
14481452 }
14491453 }
14501454
1451- Categorization :: Deref ( _, BorrowedPtr ( ty:: ImmBorrow , _) ) |
1452- Categorization :: Deref ( _, Implicit ( ty:: ImmBorrow , _) ) => {
1455+ Categorization :: Deref ( _, BorrowedPtr ( ty:: ImmBorrow , _) ) => {
14531456 FreelyAliasable ( AliasableBorrowed )
14541457 }
14551458 }
@@ -1471,7 +1474,7 @@ impl<'tcx> cmt_<'tcx> {
14711474 _ => bug ! ( )
14721475 } )
14731476 }
1474- NoteNone => None
1477+ NoteIndex | NoteNone => None
14751478 }
14761479 }
14771480
@@ -1500,17 +1503,17 @@ impl<'tcx> cmt_<'tcx> {
15001503 Some ( _) => bug ! ( ) ,
15011504 None => {
15021505 match pk {
1503- Implicit ( ..) => {
1504- format ! ( "indexed content" )
1505- }
15061506 Unique => {
15071507 format ! ( "`Box` content" )
15081508 }
15091509 UnsafePtr ( ..) => {
15101510 format ! ( "dereference of raw pointer" )
15111511 }
15121512 BorrowedPtr ( ..) => {
1513- format ! ( "borrowed content" )
1513+ match self . note {
1514+ NoteIndex => format ! ( "indexed content" ) ,
1515+ _ => format ! ( "borrowed content" ) ,
1516+ }
15141517 }
15151518 }
15161519 }
@@ -1541,12 +1544,9 @@ impl<'tcx> cmt_<'tcx> {
15411544pub fn ptr_sigil ( ptr : PointerKind ) -> & ' static str {
15421545 match ptr {
15431546 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" ,
15501550 UnsafePtr ( _) => "*" ,
15511551 }
15521552}
0 commit comments