Skip to content

Commit

Permalink
Rollup merge of rust-lang#33943 - jseyfried:libsyntax_cleanup, r=nrc
Browse files Browse the repository at this point in the history
Miscellaneous low priority cleanup in `libsyntax`.
  • Loading branch information
jseyfried committed Jun 26, 2016
2 parents 82a15a6 + 0644aba commit 33ea1e3
Show file tree
Hide file tree
Showing 27 changed files with 269 additions and 365 deletions.
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 @@ -217,7 +217,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 @@ -235,7 +235,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 @@ -247,7 +247,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 @@ -263,18 +263,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 @@ -59,8 +59,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 @@ -505,7 +505,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 @@ -498,7 +498,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 @@ -557,9 +557,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 @@ -1038,7 +1038,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 @@ -693,7 +693,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
31 changes: 1 addition & 30 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 syntax_pos::{mk_sp, Span, DUMMY_SP, ExpnId};
use codemap::{respan, Spanned};
use abi::Abi;
Expand Down Expand Up @@ -846,10 +846,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 @@ -879,12 +875,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 @@ -895,12 +885,6 @@ pub enum DeclKind {
Item(P<Item>),
}

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

/// An arm of a 'match'.
///
/// E.g. `0...10 => { println!("match!") }` as in
Expand Down Expand Up @@ -949,12 +933,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 @@ -1143,7 +1121,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 @@ -1916,12 +1893,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 @@ -882,21 +882,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

0 comments on commit 33ea1e3

Please sign in to comment.