@@ -67,7 +67,6 @@ pub use self::ElementKind::*;
6767pub use self :: MutabilityCategory :: * ;
6868pub use self :: AliasableReason :: * ;
6969pub use self :: Note :: * ;
70- pub use self :: deref_kind:: * ;
7170
7271use self :: Aliasability :: * ;
7372
@@ -195,51 +194,6 @@ pub struct cmt_<'tcx> {
195194
196195pub type cmt < ' tcx > = Rc < cmt_ < ' tcx > > ;
197196
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-
243197pub trait ast_node {
244198 fn id ( & self ) -> ast:: NodeId ;
245199 fn span ( & self ) -> Span ;
@@ -476,7 +430,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
476430 autoderefs,
477431 cmt) ;
478432 for deref in 1 ..autoderefs + 1 {
479- cmt = self . cat_deref ( expr, cmt, deref, None ) ?;
433+ cmt = self . cat_deref ( expr, cmt, deref) ?;
480434 }
481435 return Ok ( cmt) ;
482436 }
@@ -488,7 +442,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
488442 match expr. node {
489443 hir:: ExprUnary ( hir:: UnDeref , ref e_base) => {
490444 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 )
492446 }
493447
494448 hir:: ExprField ( ref base, f_name) => {
@@ -507,7 +461,6 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
507461
508462 hir:: ExprIndex ( ref base, _) => {
509463 let method_call = ty:: MethodCall :: expr ( expr. id ( ) ) ;
510- let context = InteriorOffsetKind :: Index ;
511464 match self . infcx . node_method_ty ( method_call) {
512465 Some ( method_ty) => {
513466 // If this is an index implemented by a method call, then it
@@ -529,10 +482,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
529482 // is an rvalue. That is what we will be
530483 // dereferencing.
531484 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 ) )
533486 }
534487 None => {
535- self . cat_index ( expr, self . cat_expr ( & base) ?, context )
488+ self . cat_index ( expr, self . cat_expr ( & base) ?, InteriorOffsetKind :: Index )
536489 }
537490 }
538491 }
@@ -907,8 +860,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
907860 fn cat_deref < N : ast_node > ( & self ,
908861 node : & N ,
909862 base_cmt : cmt < ' tcx > ,
910- deref_cnt : usize ,
911- deref_context : DerefKindContext )
863+ deref_cnt : usize )
912864 -> McResult < cmt < ' tcx > > {
913865 let method_call = ty:: MethodCall {
914866 expr_id : node. id ( ) ,
@@ -930,12 +882,9 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
930882 let base_cmt_ty = base_cmt. ty ;
931883 match base_cmt_ty. builtin_deref ( true , ty:: NoPreference ) {
932884 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 ) ;
937886 debug ! ( "cat_deref ret {:?}" , ret) ;
938- ret
887+ Ok ( ret)
939888 }
940889 None => {
941890 debug ! ( "Explicit deref of non-derefable type: {:?}" ,
@@ -950,40 +899,29 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
950899 base_cmt : cmt < ' tcx > ,
951900 deref_cnt : usize ,
952901 deref_ty : Ty < ' tcx > ,
953- deref_context : DerefKindContext ,
954902 implicit : bool )
955- -> McResult < cmt < ' tcx > >
903+ -> cmt < ' tcx >
956904 {
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) }
975911 }
912+ ref ty => bug ! ( "unexpected type in cat_deref_common: {:?}" , ty)
976913 } ;
977914 let ret = Rc :: new ( cmt_ {
978915 id : node. id ( ) ,
979916 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) ,
982920 ty : deref_ty,
983921 note : NoteNone
984922 } ) ;
985923 debug ! ( "cat_deref_common ret {:?}" , ret) ;
986- Ok ( ret)
924+ ret
987925 }
988926
989927 pub fn cat_index < N : ast_node > ( & self ,
@@ -1206,7 +1144,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
12061144 // box p1, &p1, &mut p1. we can ignore the mutability of
12071145 // PatKind::Ref since that information is already contained
12081146 // in the type.
1209- let subcmt = self . cat_deref ( pat, cmt, 0 , None ) ?;
1147+ let subcmt = self . cat_deref ( pat, cmt, 0 ) ?;
12101148 self . cat_pattern_ ( subcmt, & subpat, op) ?;
12111149 }
12121150
0 commit comments