@@ -67,7 +67,6 @@ pub use self::ElementKind::*;
67
67
pub use self :: MutabilityCategory :: * ;
68
68
pub use self :: AliasableReason :: * ;
69
69
pub use self :: Note :: * ;
70
- pub use self :: deref_kind:: * ;
71
70
72
71
use self :: Aliasability :: * ;
73
72
@@ -195,47 +194,6 @@ pub struct cmt_<'tcx> {
195
194
196
195
pub type cmt < ' tcx > = Rc < cmt_ < ' tcx > > ;
197
196
198
- // We pun on *T to mean both actual deref of a ptr as well
199
- // as accessing of components:
200
- #[ derive( Copy , Clone ) ]
201
- pub enum deref_kind < ' tcx > {
202
- deref_ptr( PointerKind < ' tcx > ) ,
203
- deref_interior( InteriorKind ) ,
204
- }
205
-
206
- type DerefKindContext = Option < InteriorOffsetKind > ;
207
-
208
- // Categorizes a derefable type. Note that we include vectors and strings as
209
- // derefable (we model an index as the combination of a deref and then a
210
- // pointer adjustment).
211
- fn deref_kind ( t : Ty , context : DerefKindContext ) -> McResult < deref_kind > {
212
- match t. sty {
213
- ty:: TyBox ( _) => {
214
- Ok ( deref_ptr ( Unique ) )
215
- }
216
-
217
- ty:: TyRef ( r, mt) => {
218
- let kind = ty:: BorrowKind :: from_mutbl ( mt. mutbl ) ;
219
- Ok ( deref_ptr ( BorrowedPtr ( kind, r) ) )
220
- }
221
-
222
- ty:: TyRawPtr ( ref mt) => {
223
- Ok ( deref_ptr ( UnsafePtr ( mt. mutbl ) ) )
224
- }
225
-
226
- ty:: TyArray ( ..) | ty:: TySlice ( _) => {
227
- // no deref of indexed content without supplying InteriorOffsetKind
228
- if let Some ( context) = context {
229
- Ok ( deref_interior ( InteriorElement ( context, ElementKind :: VecElement ) ) )
230
- } else {
231
- Err ( ( ) )
232
- }
233
- }
234
-
235
- _ => Err ( ( ) ) ,
236
- }
237
- }
238
-
239
197
pub trait ast_node {
240
198
fn id ( & self ) -> ast:: NodeId ;
241
199
fn span ( & self ) -> Span ;
@@ -472,7 +430,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
472
430
autoderefs,
473
431
cmt) ;
474
432
for deref in 1 ..autoderefs + 1 {
475
- cmt = self . cat_deref ( expr, cmt, deref, None ) ?;
433
+ cmt = self . cat_deref ( expr, cmt, deref) ?;
476
434
}
477
435
return Ok ( cmt) ;
478
436
}
@@ -484,7 +442,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
484
442
match expr. node {
485
443
hir:: ExprUnary ( hir:: UnDeref , ref e_base) => {
486
444
let base_cmt = self . cat_expr ( & e_base) ?;
487
- self . cat_deref ( expr, base_cmt, 0 , None )
445
+ self . cat_deref ( expr, base_cmt, 0 )
488
446
}
489
447
490
448
hir:: ExprField ( ref base, f_name) => {
@@ -503,7 +461,6 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
503
461
504
462
hir:: ExprIndex ( ref base, _) => {
505
463
let method_call = ty:: MethodCall :: expr ( expr. id ( ) ) ;
506
- let context = InteriorOffsetKind :: Index ;
507
464
match self . infcx . node_method_ty ( method_call) {
508
465
Some ( method_ty) => {
509
466
// If this is an index implemented by a method call, then it
@@ -525,10 +482,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
525
482
// is an rvalue. That is what we will be
526
483
// dereferencing.
527
484
let base_cmt = self . cat_rvalue_node ( expr. id ( ) , expr. span ( ) , ret_ty) ;
528
- self . cat_deref_common ( expr, base_cmt, 1 , elem_ty, Some ( context ) , true )
485
+ Ok ( self . cat_deref_common ( expr, base_cmt, 1 , elem_ty, true ) )
529
486
}
530
487
None => {
531
- self . cat_index ( expr, self . cat_expr ( & base) ?, context )
488
+ self . cat_index ( expr, self . cat_expr ( & base) ?, InteriorOffsetKind :: Index )
532
489
}
533
490
}
534
491
}
@@ -903,8 +860,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
903
860
fn cat_deref < N : ast_node > ( & self ,
904
861
node : & N ,
905
862
base_cmt : cmt < ' tcx > ,
906
- deref_cnt : usize ,
907
- deref_context : DerefKindContext )
863
+ deref_cnt : usize )
908
864
-> McResult < cmt < ' tcx > > {
909
865
let method_call = ty:: MethodCall {
910
866
expr_id : node. id ( ) ,
@@ -926,12 +882,9 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
926
882
let base_cmt_ty = base_cmt. ty ;
927
883
match base_cmt_ty. builtin_deref ( true , ty:: NoPreference ) {
928
884
Some ( mt) => {
929
- let ret = self . cat_deref_common ( node, base_cmt, deref_cnt,
930
- mt. ty ,
931
- deref_context,
932
- /* implicit: */ false ) ;
885
+ let ret = self . cat_deref_common ( node, base_cmt, deref_cnt, mt. ty , false ) ;
933
886
debug ! ( "cat_deref ret {:?}" , ret) ;
934
- ret
887
+ Ok ( ret)
935
888
}
936
889
None => {
937
890
debug ! ( "Explicit deref of non-derefable type: {:?}" ,
@@ -946,40 +899,29 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
946
899
base_cmt : cmt < ' tcx > ,
947
900
deref_cnt : usize ,
948
901
deref_ty : Ty < ' tcx > ,
949
- deref_context : DerefKindContext ,
950
902
implicit : bool )
951
- -> McResult < cmt < ' tcx > >
903
+ -> cmt < ' tcx >
952
904
{
953
- let ( m, cat) = match deref_kind ( base_cmt. ty , deref_context) ? {
954
- deref_ptr( ptr) => {
955
- let ptr = if implicit {
956
- match ptr {
957
- BorrowedPtr ( bk, r) => Implicit ( bk, r) ,
958
- _ => span_bug ! ( node. span( ) ,
959
- "Implicit deref of non-borrowed pointer" )
960
- }
961
- } else {
962
- ptr
963
- } ;
964
- // for unique ptrs, we inherit mutability from the
965
- // owning reference.
966
- ( MutabilityCategory :: from_pointer_kind ( base_cmt. mutbl , ptr) ,
967
- Categorization :: Deref ( base_cmt, deref_cnt, ptr) )
968
- }
969
- deref_interior( interior) => {
970
- ( base_cmt. mutbl . inherit ( ) , Categorization :: Interior ( base_cmt, interior) )
905
+ let ptr = match base_cmt. ty . sty {
906
+ ty:: TyBox ( ..) => Unique ,
907
+ ty:: TyRawPtr ( ref mt) => UnsafePtr ( mt. mutbl ) ,
908
+ ty:: TyRef ( r, mt) => {
909
+ let bk = ty:: BorrowKind :: from_mutbl ( mt. mutbl ) ;
910
+ if implicit { Implicit ( bk, r) } else { BorrowedPtr ( bk, r) }
971
911
}
912
+ ref ty => bug ! ( "unexpected type in cat_deref_common: {:?}" , ty)
972
913
} ;
973
914
let ret = Rc :: new ( cmt_ {
974
915
id : node. id ( ) ,
975
916
span : node. span ( ) ,
976
- cat : cat,
977
- mutbl : m,
917
+ // For unique ptrs, we inherit mutability from the owning reference.
918
+ mutbl : MutabilityCategory :: from_pointer_kind ( base_cmt. mutbl , ptr) ,
919
+ cat : Categorization :: Deref ( base_cmt, deref_cnt, ptr) ,
978
920
ty : deref_ty,
979
921
note : NoteNone
980
922
} ) ;
981
923
debug ! ( "cat_deref_common ret {:?}" , ret) ;
982
- Ok ( ret)
924
+ ret
983
925
}
984
926
985
927
pub fn cat_index < N : ast_node > ( & self ,
@@ -1202,7 +1144,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1202
1144
// box p1, &p1, &mut p1. we can ignore the mutability of
1203
1145
// PatKind::Ref since that information is already contained
1204
1146
// in the type.
1205
- let subcmt = self . cat_deref ( pat, cmt, 0 , None ) ?;
1147
+ let subcmt = self . cat_deref ( pat, cmt, 0 ) ?;
1206
1148
self . cat_pattern_ ( subcmt, & subpat, op) ?;
1207
1149
}
1208
1150
0 commit comments