@@ -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,51 +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:: TyAdt ( ..) => { // newtype
227
- Ok ( deref_interior ( InteriorField ( PositionalField ( 0 ) ) ) )
228
- }
229
-
230
- ty:: TyArray ( ..) | ty:: TySlice ( _) => {
231
- // no deref of indexed content without supplying InteriorOffsetKind
232
- if let Some ( context) = context {
233
- Ok ( deref_interior ( InteriorElement ( context, ElementKind :: VecElement ) ) )
234
- } else {
235
- Err ( ( ) )
236
- }
237
- }
238
-
239
- _ => Err ( ( ) ) ,
240
- }
241
- }
242
-
243
197
pub trait ast_node {
244
198
fn id ( & self ) -> ast:: NodeId ;
245
199
fn span ( & self ) -> Span ;
@@ -476,7 +430,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
476
430
autoderefs,
477
431
cmt) ;
478
432
for deref in 1 ..autoderefs + 1 {
479
- cmt = self . cat_deref ( expr, cmt, deref, None ) ?;
433
+ cmt = self . cat_deref ( expr, cmt, deref) ?;
480
434
}
481
435
return Ok ( cmt) ;
482
436
}
@@ -488,7 +442,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
488
442
match expr. node {
489
443
hir:: ExprUnary ( hir:: UnDeref , ref e_base) => {
490
444
let base_cmt = self . cat_expr ( & e_base) ?;
491
- self . cat_deref ( expr, base_cmt, 0 , None )
445
+ self . cat_deref ( expr, base_cmt, 0 )
492
446
}
493
447
494
448
hir:: ExprField ( ref base, f_name) => {
@@ -507,7 +461,6 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
507
461
508
462
hir:: ExprIndex ( ref base, _) => {
509
463
let method_call = ty:: MethodCall :: expr ( expr. id ( ) ) ;
510
- let context = InteriorOffsetKind :: Index ;
511
464
match self . infcx . node_method_ty ( method_call) {
512
465
Some ( method_ty) => {
513
466
// If this is an index implemented by a method call, then it
@@ -529,10 +482,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
529
482
// is an rvalue. That is what we will be
530
483
// dereferencing.
531
484
let base_cmt = self . cat_rvalue_node ( expr. id ( ) , expr. span ( ) , ret_ty) ;
532
- 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 ) )
533
486
}
534
487
None => {
535
- self . cat_index ( expr, self . cat_expr ( & base) ?, context )
488
+ self . cat_index ( expr, self . cat_expr ( & base) ?, InteriorOffsetKind :: Index )
536
489
}
537
490
}
538
491
}
@@ -907,8 +860,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
907
860
fn cat_deref < N : ast_node > ( & self ,
908
861
node : & N ,
909
862
base_cmt : cmt < ' tcx > ,
910
- deref_cnt : usize ,
911
- deref_context : DerefKindContext )
863
+ deref_cnt : usize )
912
864
-> McResult < cmt < ' tcx > > {
913
865
let method_call = ty:: MethodCall {
914
866
expr_id : node. id ( ) ,
@@ -930,12 +882,9 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
930
882
let base_cmt_ty = base_cmt. ty ;
931
883
match base_cmt_ty. builtin_deref ( true , ty:: NoPreference ) {
932
884
Some ( mt) => {
933
- let ret = self . cat_deref_common ( node, base_cmt, deref_cnt,
934
- mt. ty ,
935
- deref_context,
936
- /* implicit: */ false ) ;
885
+ let ret = self . cat_deref_common ( node, base_cmt, deref_cnt, mt. ty , false ) ;
937
886
debug ! ( "cat_deref ret {:?}" , ret) ;
938
- ret
887
+ Ok ( ret)
939
888
}
940
889
None => {
941
890
debug ! ( "Explicit deref of non-derefable type: {:?}" ,
@@ -950,40 +899,29 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
950
899
base_cmt : cmt < ' tcx > ,
951
900
deref_cnt : usize ,
952
901
deref_ty : Ty < ' tcx > ,
953
- deref_context : DerefKindContext ,
954
902
implicit : bool )
955
- -> McResult < cmt < ' tcx > >
903
+ -> cmt < ' tcx >
956
904
{
957
- let ( m, cat) = match deref_kind ( base_cmt. ty , deref_context) ? {
958
- deref_ptr( ptr) => {
959
- let ptr = if implicit {
960
- match ptr {
961
- BorrowedPtr ( bk, r) => Implicit ( bk, r) ,
962
- _ => span_bug ! ( node. span( ) ,
963
- "Implicit deref of non-borrowed pointer" )
964
- }
965
- } else {
966
- ptr
967
- } ;
968
- // for unique ptrs, we inherit mutability from the
969
- // owning reference.
970
- ( MutabilityCategory :: from_pointer_kind ( base_cmt. mutbl , ptr) ,
971
- Categorization :: Deref ( base_cmt, deref_cnt, ptr) )
972
- }
973
- deref_interior( interior) => {
974
- ( 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) }
975
911
}
912
+ ref ty => bug ! ( "unexpected type in cat_deref_common: {:?}" , ty)
976
913
} ;
977
914
let ret = Rc :: new ( cmt_ {
978
915
id : node. id ( ) ,
979
916
span : node. span ( ) ,
980
- cat : cat,
981
- 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) ,
982
920
ty : deref_ty,
983
921
note : NoteNone
984
922
} ) ;
985
923
debug ! ( "cat_deref_common ret {:?}" , ret) ;
986
- Ok ( ret)
924
+ ret
987
925
}
988
926
989
927
pub fn cat_index < N : ast_node > ( & self ,
@@ -1206,7 +1144,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1206
1144
// box p1, &p1, &mut p1. we can ignore the mutability of
1207
1145
// PatKind::Ref since that information is already contained
1208
1146
// in the type.
1209
- let subcmt = self . cat_deref ( pat, cmt, 0 , None ) ?;
1147
+ let subcmt = self . cat_deref ( pat, cmt, 0 ) ?;
1210
1148
self . cat_pattern_ ( subcmt, & subpat, op) ?;
1211
1149
}
1212
1150
0 commit comments