@@ -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,121 +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
- }
1063
-
1064
- /// Given a pattern P like: `[_, ..Q, _]`, where `vec_cmt` is the cmt for `P`, `slice_pat` is
1065
- /// the pattern `Q`, returns:
1066
- ///
1067
- /// * a cmt for `Q`
1068
- /// * the mutability and region of the slice `Q`
1069
- ///
1070
- /// These last two bits of info happen to be things that borrowck needs.
1071
- pub fn cat_slice_pattern ( & self ,
1072
- vec_cmt : cmt < ' tcx > ,
1073
- slice_pat : & hir:: Pat )
1074
- -> McResult < ( cmt < ' tcx > , hir:: Mutability , ty:: Region ) > {
1075
- let slice_ty = self . node_ty ( slice_pat. id ) ?;
1076
- let ( slice_mutbl, slice_r) = vec_slice_info ( slice_pat, slice_ty) ;
1077
- let context = InteriorOffsetKind :: Pattern ;
1078
- let cmt_vec = self . deref_vec ( slice_pat, vec_cmt, context) ?;
1079
- let cmt_slice = self . cat_index ( slice_pat, cmt_vec, context) ?;
1080
- return Ok ( ( cmt_slice, slice_mutbl, slice_r) ) ;
1081
-
1082
- /// In a pattern like [a, b, ..c], normally `c` has slice type, but if you have [a, b,
1083
- /// ..ref c], then the type of `ref c` will be `&&[]`, so to extract the slice details we
1084
- /// have to recurse through rptrs.
1085
- fn vec_slice_info ( pat : & hir:: Pat , slice_ty : Ty )
1086
- -> ( hir:: Mutability , ty:: Region ) {
1087
- match slice_ty. sty {
1088
- ty:: TyRef ( r, ref mt) => match mt. ty . sty {
1089
- ty:: TySlice ( _) => ( mt. mutbl , * r) ,
1090
- _ => vec_slice_info ( pat, mt. ty ) ,
1091
- } ,
1092
-
1093
- _ => {
1094
- span_bug ! ( pat. span,
1095
- "type of slice pattern is not a slice" ) ;
1096
- }
1097
- }
1098
- }
1099
1009
}
1100
1010
1101
1011
pub fn cat_imm_interior < N : ast_node > ( & self ,
@@ -1319,15 +1229,12 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1319
1229
1320
1230
PatKind :: Vec ( ref before, ref slice, ref after) => {
1321
1231
let context = InteriorOffsetKind :: Pattern ;
1322
- let vec_cmt = self . deref_vec ( pat, cmt, context) ?;
1323
- let elt_cmt = self . cat_index ( pat, vec_cmt, context) ?;
1232
+ let elt_cmt = self . cat_index ( pat, cmt, context) ?;
1324
1233
for before_pat in before {
1325
1234
self . cat_pattern_ ( elt_cmt. clone ( ) , & before_pat, op) ?;
1326
1235
}
1327
1236
if let Some ( ref slice_pat) = * slice {
1328
- let slice_ty = self . pat_ty ( & slice_pat) ?;
1329
- let slice_cmt = self . cat_rvalue_node ( pat. id ( ) , pat. span ( ) , slice_ty) ;
1330
- self . cat_pattern_ ( slice_cmt, & slice_pat, op) ?;
1237
+ self . cat_pattern_ ( elt_cmt. clone ( ) , & slice_pat, op) ?;
1331
1238
}
1332
1239
for after_pat in after {
1333
1240
self . cat_pattern_ ( elt_cmt. clone ( ) , & after_pat, op) ?;
@@ -1620,18 +1527,6 @@ impl fmt::Debug for InteriorKind {
1620
1527
}
1621
1528
}
1622
1529
1623
- fn element_kind ( t : Ty ) -> ElementKind {
1624
- match t. sty {
1625
- ty:: TyRef ( _, ty:: TypeAndMut { ty, ..} ) |
1626
- ty:: TyBox ( ty) => match ty. sty {
1627
- ty:: TySlice ( _) => VecElement ,
1628
- _ => OtherElement
1629
- } ,
1630
- ty:: TyArray ( ..) | ty:: TySlice ( _) => VecElement ,
1631
- _ => OtherElement
1632
- }
1633
- }
1634
-
1635
1530
impl fmt:: Debug for Upvar {
1636
1531
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1637
1532
write ! ( f, "{:?}/{:?}" , self . id, self . kind)
0 commit comments