@@ -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
@@ -172,6 +169,7 @@ pub enum MutabilityCategory {
172169pub enum Note {
173170 NoteClosureEnv ( ty:: UpvarId ) , // Deref through closure env
174171 NoteUpvarRef ( ty:: UpvarId ) , // Deref through by-ref upvar
172+ NoteIndex , // Deref as part of desugaring `x[]` into its two components
175173 NoteNone // Nothing special
176174}
177175
@@ -231,8 +229,7 @@ impl<'tcx> cmt_<'tcx> {
231229
232230 pub fn immutability_blame ( & self ) -> Option < ImmutabilityBlame < ' tcx > > {
233231 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 , _) ) => {
236233 // try to figure out where the immutable reference came from
237234 match base_cmt. cat {
238235 Categorization :: Local ( node_id) =>
@@ -328,7 +325,7 @@ impl MutabilityCategory {
328325 Unique => {
329326 base_mutbl. inherit ( )
330327 }
331- BorrowedPtr ( borrow_kind, _) | Implicit ( borrow_kind , _ ) => {
328+ BorrowedPtr ( borrow_kind, _) => {
332329 MutabilityCategory :: from_borrow_kind ( borrow_kind)
333330 }
334331 UnsafePtr ( m) => {
@@ -617,7 +614,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
617614 } else {
618615 previous ( ) ?
619616 } ) ;
620- self . cat_deref ( expr, base, false )
617+ self . cat_deref ( expr, base, NoteNone )
621618 }
622619
623620 adjustment:: Adjust :: NeverToAny |
@@ -640,10 +637,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
640637 match expr. node {
641638 hir:: ExprUnary ( hir:: UnDeref , ref e_base) => {
642639 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 )
644641 } else {
645642 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 )
647644 }
648645 }
649646
@@ -664,7 +661,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
664661 // The call to index() returns a `&T` value, which
665662 // is an rvalue. That is what we will be
666663 // dereferencing.
667- self . cat_overloaded_place ( expr, base, true )
664+ self . cat_overloaded_place ( expr, base, NoteIndex )
668665 } else {
669666 let base_cmt = Rc :: new ( self . cat_expr ( & base) ?) ;
670667 self . cat_index ( expr, base_cmt, expr_ty, InteriorOffsetKind :: Index )
@@ -999,12 +996,18 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
999996 ret
1000997 }
1001998
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+ ) ;
10081011
10091012 // Reconstruct the output assuming it's a reference with the
10101013 // same region and mutability as the receiver. This holds for
@@ -1024,14 +1027,15 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
10241027 } ) ;
10251028
10261029 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 )
10281031 }
10291032
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 > > {
10351039 debug ! ( "cat_deref: base_cmt={:?}" , base_cmt) ;
10361040
10371041 let base_cmt_ty = base_cmt. ty ;
@@ -1049,7 +1053,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
10491053 ty:: TyRawPtr ( ref mt) => UnsafePtr ( mt. mutbl ) ,
10501054 ty:: TyRef ( r, _, mutbl) => {
10511055 let bk = ty:: BorrowKind :: from_mutbl ( mutbl) ;
1052- if implicit { Implicit ( bk , r ) } else { BorrowedPtr ( bk, r) }
1056+ BorrowedPtr ( bk, r)
10531057 }
10541058 ref ty => bug ! ( "unexpected type in cat_deref: {:?}" , ty)
10551059 } ;
@@ -1060,7 +1064,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
10601064 mutbl : MutabilityCategory :: from_pointer_kind ( base_cmt. mutbl , ptr) ,
10611065 cat : Categorization :: Deref ( base_cmt, ptr) ,
10621066 ty : deref_ty,
1063- note : NoteNone
1067+ note : note ,
10641068 } ;
10651069 debug ! ( "cat_deref ret {:?}" , ret) ;
10661070 Ok ( ret)
@@ -1193,7 +1197,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
11931197 // step out of sync again. So you'll see below that we always
11941198 // get the type of the *subpattern* and use that.
11951199
1196- debug ! ( "cat_pattern: {:?} cmt={:?}" , pat, cmt) ;
1200+ debug ! ( "cat_pattern(pat= {:?}, cmt={:?}) " , pat, cmt) ;
11971201
11981202 // If (pattern) adjustments are active for this pattern, adjust the `cmt` correspondingly.
11991203 // `cmt`s are constructed differently from patterns. For example, in
@@ -1231,10 +1235,13 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
12311235 . pat_adjustments ( )
12321236 . get ( pat. hir_id )
12331237 . 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 ) ?) ;
12361242 }
12371243 let cmt = cmt; // lose mutability
1244+ debug ! ( "cat_pattern: applied adjustment derefs to get cmt={:?}" , cmt) ;
12381245
12391246 // Invoke the callback, but only now, after the `cmt` has adjusted.
12401247 //
@@ -1330,7 +1337,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
13301337 // box p1, &p1, &mut p1. we can ignore the mutability of
13311338 // PatKind::Ref since that information is already contained
13321339 // 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 ) ?) ;
13341341 self . cat_pattern_ ( subcmt, & subpat, op) ?;
13351342 }
13361343
@@ -1391,7 +1398,6 @@ impl<'tcx> cmt_<'tcx> {
13911398 Categorization :: Local ( ..) |
13921399 Categorization :: Deref ( _, UnsafePtr ( ..) ) |
13931400 Categorization :: Deref ( _, BorrowedPtr ( ..) ) |
1394- Categorization :: Deref ( _, Implicit ( ..) ) |
13951401 Categorization :: Upvar ( ..) => {
13961402 ( * self ) . clone ( )
13971403 }
@@ -1411,9 +1417,7 @@ impl<'tcx> cmt_<'tcx> {
14111417
14121418 match self . cat {
14131419 Categorization :: Deref ( ref b, BorrowedPtr ( ty:: MutBorrow , _) ) |
1414- Categorization :: Deref ( ref b, Implicit ( ty:: MutBorrow , _) ) |
14151420 Categorization :: Deref ( ref b, BorrowedPtr ( ty:: UniqueImmBorrow , _) ) |
1416- Categorization :: Deref ( ref b, Implicit ( ty:: UniqueImmBorrow , _) ) |
14171421 Categorization :: Deref ( ref b, Unique ) |
14181422 Categorization :: Downcast ( ref b, _) |
14191423 Categorization :: Interior ( ref b, _) => {
@@ -1436,8 +1440,7 @@ impl<'tcx> cmt_<'tcx> {
14361440 }
14371441 }
14381442
1439- Categorization :: Deref ( _, BorrowedPtr ( ty:: ImmBorrow , _) ) |
1440- Categorization :: Deref ( _, Implicit ( ty:: ImmBorrow , _) ) => {
1443+ Categorization :: Deref ( _, BorrowedPtr ( ty:: ImmBorrow , _) ) => {
14411444 FreelyAliasable ( AliasableBorrowed )
14421445 }
14431446 }
@@ -1460,7 +1463,7 @@ impl<'tcx> cmt_<'tcx> {
14601463 _ => bug ! ( )
14611464 } )
14621465 }
1463- NoteNone => None
1466+ NoteIndex | NoteNone => None
14641467 }
14651468 }
14661469
@@ -1487,17 +1490,17 @@ impl<'tcx> cmt_<'tcx> {
14871490 Some ( _) => bug ! ( ) ,
14881491 None => {
14891492 match pk {
1490- Implicit ( ..) => {
1491- format ! ( "indexed content" )
1492- }
14931493 Unique => {
14941494 format ! ( "`Box` content" )
14951495 }
14961496 UnsafePtr ( ..) => {
14971497 format ! ( "dereference of raw pointer" )
14981498 }
14991499 BorrowedPtr ( ..) => {
1500- format ! ( "borrowed content" )
1500+ match self . note {
1501+ NoteIndex => format ! ( "indexed content" ) ,
1502+ _ => format ! ( "borrowed content" ) ,
1503+ }
15011504 }
15021505 }
15031506 }
@@ -1525,12 +1528,9 @@ impl<'tcx> cmt_<'tcx> {
15251528pub fn ptr_sigil ( ptr : PointerKind ) -> & ' static str {
15261529 match ptr {
15271530 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" ,
15341534 UnsafePtr ( _) => "*" ,
15351535 }
15361536}
0 commit comments