1
Fork 0

Remove some ancient code providing special support for newtypes

This commit is contained in:
Vadim Petrochenkov 2016-08-26 19:23:42 +03:00
parent c87ba3f122
commit 4b6c4c08df
7 changed files with 16 additions and 56 deletions

View file

@ -223,10 +223,6 @@ fn deref_kind(t: Ty, context: DerefKindContext) -> McResult<deref_kind> {
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 {

View file

@ -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) {
@ -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);

View file

@ -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));

View file

@ -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));
}

View file

@ -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),

View file

@ -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,
}
}

View file

@ -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 {