Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libsyntax: miscellaneous cleanup #33943

Merged
merged 5 commits into from
Jun 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc/hir/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl<'a> CheckAttrVisitor<'a> {
}
}

impl<'a, 'v> Visitor<'v> for CheckAttrVisitor<'a> {
impl<'a> Visitor for CheckAttrVisitor<'a> {
fn visit_item(&mut self, item: &ast::Item) {
let target = Target::from_item(item);
for attr in &item.attrs {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ impl<'a> LoweringContext<'a> {
lctx: &'lcx mut LoweringContext<'interner>,
}

impl<'lcx, 'interner> Visitor<'lcx> for ItemLowerer<'lcx, 'interner> {
fn visit_item(&mut self, item: &'lcx Item) {
impl<'lcx, 'interner> Visitor for ItemLowerer<'lcx, 'interner> {
fn visit_item(&mut self, item: &Item) {
self.items.insert(item.id, self.lctx.lower_item(item));
visit::walk_item(self, item);
}
Expand Down
24 changes: 12 additions & 12 deletions src/librustc/hir/map/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl<'ast> DefCollector<'ast> {
self.parent_def = parent;
}

fn visit_ast_const_integer(&mut self, expr: &'ast Expr) {
fn visit_ast_const_integer(&mut self, expr: &Expr) {
// Find the node which will be used after lowering.
if let ExprKind::Paren(ref inner) = expr.node {
return self.visit_ast_const_integer(inner);
Expand All @@ -124,8 +124,8 @@ impl<'ast> DefCollector<'ast> {
}
}

impl<'ast> visit::Visitor<'ast> for DefCollector<'ast> {
fn visit_item(&mut self, i: &'ast Item) {
impl<'ast> visit::Visitor for DefCollector<'ast> {
fn visit_item(&mut self, i: &Item) {
debug!("visit_item: {:?}", i);

// Pick the def data. This need not be unique, but the more
Expand Down Expand Up @@ -183,23 +183,23 @@ impl<'ast> visit::Visitor<'ast> for DefCollector<'ast> {
});
}

fn visit_foreign_item(&mut self, foreign_item: &'ast ForeignItem) {
fn visit_foreign_item(&mut self, foreign_item: &ForeignItem) {
let def = self.create_def(foreign_item.id, DefPathData::ValueNs(foreign_item.ident.name));

self.with_parent(def, |this| {
visit::walk_foreign_item(this, foreign_item);
});
}

fn visit_generics(&mut self, generics: &'ast Generics) {
fn visit_generics(&mut self, generics: &Generics) {
for ty_param in generics.ty_params.iter() {
self.create_def(ty_param.id, DefPathData::TypeParam(ty_param.ident.name));
}

visit::walk_generics(self, generics);
}

fn visit_trait_item(&mut self, ti: &'ast TraitItem) {
fn visit_trait_item(&mut self, ti: &TraitItem) {
let def_data = match ti.node {
TraitItemKind::Method(..) | TraitItemKind::Const(..) =>
DefPathData::ValueNs(ti.ident.name),
Expand All @@ -216,7 +216,7 @@ impl<'ast> visit::Visitor<'ast> for DefCollector<'ast> {
});
}

fn visit_impl_item(&mut self, ii: &'ast ImplItem) {
fn visit_impl_item(&mut self, ii: &ImplItem) {
let def_data = match ii.node {
ImplItemKind::Method(..) | ImplItemKind::Const(..) =>
DefPathData::ValueNs(ii.ident.name),
Expand All @@ -234,7 +234,7 @@ impl<'ast> visit::Visitor<'ast> for DefCollector<'ast> {
});
}

fn visit_pat(&mut self, pat: &'ast Pat) {
fn visit_pat(&mut self, pat: &Pat) {
let parent_def = self.parent_def;

if let PatKind::Ident(_, id, _) = pat.node {
Expand All @@ -246,7 +246,7 @@ impl<'ast> visit::Visitor<'ast> for DefCollector<'ast> {
self.parent_def = parent_def;
}

fn visit_expr(&mut self, expr: &'ast Expr) {
fn visit_expr(&mut self, expr: &Expr) {
let parent_def = self.parent_def;

if let ExprKind::Repeat(_, ref count) = expr.node {
Expand All @@ -262,18 +262,18 @@ impl<'ast> visit::Visitor<'ast> for DefCollector<'ast> {
self.parent_def = parent_def;
}

fn visit_ty(&mut self, ty: &'ast Ty) {
fn visit_ty(&mut self, ty: &Ty) {
if let TyKind::FixedLengthVec(_, ref length) = ty.node {
self.visit_ast_const_integer(length);
}
visit::walk_ty(self, ty);
}

fn visit_lifetime_def(&mut self, def: &'ast LifetimeDef) {
fn visit_lifetime_def(&mut self, def: &LifetimeDef) {
self.create_def(def.lifetime.id, DefPathData::LifetimeDef(def.lifetime.name));
}

fn visit_macro_def(&mut self, macro_def: &'ast MacroDef) {
fn visit_macro_def(&mut self, macro_def: &MacroDef) {
self.create_def(macro_def.id, DefPathData::MacroDef(macro_def.ident.name));
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> {
}
}

impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> {
impl<'a> ast_visit::Visitor for EarlyContext<'a> {
fn visit_item(&mut self, it: &ast::Item) {
self.with_lint_attrs(&it.attrs, |cx| {
run_lints!(cx, check_item, early_passes, it);
Expand Down Expand Up @@ -939,8 +939,8 @@ impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> {
ast_visit::walk_stmt(self, s);
}

fn visit_fn(&mut self, fk: ast_visit::FnKind<'v>, decl: &'v ast::FnDecl,
body: &'v ast::Block, span: Span, id: ast::NodeId) {
fn visit_fn(&mut self, fk: ast_visit::FnKind, decl: &ast::FnDecl,
body: &ast::Block, span: Span, id: ast::NodeId) {
run_lints!(self, check_fn, early_passes, fk, decl, body, span, id);
ast_visit::walk_fn(self, fk, decl, body, span);
run_lints!(self, check_fn_post, early_passes, fk, decl, body, span, id);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ pub struct CrateReader<'a> {
local_crate_name: String,
}

impl<'a, 'ast> visit::Visitor<'ast> for LocalCrateReader<'a> {
fn visit_item(&mut self, a: &'ast ast::Item) {
impl<'a> visit::Visitor for LocalCrateReader<'a> {
fn visit_item(&mut self, a: &ast::Item) {
self.process_item(a);
visit::walk_item(self, a);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_passes/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl<'a> AstValidator<'a> {
}
}

impl<'a, 'v> Visitor<'v> for AstValidator<'a> {
impl<'a> Visitor for AstValidator<'a> {
fn visit_lifetime(&mut self, lt: &Lifetime) {
if lt.name.as_str() == "'_" {
self.session.add_lint(
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_passes/no_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct CheckNoAsm<'a> {
sess: &'a Session,
}

impl<'a, 'v> Visitor<'v> for CheckNoAsm<'a> {
impl<'a> Visitor for CheckNoAsm<'a> {
fn visit_expr(&mut self, e: &ast::Expr) {
match e.node {
ast::ExprKind::InlineAsm(_) => span_err!(self.sess, e.span, E0472,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ struct BuildReducedGraphVisitor<'a, 'b: 'a> {
parent: Module<'b>,
}

impl<'a, 'b, 'v> Visitor<'v> for BuildReducedGraphVisitor<'a, 'b> {
impl<'a, 'b> Visitor for BuildReducedGraphVisitor<'a, 'b> {
fn visit_item(&mut self, item: &Item) {
let old_parent = self.parent;
self.resolver.build_reduced_graph_for_item(item, &mut self.parent);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/check_unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl<'a, 'b> UnusedImportCheckVisitor<'a, 'b> {
}
}

impl<'a, 'b, 'v> Visitor<'v> for UnusedImportCheckVisitor<'a, 'b> {
impl<'a, 'b> Visitor for UnusedImportCheckVisitor<'a, 'b> {
fn visit_item(&mut self, item: &ast::Item) {
visit::walk_item(self, item);
// Ignore is_public import statements because there's no way to be sure
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ pub enum Namespace {
ValueNS,
}

impl<'a, 'v> Visitor<'v> for Resolver<'a> {
impl<'a> Visitor for Resolver<'a> {
fn visit_item(&mut self, item: &Item) {
self.resolve_item(item);
}
Expand Down Expand Up @@ -562,9 +562,9 @@ impl<'a, 'v> Visitor<'v> for Resolver<'a> {
});
}
fn visit_fn(&mut self,
function_kind: FnKind<'v>,
declaration: &'v FnDecl,
block: &'v Block,
function_kind: FnKind,
declaration: &FnDecl,
block: &Block,
_: Span,
node_id: NodeId) {
let rib_kind = match function_kind {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_save_analysis/dump_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
}
}

impl<'v, 'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'v> for DumpVisitor<'l, 'tcx, 'll, D> {
impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor for DumpVisitor<'l, 'tcx, 'll, D> {
fn visit_item(&mut self, item: &ast::Item) {
use syntax::ast::ItemKind::*;
self.process_macro_use(item.span, item.id);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_save_analysis/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ impl PathCollector {
}
}

impl<'v> Visitor<'v> for PathCollector {
impl Visitor for PathCollector {
fn visit_pat(&mut self, p: &ast::Pat) {
match p.node {
PatKind::Struct(ref path, _, _) => {
Expand Down
39 changes: 5 additions & 34 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub use self::UnsafeSource::*;
pub use self::ViewPath_::*;
pub use self::PathParameters::*;

use attr::{ThinAttributes, HasAttrs};
use attr::ThinAttributes;
use codemap::{mk_sp, respan, Span, Spanned, DUMMY_SP, ExpnId};
use abi::Abi;
use errors;
Expand Down Expand Up @@ -825,10 +825,6 @@ impl StmtKind {
StmtKind::Mac(..) => None,
}
}

pub fn attrs(&self) -> &[Attribute] {
HasAttrs::attrs(self)
}
}

#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
Expand Down Expand Up @@ -858,12 +854,6 @@ pub struct Local {
pub attrs: ThinAttributes,
}

impl Local {
pub fn attrs(&self) -> &[Attribute] {
HasAttrs::attrs(self)
}
}

pub type Decl = Spanned<DeclKind>;

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
Expand All @@ -874,12 +864,6 @@ pub enum DeclKind {
Item(P<Item>),
}

impl Decl {
pub fn attrs(&self) -> &[Attribute] {
HasAttrs::attrs(self)
}
}

/// represents one arm of a 'match'
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct Arm {
Expand Down Expand Up @@ -919,12 +903,6 @@ pub struct Expr {
pub attrs: ThinAttributes
}

impl Expr {
pub fn attrs(&self) -> &[Attribute] {
HasAttrs::attrs(self)
}
}

impl fmt::Debug for Expr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "expr({}: {})", self.id, pprust::expr_to_string(self))
Expand Down Expand Up @@ -1174,13 +1152,13 @@ pub enum TokenTree {
/// A single token
Token(Span, token::Token),
/// A delimited sequence of token trees
Delimited(Span, Rc<Delimited>),
Delimited(Span, Delimited),

// This only makes sense in MBE macros.

/// A kleene-style repetition sequence with a span
// FIXME(eddyb) #12938 Use DST.
Sequence(Span, Rc<SequenceRepetition>),
Sequence(Span, SequenceRepetition),
}

impl TokenTree {
Expand Down Expand Up @@ -1229,15 +1207,15 @@ impl TokenTree {
Some(*cnt)
}).max().unwrap_or(0);

TokenTree::Delimited(sp, Rc::new(Delimited {
TokenTree::Delimited(sp, Delimited {
delim: token::Bracket,
open_span: sp,
tts: vec![TokenTree::Token(sp, token::Ident(token::str_to_ident("doc"))),
TokenTree::Token(sp, token::Eq),
TokenTree::Token(sp, token::Literal(
token::StrRaw(token::intern(&stripped), num_of_hashes), None))],
close_span: sp,
}))
})
}
(&TokenTree::Delimited(_, ref delimed), _) => {
if index == 0 {
Expand Down Expand Up @@ -1300,7 +1278,6 @@ pub type Mac = Spanned<Mac_>;
pub struct Mac_ {
pub path: Path,
pub tts: Vec<TokenTree>,
pub ctxt: SyntaxContext,
}

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
Expand Down Expand Up @@ -2036,12 +2013,6 @@ pub struct Item {
pub span: Span,
}

impl Item {
pub fn attrs(&self) -> &[Attribute] {
&self.attrs
}
}

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum ItemKind {
/// An`extern crate` item, with optional original crate name,
Expand Down
15 changes: 0 additions & 15 deletions src/libsyntax/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,21 +889,6 @@ pub trait HasAttrs: Sized {
fn map_attrs<F: FnOnce(Vec<ast::Attribute>) -> Vec<ast::Attribute>>(self, f: F) -> Self;
}

/// A cheap way to add Attributes to an AST node.
pub trait WithAttrs {
// FIXME: Could be extended to anything IntoIter<Item=Attribute>
fn with_attrs(self, attrs: ThinAttributes) -> Self;
}

impl<T: HasAttrs> WithAttrs for T {
fn with_attrs(self, attrs: ThinAttributes) -> Self {
self.map_attrs(|mut orig_attrs| {
orig_attrs.extend(attrs.into_attr_vec());
orig_attrs
})
}
}

impl HasAttrs for Vec<Attribute> {
fn attrs(&self) -> &[Attribute] {
&self
Expand Down
Loading