Skip to content

Commit 03161e9

Browse files
committed
Remove some more dead code from mem categorization
1 parent 4b6c4c0 commit 03161e9

File tree

1 file changed

+20
-78
lines changed

1 file changed

+20
-78
lines changed

src/librustc/middle/mem_categorization.rs

+20-78
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ pub use self::ElementKind::*;
6767
pub use self::MutabilityCategory::*;
6868
pub use self::AliasableReason::*;
6969
pub use self::Note::*;
70-
pub use self::deref_kind::*;
7170

7271
use self::Aliasability::*;
7372

@@ -195,47 +194,6 @@ pub struct cmt_<'tcx> {
195194

196195
pub 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::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-
239197
pub trait ast_node {
240198
fn id(&self) -> ast::NodeId;
241199
fn span(&self) -> Span;
@@ -472,7 +430,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
472430
autoderefs,
473431
cmt);
474432
for deref in 1..autoderefs + 1 {
475-
cmt = self.cat_deref(expr, cmt, deref, None)?;
433+
cmt = self.cat_deref(expr, cmt, deref)?;
476434
}
477435
return Ok(cmt);
478436
}
@@ -484,7 +442,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
484442
match expr.node {
485443
hir::ExprUnary(hir::UnDeref, ref e_base) => {
486444
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)
488446
}
489447

490448
hir::ExprField(ref base, f_name) => {
@@ -503,7 +461,6 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
503461

504462
hir::ExprIndex(ref base, _) => {
505463
let method_call = ty::MethodCall::expr(expr.id());
506-
let context = InteriorOffsetKind::Index;
507464
match self.infcx.node_method_ty(method_call) {
508465
Some(method_ty) => {
509466
// If this is an index implemented by a method call, then it
@@ -525,10 +482,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
525482
// is an rvalue. That is what we will be
526483
// dereferencing.
527484
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))
529486
}
530487
None => {
531-
self.cat_index(expr, self.cat_expr(&base)?, context)
488+
self.cat_index(expr, self.cat_expr(&base)?, InteriorOffsetKind::Index)
532489
}
533490
}
534491
}
@@ -903,8 +860,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
903860
fn cat_deref<N:ast_node>(&self,
904861
node: &N,
905862
base_cmt: cmt<'tcx>,
906-
deref_cnt: usize,
907-
deref_context: DerefKindContext)
863+
deref_cnt: usize)
908864
-> McResult<cmt<'tcx>> {
909865
let method_call = ty::MethodCall {
910866
expr_id: node.id(),
@@ -926,12 +882,9 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
926882
let base_cmt_ty = base_cmt.ty;
927883
match base_cmt_ty.builtin_deref(true, ty::NoPreference) {
928884
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);
933886
debug!("cat_deref ret {:?}", ret);
934-
ret
887+
Ok(ret)
935888
}
936889
None => {
937890
debug!("Explicit deref of non-derefable type: {:?}",
@@ -946,40 +899,29 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
946899
base_cmt: cmt<'tcx>,
947900
deref_cnt: usize,
948901
deref_ty: Ty<'tcx>,
949-
deref_context: DerefKindContext,
950902
implicit: bool)
951-
-> McResult<cmt<'tcx>>
903+
-> cmt<'tcx>
952904
{
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) }
971911
}
912+
ref ty => bug!("unexpected type in cat_deref_common: {:?}", ty)
972913
};
973914
let ret = Rc::new(cmt_ {
974915
id: node.id(),
975916
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),
978920
ty: deref_ty,
979921
note: NoteNone
980922
});
981923
debug!("cat_deref_common ret {:?}", ret);
982-
Ok(ret)
924+
ret
983925
}
984926

985927
pub fn cat_index<N:ast_node>(&self,
@@ -1202,7 +1144,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
12021144
// box p1, &p1, &mut p1. we can ignore the mutability of
12031145
// PatKind::Ref since that information is already contained
12041146
// in the type.
1205-
let subcmt = self.cat_deref(pat, cmt, 0, None)?;
1147+
let subcmt = self.cat_deref(pat, cmt, 0)?;
12061148
self.cat_pattern_(subcmt, &subpat, op)?;
12071149
}
12081150

0 commit comments

Comments
 (0)