Skip to content

Commit 1265cbf

Browse files
authored
Auto merge of #36393 - petrochenkov:ancient, r=eddyb
Remove some obsolete code from the compiler
2 parents d1acabe + b57f109 commit 1265cbf

File tree

10 files changed

+40
-196
lines changed

10 files changed

+40
-196
lines changed

src/librustc/middle/mem_categorization.rs

+20-82
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,51 +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::TyAdt(..) => { // newtype
227-
Ok(deref_interior(InteriorField(PositionalField(0))))
228-
}
229-
230-
ty::TyArray(..) | ty::TySlice(_) => {
231-
// no deref of indexed content without supplying InteriorOffsetKind
232-
if let Some(context) = context {
233-
Ok(deref_interior(InteriorElement(context, ElementKind::VecElement)))
234-
} else {
235-
Err(())
236-
}
237-
}
238-
239-
_ => Err(()),
240-
}
241-
}
242-
243197
pub trait ast_node {
244198
fn id(&self) -> ast::NodeId;
245199
fn span(&self) -> Span;
@@ -476,7 +430,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
476430
autoderefs,
477431
cmt);
478432
for deref in 1..autoderefs + 1 {
479-
cmt = self.cat_deref(expr, cmt, deref, None)?;
433+
cmt = self.cat_deref(expr, cmt, deref)?;
480434
}
481435
return Ok(cmt);
482436
}
@@ -488,7 +442,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
488442
match expr.node {
489443
hir::ExprUnary(hir::UnDeref, ref e_base) => {
490444
let base_cmt = self.cat_expr(&e_base)?;
491-
self.cat_deref(expr, base_cmt, 0, None)
445+
self.cat_deref(expr, base_cmt, 0)
492446
}
493447

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

508462
hir::ExprIndex(ref base, _) => {
509463
let method_call = ty::MethodCall::expr(expr.id());
510-
let context = InteriorOffsetKind::Index;
511464
match self.infcx.node_method_ty(method_call) {
512465
Some(method_ty) => {
513466
// If this is an index implemented by a method call, then it
@@ -529,10 +482,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
529482
// is an rvalue. That is what we will be
530483
// dereferencing.
531484
let base_cmt = self.cat_rvalue_node(expr.id(), expr.span(), ret_ty);
532-
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))
533486
}
534487
None => {
535-
self.cat_index(expr, self.cat_expr(&base)?, context)
488+
self.cat_index(expr, self.cat_expr(&base)?, InteriorOffsetKind::Index)
536489
}
537490
}
538491
}
@@ -907,8 +860,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
907860
fn cat_deref<N:ast_node>(&self,
908861
node: &N,
909862
base_cmt: cmt<'tcx>,
910-
deref_cnt: usize,
911-
deref_context: DerefKindContext)
863+
deref_cnt: usize)
912864
-> McResult<cmt<'tcx>> {
913865
let method_call = ty::MethodCall {
914866
expr_id: node.id(),
@@ -930,12 +882,9 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
930882
let base_cmt_ty = base_cmt.ty;
931883
match base_cmt_ty.builtin_deref(true, ty::NoPreference) {
932884
Some(mt) => {
933-
let ret = self.cat_deref_common(node, base_cmt, deref_cnt,
934-
mt.ty,
935-
deref_context,
936-
/* implicit: */ false);
885+
let ret = self.cat_deref_common(node, base_cmt, deref_cnt, mt.ty, false);
937886
debug!("cat_deref ret {:?}", ret);
938-
ret
887+
Ok(ret)
939888
}
940889
None => {
941890
debug!("Explicit deref of non-derefable type: {:?}",
@@ -950,40 +899,29 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
950899
base_cmt: cmt<'tcx>,
951900
deref_cnt: usize,
952901
deref_ty: Ty<'tcx>,
953-
deref_context: DerefKindContext,
954902
implicit: bool)
955-
-> McResult<cmt<'tcx>>
903+
-> cmt<'tcx>
956904
{
957-
let (m, cat) = match deref_kind(base_cmt.ty, deref_context)? {
958-
deref_ptr(ptr) => {
959-
let ptr = if implicit {
960-
match ptr {
961-
BorrowedPtr(bk, r) => Implicit(bk, r),
962-
_ => span_bug!(node.span(),
963-
"Implicit deref of non-borrowed pointer")
964-
}
965-
} else {
966-
ptr
967-
};
968-
// for unique ptrs, we inherit mutability from the
969-
// owning reference.
970-
(MutabilityCategory::from_pointer_kind(base_cmt.mutbl, ptr),
971-
Categorization::Deref(base_cmt, deref_cnt, ptr))
972-
}
973-
deref_interior(interior) => {
974-
(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) }
975911
}
912+
ref ty => bug!("unexpected type in cat_deref_common: {:?}", ty)
976913
};
977914
let ret = Rc::new(cmt_ {
978915
id: node.id(),
979916
span: node.span(),
980-
cat: cat,
981-
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),
982920
ty: deref_ty,
983921
note: NoteNone
984922
});
985923
debug!("cat_deref_common ret {:?}", ret);
986-
Ok(ret)
924+
ret
987925
}
988926

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

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
@@ -2546,7 +2546,7 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item,
25462546
}
25472547
write!(w, "}}")?;
25482548
}
2549-
doctree::Tuple | doctree::Newtype => {
2549+
doctree::Tuple => {
25502550
write!(w, "(")?;
25512551
for (i, field) in fields.iter().enumerate() {
25522552
if i > 0 {

src/libsyntax/parse/obsolete.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ use parse::parser;
1919
/// The specific types of unsupported syntax
2020
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
2121
pub enum ObsoleteSyntax {
22-
ClosureKind,
23-
ExternCrateString,
22+
// Nothing here at the moment
2423
}
2524

2625
pub trait ParserObsoleteMethods {
@@ -36,18 +35,10 @@ pub trait ParserObsoleteMethods {
3635

3736
impl<'a> ParserObsoleteMethods for parser::Parser<'a> {
3837
/// Reports an obsolete syntax non-fatal error.
38+
#[allow(unused_variables)]
3939
fn obsolete(&mut self, sp: Span, kind: ObsoleteSyntax) {
4040
let (kind_str, desc, error) = match kind {
41-
ObsoleteSyntax::ClosureKind => (
42-
"`:`, `&mut:`, or `&:`",
43-
"rely on inference instead",
44-
true,
45-
),
46-
ObsoleteSyntax::ExternCrateString => (
47-
"\"crate-name\"",
48-
"use an identifier not in quotes instead",
49-
false, // warning for now
50-
),
41+
// Nothing here at the moment
5142
};
5243

5344
self.report(sp, kind, kind_str, desc, error);

0 commit comments

Comments
 (0)