From 4b6c4c08df7f4685daf0fa2cfe127b06216176d6 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 26 Aug 2016 19:23:42 +0300 Subject: [PATCH] Remove some ancient code providing special support for newtypes --- src/librustc/middle/mem_categorization.rs | 4 --- src/librustc_metadata/encoder.rs | 28 --------------------- src/librustc_resolve/build_reduced_graph.rs | 4 +-- src/librustc_trans/adt.rs | 2 +- src/librustdoc/clean/inline.rs | 11 ++++---- src/librustdoc/doctree.rs | 21 ++++++---------- src/librustdoc/html/render.rs | 2 +- 7 files changed, 16 insertions(+), 56 deletions(-) diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 39d5487e8beb..5594ac413e23 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -223,10 +223,6 @@ fn deref_kind(t: Ty, context: DerefKindContext) -> McResult { 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 { diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 603b7a483b90..e228bf743026 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -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(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) { @@ -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); diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index ad750ccc0129..83f03e7cfc5a 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -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)); diff --git a/src/librustc_trans/adt.rs b/src/librustc_trans/adt.rs index e8498363e45a..67e5ec2616d2 100644 --- a/src/librustc_trans/adt.rs +++ b/src/librustc_trans/adt.rs @@ -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)); } diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index f1b907e70d74..709e36989244 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -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; @@ -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), diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index cc62fcfa0aa8..c2404f4294e9 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -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 { @@ -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, } } diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 6da7423edb89..df6b3239cd86 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2537,7 +2537,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 {