Skip to content

Commit 4b6c4c0

Browse files
committed
Remove some ancient code providing special support for newtypes
1 parent c87ba3f commit 4b6c4c0

File tree

7 files changed

+16
-56
lines changed

7 files changed

+16
-56
lines changed

src/librustc/middle/mem_categorization.rs

-4
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,6 @@ fn deref_kind(t: Ty, context: DerefKindContext) -> McResult<deref_kind> {
223223
Ok(deref_ptr(UnsafePtr(mt.mutbl)))
224224
}
225225

226-
ty::TyAdt(..) => { // newtype
227-
Ok(deref_interior(InteriorField(PositionalField(0))))
228-
}
229-
230226
ty::TyArray(..) | ty::TySlice(_) => {
231227
// no deref of indexed content without supplying InteriorOffsetKind
232228
if let Some(context) = context {

src/librustc_metadata/encoder.rs

-28
Original file line numberDiff line numberDiff line change
@@ -252,27 +252,6 @@ impl<'a, 'tcx, 'encoder> ItemContentBuilder<'a, 'tcx, 'encoder> {
252252
}
253253
}
254254

255-
/// Iterates through "auxiliary node IDs", which are node IDs that describe
256-
/// top-level items that are sub-items of the given item. Specifically:
257-
///
258-
/// * For newtype structs, iterates through the node ID of the constructor.
259-
fn each_auxiliary_node_id<F>(item: &hir::Item, callback: F) -> bool where
260-
F: FnOnce(NodeId) -> bool,
261-
{
262-
let mut continue_ = true;
263-
match item.node {
264-
hir::ItemStruct(ref struct_def, _) => {
265-
// If this is a newtype struct, return the constructor.
266-
if struct_def.is_tuple() {
267-
continue_ = callback(struct_def.id());
268-
}
269-
}
270-
_ => {}
271-
}
272-
273-
continue_
274-
}
275-
276255
fn encode_reexports(ecx: &EncodeContext,
277256
rbml_w: &mut Encoder,
278257
id: NodeId) {
@@ -313,13 +292,6 @@ impl<'a, 'tcx, 'encoder> ItemContentBuilder<'a, 'tcx, 'encoder> {
313292
for item_id in &md.item_ids {
314293
self.rbml_w.wr_tagged_u64(tag_mod_child,
315294
def_to_u64(ecx.tcx.map.local_def_id(item_id.id)));
316-
317-
let item = ecx.tcx.map.expect_item(item_id.id);
318-
each_auxiliary_node_id(item, |auxiliary_node_id| {
319-
self.rbml_w.wr_tagged_u64(tag_mod_child,
320-
def_to_u64(ecx.tcx.map.local_def_id(auxiliary_node_id)));
321-
true
322-
});
323295
}
324296

325297
self.encode_visibility(vis);

src/librustc_resolve/build_reduced_graph.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ impl<'b> Resolver<'b> {
261261
let def = Def::Struct(self.definitions.local_def_id(item.id));
262262
self.define(parent, name, TypeNS, (def, sp, vis));
263263

264-
// If this is a newtype or unit-like struct, define a name
265-
// in the value namespace as well
264+
// If this is a tuple or unit struct, define a name
265+
// in the value namespace as well.
266266
if !struct_def.is_struct() {
267267
let def = Def::Struct(self.definitions.local_def_id(struct_def.id()));
268268
self.define(parent, name, ValueNS, (def, sp, vis));

src/librustc_trans/adt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ fn represent_type_uncached<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
231231
}
232232

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

src/librustdoc/clean/inline.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc::middle::cstore;
1919
use rustc::hir::def::Def;
2020
use rustc::hir::def_id::DefId;
2121
use rustc::hir::print as pprust;
22-
use rustc::ty::{self, TyCtxt};
22+
use rustc::ty::{self, TyCtxt, VariantKind};
2323
use rustc::util::nodemap::FnvHashSet;
2424

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

209209
clean::Struct {
210-
struct_type: match &variant.fields[..] {
211-
&[] => doctree::Unit,
212-
&[_] if variant.kind == ty::VariantKind::Tuple => doctree::Newtype,
213-
&[..] if variant.kind == ty::VariantKind::Tuple => doctree::Tuple,
214-
_ => doctree::Plain,
210+
struct_type: match variant.kind {
211+
VariantKind::Struct => doctree::Plain,
212+
VariantKind::Tuple => doctree::Tuple,
213+
VariantKind::Unit => doctree::Unit,
215214
},
216215
generics: (t.generics, &predicates).clean(cx),
217216
fields: variant.fields.clean(cx),

src/librustdoc/doctree.rs

+7-14
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,12 @@ impl Module {
8282

8383
#[derive(Debug, Clone, RustcEncodable, RustcDecodable, Copy)]
8484
pub enum StructType {
85-
/// A normal struct
85+
/// A braced struct
8686
Plain,
8787
/// A tuple struct
8888
Tuple,
89-
/// A newtype struct (tuple struct with one element)
90-
Newtype,
9189
/// A unit struct
92-
Unit
90+
Unit,
9391
}
9492

9593
pub enum TypeBound {
@@ -262,15 +260,10 @@ pub struct Import {
262260
pub whence: Span,
263261
}
264262

265-
pub fn struct_type_from_def(sd: &hir::VariantData) -> StructType {
266-
if !sd.is_struct() {
267-
// We are in a tuple-struct
268-
match sd.fields().len() {
269-
0 => Unit,
270-
1 => Newtype,
271-
_ => Tuple
272-
}
273-
} else {
274-
Plain
263+
pub fn struct_type_from_def(vdata: &hir::VariantData) -> StructType {
264+
match *vdata {
265+
hir::VariantData::Struct(..) => Plain,
266+
hir::VariantData::Tuple(..) => Tuple,
267+
hir::VariantData::Unit(..) => Unit,
275268
}
276269
}

src/librustdoc/html/render.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2537,7 +2537,7 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item,
25372537
}
25382538
write!(w, "}}")?;
25392539
}
2540-
doctree::Tuple | doctree::Newtype => {
2540+
doctree::Tuple => {
25412541
write!(w, "(")?;
25422542
for (i, field) in fields.iter().enumerate() {
25432543
if i > 0 {

0 commit comments

Comments
 (0)