Skip to content

Commit

Permalink
Auto merge of #36393 - petrochenkov:ancient, r=eddyb
Browse files Browse the repository at this point in the history
Remove some obsolete code from the compiler
  • Loading branch information
bors committed Sep 15, 2016
2 parents d1acabe + b57f109 commit 1265cbf
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 196 deletions.
102 changes: 20 additions & 82 deletions src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ pub use self::ElementKind::*;
pub use self::MutabilityCategory::*;
pub use self::AliasableReason::*;
pub use self::Note::*;
pub use self::deref_kind::*;

use self::Aliasability::*;

Expand Down Expand Up @@ -195,51 +194,6 @@ pub struct cmt_<'tcx> {

pub type cmt<'tcx> = Rc<cmt_<'tcx>>;

// We pun on *T to mean both actual deref of a ptr as well
// as accessing of components:
#[derive(Copy, Clone)]
pub enum deref_kind<'tcx> {
deref_ptr(PointerKind<'tcx>),
deref_interior(InteriorKind),
}

type DerefKindContext = Option<InteriorOffsetKind>;

// Categorizes a derefable type. Note that we include vectors and strings as
// derefable (we model an index as the combination of a deref and then a
// pointer adjustment).
fn deref_kind(t: Ty, context: DerefKindContext) -> McResult<deref_kind> {
match t.sty {
ty::TyBox(_) => {
Ok(deref_ptr(Unique))
}

ty::TyRef(r, mt) => {
let kind = ty::BorrowKind::from_mutbl(mt.mutbl);
Ok(deref_ptr(BorrowedPtr(kind, r)))
}

ty::TyRawPtr(ref mt) => {
Ok(deref_ptr(UnsafePtr(mt.mutbl)))
}

ty::TyAdt(..) => { // newtype
Ok(deref_interior(InteriorField(PositionalField(0))))
}

ty::TyArray(..) | ty::TySlice(_) => {
// no deref of indexed content without supplying InteriorOffsetKind
if let Some(context) = context {
Ok(deref_interior(InteriorElement(context, ElementKind::VecElement)))
} else {
Err(())
}
}

_ => Err(()),
}
}

pub trait ast_node {
fn id(&self) -> ast::NodeId;
fn span(&self) -> Span;
Expand Down Expand Up @@ -476,7 +430,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
autoderefs,
cmt);
for deref in 1..autoderefs + 1 {
cmt = self.cat_deref(expr, cmt, deref, None)?;
cmt = self.cat_deref(expr, cmt, deref)?;
}
return Ok(cmt);
}
Expand All @@ -488,7 +442,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
match expr.node {
hir::ExprUnary(hir::UnDeref, ref e_base) => {
let base_cmt = self.cat_expr(&e_base)?;
self.cat_deref(expr, base_cmt, 0, None)
self.cat_deref(expr, base_cmt, 0)
}

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

hir::ExprIndex(ref base, _) => {
let method_call = ty::MethodCall::expr(expr.id());
let context = InteriorOffsetKind::Index;
match self.infcx.node_method_ty(method_call) {
Some(method_ty) => {
// If this is an index implemented by a method call, then it
Expand All @@ -529,10 +482,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
// is an rvalue. That is what we will be
// dereferencing.
let base_cmt = self.cat_rvalue_node(expr.id(), expr.span(), ret_ty);
self.cat_deref_common(expr, base_cmt, 1, elem_ty, Some(context), true)
Ok(self.cat_deref_common(expr, base_cmt, 1, elem_ty, true))
}
None => {
self.cat_index(expr, self.cat_expr(&base)?, context)
self.cat_index(expr, self.cat_expr(&base)?, InteriorOffsetKind::Index)
}
}
}
Expand Down Expand Up @@ -907,8 +860,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
fn cat_deref<N:ast_node>(&self,
node: &N,
base_cmt: cmt<'tcx>,
deref_cnt: usize,
deref_context: DerefKindContext)
deref_cnt: usize)
-> McResult<cmt<'tcx>> {
let method_call = ty::MethodCall {
expr_id: node.id(),
Expand All @@ -930,12 +882,9 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
let base_cmt_ty = base_cmt.ty;
match base_cmt_ty.builtin_deref(true, ty::NoPreference) {
Some(mt) => {
let ret = self.cat_deref_common(node, base_cmt, deref_cnt,
mt.ty,
deref_context,
/* implicit: */ false);
let ret = self.cat_deref_common(node, base_cmt, deref_cnt, mt.ty, false);
debug!("cat_deref ret {:?}", ret);
ret
Ok(ret)
}
None => {
debug!("Explicit deref of non-derefable type: {:?}",
Expand All @@ -950,40 +899,29 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
base_cmt: cmt<'tcx>,
deref_cnt: usize,
deref_ty: Ty<'tcx>,
deref_context: DerefKindContext,
implicit: bool)
-> McResult<cmt<'tcx>>
-> cmt<'tcx>
{
let (m, cat) = match deref_kind(base_cmt.ty, deref_context)? {
deref_ptr(ptr) => {
let ptr = if implicit {
match ptr {
BorrowedPtr(bk, r) => Implicit(bk, r),
_ => span_bug!(node.span(),
"Implicit deref of non-borrowed pointer")
}
} else {
ptr
};
// for unique ptrs, we inherit mutability from the
// owning reference.
(MutabilityCategory::from_pointer_kind(base_cmt.mutbl, ptr),
Categorization::Deref(base_cmt, deref_cnt, ptr))
}
deref_interior(interior) => {
(base_cmt.mutbl.inherit(), Categorization::Interior(base_cmt, interior))
let ptr = match base_cmt.ty.sty {
ty::TyBox(..) => Unique,
ty::TyRawPtr(ref mt) => UnsafePtr(mt.mutbl),
ty::TyRef(r, mt) => {
let bk = ty::BorrowKind::from_mutbl(mt.mutbl);
if implicit { Implicit(bk, r) } else { BorrowedPtr(bk, r) }
}
ref ty => bug!("unexpected type in cat_deref_common: {:?}", ty)
};
let ret = Rc::new(cmt_ {
id: node.id(),
span: node.span(),
cat: cat,
mutbl: m,
// For unique ptrs, we inherit mutability from the owning reference.
mutbl: MutabilityCategory::from_pointer_kind(base_cmt.mutbl, ptr),
cat: Categorization::Deref(base_cmt, deref_cnt, ptr),
ty: deref_ty,
note: NoteNone
});
debug!("cat_deref_common ret {:?}", ret);
Ok(ret)
ret
}

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

Expand Down
28 changes: 0 additions & 28 deletions src/librustc_metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,27 +252,6 @@ impl<'a, 'tcx, 'encoder> ItemContentBuilder<'a, 'tcx, 'encoder> {
}
}

/// Iterates through "auxiliary node IDs", which are node IDs that describe
/// top-level items that are sub-items of the given item. Specifically:
///
/// * For newtype structs, iterates through the node ID of the constructor.
fn each_auxiliary_node_id<F>(item: &hir::Item, callback: F) -> bool where
F: FnOnce(NodeId) -> bool,
{
let mut continue_ = true;
match item.node {
hir::ItemStruct(ref struct_def, _) => {
// If this is a newtype struct, return the constructor.
if struct_def.is_tuple() {
continue_ = callback(struct_def.id());
}
}
_ => {}
}

continue_
}

fn encode_reexports(ecx: &EncodeContext,
rbml_w: &mut Encoder,
id: NodeId) {
Expand Down Expand Up @@ -313,13 +292,6 @@ impl<'a, 'tcx, 'encoder> ItemContentBuilder<'a, 'tcx, 'encoder> {
for item_id in &md.item_ids {
self.rbml_w.wr_tagged_u64(tag_mod_child,
def_to_u64(ecx.tcx.map.local_def_id(item_id.id)));

let item = ecx.tcx.map.expect_item(item_id.id);
each_auxiliary_node_id(item, |auxiliary_node_id| {
self.rbml_w.wr_tagged_u64(tag_mod_child,
def_to_u64(ecx.tcx.map.local_def_id(auxiliary_node_id)));
true
});
}

self.encode_visibility(vis);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ impl<'b> Resolver<'b> {
let def = Def::Struct(self.definitions.local_def_id(item.id));
self.define(parent, name, TypeNS, (def, sp, vis));

// If this is a newtype or unit-like struct, define a name
// in the value namespace as well
// If this is a tuple or unit struct, define a name
// in the value namespace as well.
if !struct_def.is_struct() {
let def = Def::Struct(self.definitions.local_def_id(struct_def.id()));
self.define(parent, name, ValueNS, (def, sp, vis));
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/adt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ fn represent_type_uncached<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
}

if cases.len() == 1 && hint == attr::ReprAny {
// Equivalent to a struct/tuple/newtype.
// Equivalent to a struct or tuple.
return Univariant(mk_struct(cx, &cases[0].tys, false, t));
}

Expand Down
11 changes: 5 additions & 6 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use rustc::middle::cstore;
use rustc::hir::def::Def;
use rustc::hir::def_id::DefId;
use rustc::hir::print as pprust;
use rustc::ty::{self, TyCtxt};
use rustc::ty::{self, TyCtxt, VariantKind};
use rustc::util::nodemap::FnvHashSet;

use rustc_const_eval::lookup_const_by_id;
Expand Down Expand Up @@ -207,11 +207,10 @@ fn build_struct<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
let variant = tcx.lookup_adt_def(did).struct_variant();

clean::Struct {
struct_type: match &variant.fields[..] {
&[] => doctree::Unit,
&[_] if variant.kind == ty::VariantKind::Tuple => doctree::Newtype,
&[..] if variant.kind == ty::VariantKind::Tuple => doctree::Tuple,
_ => doctree::Plain,
struct_type: match variant.kind {
VariantKind::Struct => doctree::Plain,
VariantKind::Tuple => doctree::Tuple,
VariantKind::Unit => doctree::Unit,
},
generics: (t.generics, &predicates).clean(cx),
fields: variant.fields.clean(cx),
Expand Down
21 changes: 7 additions & 14 deletions src/librustdoc/doctree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,12 @@ impl Module {

#[derive(Debug, Clone, RustcEncodable, RustcDecodable, Copy)]
pub enum StructType {
/// A normal struct
/// A braced struct
Plain,
/// A tuple struct
Tuple,
/// A newtype struct (tuple struct with one element)
Newtype,
/// A unit struct
Unit
Unit,
}

pub enum TypeBound {
Expand Down Expand Up @@ -262,15 +260,10 @@ pub struct Import {
pub whence: Span,
}

pub fn struct_type_from_def(sd: &hir::VariantData) -> StructType {
if !sd.is_struct() {
// We are in a tuple-struct
match sd.fields().len() {
0 => Unit,
1 => Newtype,
_ => Tuple
}
} else {
Plain
pub fn struct_type_from_def(vdata: &hir::VariantData) -> StructType {
match *vdata {
hir::VariantData::Struct(..) => Plain,
hir::VariantData::Tuple(..) => Tuple,
hir::VariantData::Unit(..) => Unit,
}
}
2 changes: 1 addition & 1 deletion src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2546,7 +2546,7 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item,
}
write!(w, "}}")?;
}
doctree::Tuple | doctree::Newtype => {
doctree::Tuple => {
write!(w, "(")?;
for (i, field) in fields.iter().enumerate() {
if i > 0 {
Expand Down
15 changes: 3 additions & 12 deletions src/libsyntax/parse/obsolete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ use parse::parser;
/// The specific types of unsupported syntax
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub enum ObsoleteSyntax {
ClosureKind,
ExternCrateString,
// Nothing here at the moment
}

pub trait ParserObsoleteMethods {
Expand All @@ -36,18 +35,10 @@ pub trait ParserObsoleteMethods {

impl<'a> ParserObsoleteMethods for parser::Parser<'a> {
/// Reports an obsolete syntax non-fatal error.
#[allow(unused_variables)]
fn obsolete(&mut self, sp: Span, kind: ObsoleteSyntax) {
let (kind_str, desc, error) = match kind {
ObsoleteSyntax::ClosureKind => (
"`:`, `&mut:`, or `&:`",
"rely on inference instead",
true,
),
ObsoleteSyntax::ExternCrateString => (
"\"crate-name\"",
"use an identifier not in quotes instead",
false, // warning for now
),
// Nothing here at the moment
};

self.report(sp, kind, kind_str, desc, error);
Expand Down
Loading

0 comments on commit 1265cbf

Please sign in to comment.