@@ -228,10 +228,10 @@ fn deref_kind(t: Ty, context: DerefKindContext) -> McResult<deref_kind> {
228
228
Ok ( deref_interior ( InteriorField ( PositionalField ( 0 ) ) ) )
229
229
}
230
230
231
- ty:: TyArray ( _, _) | ty:: TySlice ( _) | ty :: TyStr => {
231
+ ty:: TyArray ( _, _) | ty:: TySlice ( _) => {
232
232
// no deref of indexed content without supplying InteriorOffsetKind
233
233
if let Some ( context) = context {
234
- Ok ( deref_interior ( InteriorElement ( context, element_kind ( t ) ) ) )
234
+ Ok ( deref_interior ( InteriorElement ( context, ElementKind :: VecElement ) ) )
235
235
} else {
236
236
Err ( ( ) )
237
237
}
@@ -981,84 +981,31 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
981
981
let method_call = ty:: MethodCall :: expr ( elt. id ( ) ) ;
982
982
let method_ty = self . infcx . node_method_ty ( method_call) ;
983
983
984
- let element_ty = match method_ty {
984
+ let ( element_ty, element_kind ) = match method_ty {
985
985
Some ( method_ty) => {
986
986
let ref_ty = self . overloaded_method_return_ty ( method_ty) ;
987
987
base_cmt = self . cat_rvalue_node ( elt. id ( ) , elt. span ( ) , ref_ty) ;
988
988
989
989
// FIXME(#20649) -- why are we using the `self_ty` as the element type...?
990
990
let self_ty = method_ty. fn_sig ( ) . input ( 0 ) ;
991
- self . tcx ( ) . no_late_bound_regions ( & self_ty) . unwrap ( )
991
+ ( self . tcx ( ) . no_late_bound_regions ( & self_ty) . unwrap ( ) ,
992
+ ElementKind :: OtherElement )
992
993
}
993
994
None => {
994
995
match base_cmt. ty . builtin_index ( ) {
995
- Some ( ty) => ty ,
996
+ Some ( ty) => ( ty , ElementKind :: VecElement ) ,
996
997
None => {
997
998
return Err ( ( ) ) ;
998
999
}
999
1000
}
1000
1001
}
1001
1002
} ;
1002
1003
1003
- let m = base_cmt . mutbl . inherit ( ) ;
1004
- let ret = interior ( elt , base_cmt . clone ( ) , base_cmt . ty ,
1005
- m , context , element_ty) ;
1004
+ let interior_elem = InteriorElement ( context , element_kind ) ;
1005
+ let ret =
1006
+ self . cat_imm_interior ( elt , base_cmt . clone ( ) , element_ty, interior_elem ) ;
1006
1007
debug ! ( "cat_index ret {:?}" , ret) ;
1007
1008
return Ok ( ret) ;
1008
-
1009
- fn interior < ' tcx , N : ast_node > ( elt : & N ,
1010
- of_cmt : cmt < ' tcx > ,
1011
- vec_ty : Ty < ' tcx > ,
1012
- mutbl : MutabilityCategory ,
1013
- context : InteriorOffsetKind ,
1014
- element_ty : Ty < ' tcx > ) -> cmt < ' tcx >
1015
- {
1016
- let interior_elem = InteriorElement ( context, element_kind ( vec_ty) ) ;
1017
- Rc :: new ( cmt_ {
1018
- id : elt. id ( ) ,
1019
- span : elt. span ( ) ,
1020
- cat : Categorization :: Interior ( of_cmt, interior_elem) ,
1021
- mutbl : mutbl,
1022
- ty : element_ty,
1023
- note : NoteNone
1024
- } )
1025
- }
1026
- }
1027
-
1028
- // Takes either a vec or a reference to a vec and returns the cmt for the
1029
- // underlying vec.
1030
- fn deref_vec < N : ast_node > ( & self ,
1031
- elt : & N ,
1032
- base_cmt : cmt < ' tcx > ,
1033
- context : InteriorOffsetKind )
1034
- -> McResult < cmt < ' tcx > >
1035
- {
1036
- let ret = match deref_kind ( base_cmt. ty , Some ( context) ) ? {
1037
- deref_ptr( ptr) => {
1038
- // for unique ptrs, we inherit mutability from the
1039
- // owning reference.
1040
- let m = MutabilityCategory :: from_pointer_kind ( base_cmt. mutbl , ptr) ;
1041
-
1042
- // the deref is explicit in the resulting cmt
1043
- Rc :: new ( cmt_ {
1044
- id : elt. id ( ) ,
1045
- span : elt. span ( ) ,
1046
- cat : Categorization :: Deref ( base_cmt. clone ( ) , 0 , ptr) ,
1047
- mutbl : m,
1048
- ty : match base_cmt. ty . builtin_deref ( false , ty:: NoPreference ) {
1049
- Some ( mt) => mt. ty ,
1050
- None => bug ! ( "Found non-derefable type" )
1051
- } ,
1052
- note : NoteNone
1053
- } )
1054
- }
1055
-
1056
- deref_interior( _) => {
1057
- base_cmt
1058
- }
1059
- } ;
1060
- debug ! ( "deref_vec ret {:?}" , ret) ;
1061
- Ok ( ret)
1062
1009
}
1063
1010
1064
1011
pub fn cat_imm_interior < N : ast_node > ( & self ,
@@ -1282,8 +1229,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1282
1229
1283
1230
PatKind :: Vec ( ref before, ref slice, ref after) => {
1284
1231
let context = InteriorOffsetKind :: Pattern ;
1285
- let vec_cmt = self . deref_vec ( pat, cmt, context) ?;
1286
- let elt_cmt = self . cat_index ( pat, vec_cmt, context) ?;
1232
+ let elt_cmt = self . cat_index ( pat, cmt, context) ?;
1287
1233
for before_pat in before {
1288
1234
self . cat_pattern_ ( elt_cmt. clone ( ) , & before_pat, op) ?;
1289
1235
}
@@ -1581,18 +1527,6 @@ impl fmt::Debug for InteriorKind {
1581
1527
}
1582
1528
}
1583
1529
1584
- fn element_kind ( t : Ty ) -> ElementKind {
1585
- match t. sty {
1586
- ty:: TyRef ( _, ty:: TypeAndMut { ty, ..} ) |
1587
- ty:: TyBox ( ty) => match ty. sty {
1588
- ty:: TySlice ( _) => VecElement ,
1589
- _ => OtherElement
1590
- } ,
1591
- ty:: TyArray ( ..) | ty:: TySlice ( _) => VecElement ,
1592
- _ => OtherElement
1593
- }
1594
- }
1595
-
1596
1530
impl fmt:: Debug for Upvar {
1597
1531
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1598
1532
write ! ( f, "{:?}/{:?}" , self . id, self . kind)
0 commit comments