Auto merge of #36393 - petrochenkov:ancient, r=eddyb
Remove some obsolete code from the compiler
This commit is contained in:
commit
1265cbf4e0
10 changed files with 40 additions and 196 deletions
|
@ -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::*;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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) => {
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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(),
|
||||
|
@ -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: {:?}",
|
||||
|
@ -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,
|
||||
|
@ -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)?;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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);
|
||||
|
|
|
@ -47,7 +47,7 @@ use parse;
|
|||
use parse::classify;
|
||||
use parse::common::SeqSep;
|
||||
use parse::lexer::{Reader, TokenAndSpan};
|
||||
use parse::obsolete::{ParserObsoleteMethods, ObsoleteSyntax};
|
||||
use parse::obsolete::ObsoleteSyntax;
|
||||
use parse::token::{self, intern, MatchNt, SubstNt, SpecialVarNt, InternedString};
|
||||
use parse::token::{keywords, SpecialMacroVar};
|
||||
use parse::{new_sub_parser_from_file, ParseSess};
|
||||
|
@ -1165,36 +1165,6 @@ impl<'a> Parser<'a> {
|
|||
})))
|
||||
}
|
||||
|
||||
/// Parses an obsolete closure kind (`&:`, `&mut:`, or `:`).
|
||||
pub fn parse_obsolete_closure_kind(&mut self) -> PResult<'a, ()> {
|
||||
let lo = self.span.lo;
|
||||
if
|
||||
self.check(&token::BinOp(token::And)) &&
|
||||
self.look_ahead(1, |t| t.is_keyword(keywords::Mut)) &&
|
||||
self.look_ahead(2, |t| *t == token::Colon)
|
||||
{
|
||||
self.bump();
|
||||
self.bump();
|
||||
self.bump();
|
||||
} else if
|
||||
self.token == token::BinOp(token::And) &&
|
||||
self.look_ahead(1, |t| *t == token::Colon)
|
||||
{
|
||||
self.bump();
|
||||
self.bump();
|
||||
} else if
|
||||
self.eat(&token::Colon)
|
||||
{
|
||||
/* nothing */
|
||||
} else {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let span = mk_sp(lo, self.span.hi);
|
||||
self.obsolete(span, ObsoleteSyntax::ClosureKind);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn parse_unsafety(&mut self) -> PResult<'a, Unsafety> {
|
||||
if self.eat_keyword(keywords::Unsafe) {
|
||||
return Ok(Unsafety::Unsafe);
|
||||
|
@ -4728,7 +4698,6 @@ impl<'a> Parser<'a> {
|
|||
Vec::new()
|
||||
} else {
|
||||
self.expect(&token::BinOp(token::Or))?;
|
||||
self.parse_obsolete_closure_kind()?;
|
||||
let args = self.parse_seq_to_before_end(
|
||||
&token::BinOp(token::Or),
|
||||
SeqSep::trailing_allowed(token::Comma),
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// Test that we generate obsolete syntax errors around usages of closure kinds: `|:|`, `|&:|` and
|
||||
// `|&mut:|`.
|
||||
|
||||
fn main() {
|
||||
let a = |:| {}; //~ ERROR obsolete syntax: `:`, `&mut:`, or `&:`
|
||||
let a = |&:| {}; //~ ERROR obsolete syntax: `:`, `&mut:`, or `&:`
|
||||
let a = |&mut:| {}; //~ ERROR obsolete syntax: `:`, `&mut:`, or `&:`
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue