annotate stricter lifetimes on LateLintPass methods to allow them to forward to a Visitor
This commit is contained in:
parent
f7c93c07b8
commit
5e51edb0de
|
@ -129,8 +129,8 @@ impl<'a> CheckAttrVisitor<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Visitor for CheckAttrVisitor<'a> {
|
impl<'a> Visitor<'a> for CheckAttrVisitor<'a> {
|
||||||
fn visit_item(&mut self, item: &ast::Item) {
|
fn visit_item(&mut self, item: &'a ast::Item) {
|
||||||
let target = Target::from_item(item);
|
let target = Target::from_item(item);
|
||||||
for attr in &item.attrs {
|
for attr in &item.attrs {
|
||||||
self.check_attribute(attr, target);
|
self.check_attribute(attr, target);
|
||||||
|
|
|
@ -143,14 +143,14 @@ impl<'a> LoweringContext<'a> {
|
||||||
lctx: &'lcx mut LoweringContext<'interner>,
|
lctx: &'lcx mut LoweringContext<'interner>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'lcx, 'interner> Visitor for ItemLowerer<'lcx, 'interner> {
|
impl<'lcx, 'interner> Visitor<'lcx> for ItemLowerer<'lcx, 'interner> {
|
||||||
fn visit_item(&mut self, item: &Item) {
|
fn visit_item(&mut self, item: &'lcx Item) {
|
||||||
let hir_item = self.lctx.lower_item(item);
|
let hir_item = self.lctx.lower_item(item);
|
||||||
self.lctx.items.insert(item.id, hir_item);
|
self.lctx.items.insert(item.id, hir_item);
|
||||||
visit::walk_item(self, item);
|
visit::walk_item(self, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_impl_item(&mut self, item: &ImplItem) {
|
fn visit_impl_item(&mut self, item: &'lcx ImplItem) {
|
||||||
let id = self.lctx.lower_impl_item_ref(item).id;
|
let id = self.lctx.lower_impl_item_ref(item).id;
|
||||||
let hir_item = self.lctx.lower_impl_item(item);
|
let hir_item = self.lctx.lower_impl_item(item);
|
||||||
self.lctx.impl_items.insert(id, hir_item);
|
self.lctx.impl_items.insert(id, hir_item);
|
||||||
|
|
|
@ -135,8 +135,8 @@ impl<'a> DefCollector<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> visit::Visitor for DefCollector<'a> {
|
impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
||||||
fn visit_item(&mut self, i: &Item) {
|
fn visit_item(&mut self, i: &'a Item) {
|
||||||
debug!("visit_item: {:?}", i);
|
debug!("visit_item: {:?}", i);
|
||||||
|
|
||||||
// Pick the def data. This need not be unique, but the more
|
// Pick the def data. This need not be unique, but the more
|
||||||
|
@ -211,7 +211,7 @@ impl<'a> visit::Visitor for DefCollector<'a> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_foreign_item(&mut self, foreign_item: &ForeignItem) {
|
fn visit_foreign_item(&mut self, foreign_item: &'a ForeignItem) {
|
||||||
let def = self.create_def(foreign_item.id,
|
let def = self.create_def(foreign_item.id,
|
||||||
DefPathData::ValueNs(foreign_item.ident.name.as_str()));
|
DefPathData::ValueNs(foreign_item.ident.name.as_str()));
|
||||||
|
|
||||||
|
@ -220,7 +220,7 @@ impl<'a> visit::Visitor for DefCollector<'a> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_generics(&mut self, generics: &Generics) {
|
fn visit_generics(&mut self, generics: &'a Generics) {
|
||||||
for ty_param in generics.ty_params.iter() {
|
for ty_param in generics.ty_params.iter() {
|
||||||
self.create_def(ty_param.id, DefPathData::TypeParam(ty_param.ident.name.as_str()));
|
self.create_def(ty_param.id, DefPathData::TypeParam(ty_param.ident.name.as_str()));
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,7 @@ impl<'a> visit::Visitor for DefCollector<'a> {
|
||||||
visit::walk_generics(self, generics);
|
visit::walk_generics(self, generics);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_trait_item(&mut self, ti: &TraitItem) {
|
fn visit_trait_item(&mut self, ti: &'a TraitItem) {
|
||||||
let def_data = match ti.node {
|
let def_data = match ti.node {
|
||||||
TraitItemKind::Method(..) | TraitItemKind::Const(..) =>
|
TraitItemKind::Method(..) | TraitItemKind::Const(..) =>
|
||||||
DefPathData::ValueNs(ti.ident.name.as_str()),
|
DefPathData::ValueNs(ti.ident.name.as_str()),
|
||||||
|
@ -246,7 +246,7 @@ impl<'a> visit::Visitor for DefCollector<'a> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_impl_item(&mut self, ii: &ImplItem) {
|
fn visit_impl_item(&mut self, ii: &'a ImplItem) {
|
||||||
let def_data = match ii.node {
|
let def_data = match ii.node {
|
||||||
ImplItemKind::Method(..) | ImplItemKind::Const(..) =>
|
ImplItemKind::Method(..) | ImplItemKind::Const(..) =>
|
||||||
DefPathData::ValueNs(ii.ident.name.as_str()),
|
DefPathData::ValueNs(ii.ident.name.as_str()),
|
||||||
|
@ -264,7 +264,7 @@ impl<'a> visit::Visitor for DefCollector<'a> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_pat(&mut self, pat: &Pat) {
|
fn visit_pat(&mut self, pat: &'a Pat) {
|
||||||
let parent_def = self.parent_def;
|
let parent_def = self.parent_def;
|
||||||
|
|
||||||
match pat.node {
|
match pat.node {
|
||||||
|
@ -280,7 +280,7 @@ impl<'a> visit::Visitor for DefCollector<'a> {
|
||||||
self.parent_def = parent_def;
|
self.parent_def = parent_def;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_expr(&mut self, expr: &Expr) {
|
fn visit_expr(&mut self, expr: &'a Expr) {
|
||||||
let parent_def = self.parent_def;
|
let parent_def = self.parent_def;
|
||||||
|
|
||||||
match expr.node {
|
match expr.node {
|
||||||
|
@ -297,7 +297,7 @@ impl<'a> visit::Visitor for DefCollector<'a> {
|
||||||
self.parent_def = parent_def;
|
self.parent_def = parent_def;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_ty(&mut self, ty: &Ty) {
|
fn visit_ty(&mut self, ty: &'a Ty) {
|
||||||
match ty.node {
|
match ty.node {
|
||||||
TyKind::Mac(..) => return self.visit_macro_invoc(ty.id, false),
|
TyKind::Mac(..) => return self.visit_macro_invoc(ty.id, false),
|
||||||
TyKind::Array(_, ref length) => self.visit_ast_const_integer(length),
|
TyKind::Array(_, ref length) => self.visit_ast_const_integer(length),
|
||||||
|
@ -309,15 +309,15 @@ impl<'a> visit::Visitor for DefCollector<'a> {
|
||||||
visit::walk_ty(self, ty);
|
visit::walk_ty(self, ty);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_lifetime_def(&mut self, def: &LifetimeDef) {
|
fn visit_lifetime_def(&mut self, def: &'a LifetimeDef) {
|
||||||
self.create_def(def.lifetime.id, DefPathData::LifetimeDef(def.lifetime.name.as_str()));
|
self.create_def(def.lifetime.id, DefPathData::LifetimeDef(def.lifetime.name.as_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_macro_def(&mut self, macro_def: &MacroDef) {
|
fn visit_macro_def(&mut self, macro_def: &'a MacroDef) {
|
||||||
self.create_def(macro_def.id, DefPathData::MacroDef(macro_def.ident.name.as_str()));
|
self.create_def(macro_def.id, DefPathData::MacroDef(macro_def.ident.name.as_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_stmt(&mut self, stmt: &Stmt) {
|
fn visit_stmt(&mut self, stmt: &'a Stmt) {
|
||||||
match stmt.node {
|
match stmt.node {
|
||||||
StmtKind::Mac(..) => self.visit_macro_invoc(stmt.id, false),
|
StmtKind::Mac(..) => self.visit_macro_invoc(stmt.id, false),
|
||||||
_ => visit::walk_stmt(self, stmt),
|
_ => visit::walk_stmt(self, stmt),
|
||||||
|
|
|
@ -496,13 +496,13 @@ pub fn raw_struct_lint<'a, S>(sess: &'a Session,
|
||||||
err
|
err
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait LintContext: Sized {
|
pub trait LintContext<'tcx>: Sized {
|
||||||
fn sess(&self) -> &Session;
|
fn sess(&self) -> &Session;
|
||||||
fn lints(&self) -> &LintStore;
|
fn lints(&self) -> &LintStore;
|
||||||
fn mut_lints(&mut self) -> &mut LintStore;
|
fn mut_lints(&mut self) -> &mut LintStore;
|
||||||
fn level_stack(&mut self) -> &mut Vec<(LintId, LevelSource)>;
|
fn level_stack(&mut self) -> &mut Vec<(LintId, LevelSource)>;
|
||||||
fn enter_attrs(&mut self, attrs: &[ast::Attribute]);
|
fn enter_attrs(&mut self, attrs: &'tcx [ast::Attribute]);
|
||||||
fn exit_attrs(&mut self, attrs: &[ast::Attribute]);
|
fn exit_attrs(&mut self, attrs: &'tcx [ast::Attribute]);
|
||||||
|
|
||||||
/// Get the level of `lint` at the current position of the lint
|
/// Get the level of `lint` at the current position of the lint
|
||||||
/// traversal.
|
/// traversal.
|
||||||
|
@ -606,7 +606,7 @@ pub trait LintContext: Sized {
|
||||||
/// current lint context, call the provided function, then reset the
|
/// current lint context, call the provided function, then reset the
|
||||||
/// lints in effect to their previous state.
|
/// lints in effect to their previous state.
|
||||||
fn with_lint_attrs<F>(&mut self,
|
fn with_lint_attrs<F>(&mut self,
|
||||||
attrs: &[ast::Attribute],
|
attrs: &'tcx [ast::Attribute],
|
||||||
f: F)
|
f: F)
|
||||||
where F: FnOnce(&mut Self),
|
where F: FnOnce(&mut Self),
|
||||||
{
|
{
|
||||||
|
@ -729,7 +729,7 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> LintContext for LateContext<'a, 'tcx> {
|
impl<'a, 'tcx> LintContext<'tcx> for LateContext<'a, 'tcx> {
|
||||||
/// Get the overall compiler `Session` object.
|
/// Get the overall compiler `Session` object.
|
||||||
fn sess(&self) -> &Session {
|
fn sess(&self) -> &Session {
|
||||||
&self.tcx.sess
|
&self.tcx.sess
|
||||||
|
@ -747,18 +747,18 @@ impl<'a, 'tcx> LintContext for LateContext<'a, 'tcx> {
|
||||||
&mut self.level_stack
|
&mut self.level_stack
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enter_attrs(&mut self, attrs: &[ast::Attribute]) {
|
fn enter_attrs(&mut self, attrs: &'tcx [ast::Attribute]) {
|
||||||
debug!("late context: enter_attrs({:?})", attrs);
|
debug!("late context: enter_attrs({:?})", attrs);
|
||||||
run_lints!(self, enter_lint_attrs, late_passes, attrs);
|
run_lints!(self, enter_lint_attrs, late_passes, attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exit_attrs(&mut self, attrs: &[ast::Attribute]) {
|
fn exit_attrs(&mut self, attrs: &'tcx [ast::Attribute]) {
|
||||||
debug!("late context: exit_attrs({:?})", attrs);
|
debug!("late context: exit_attrs({:?})", attrs);
|
||||||
run_lints!(self, exit_lint_attrs, late_passes, attrs);
|
run_lints!(self, exit_lint_attrs, late_passes, attrs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> LintContext for EarlyContext<'a> {
|
impl<'a> LintContext<'a> for EarlyContext<'a> {
|
||||||
/// Get the overall compiler `Session` object.
|
/// Get the overall compiler `Session` object.
|
||||||
fn sess(&self) -> &Session {
|
fn sess(&self) -> &Session {
|
||||||
&self.sess
|
&self.sess
|
||||||
|
@ -776,12 +776,12 @@ impl<'a> LintContext for EarlyContext<'a> {
|
||||||
&mut self.level_stack
|
&mut self.level_stack
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enter_attrs(&mut self, attrs: &[ast::Attribute]) {
|
fn enter_attrs(&mut self, attrs: &'a [ast::Attribute]) {
|
||||||
debug!("early context: enter_attrs({:?})", attrs);
|
debug!("early context: enter_attrs({:?})", attrs);
|
||||||
run_lints!(self, enter_lint_attrs, early_passes, attrs);
|
run_lints!(self, enter_lint_attrs, early_passes, attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exit_attrs(&mut self, attrs: &[ast::Attribute]) {
|
fn exit_attrs(&mut self, attrs: &'a [ast::Attribute]) {
|
||||||
debug!("early context: exit_attrs({:?})", attrs);
|
debug!("early context: exit_attrs({:?})", attrs);
|
||||||
run_lints!(self, exit_lint_attrs, early_passes, attrs);
|
run_lints!(self, exit_lint_attrs, early_passes, attrs);
|
||||||
}
|
}
|
||||||
|
@ -949,14 +949,14 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> {
|
||||||
hir_visit::walk_path(self, p);
|
hir_visit::walk_path(self, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_attribute(&mut self, attr: &ast::Attribute) {
|
fn visit_attribute(&mut self, attr: &'tcx ast::Attribute) {
|
||||||
check_lint_name_attribute(self, attr);
|
check_lint_name_attribute(self, attr);
|
||||||
run_lints!(self, check_attribute, late_passes, attr);
|
run_lints!(self, check_attribute, late_passes, attr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ast_visit::Visitor for EarlyContext<'a> {
|
impl<'a> ast_visit::Visitor<'a> for EarlyContext<'a> {
|
||||||
fn visit_item(&mut self, it: &ast::Item) {
|
fn visit_item(&mut self, it: &'a ast::Item) {
|
||||||
self.with_lint_attrs(&it.attrs, |cx| {
|
self.with_lint_attrs(&it.attrs, |cx| {
|
||||||
run_lints!(cx, check_item, early_passes, it);
|
run_lints!(cx, check_item, early_passes, it);
|
||||||
ast_visit::walk_item(cx, it);
|
ast_visit::walk_item(cx, it);
|
||||||
|
@ -964,7 +964,7 @@ impl<'a> ast_visit::Visitor for EarlyContext<'a> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_foreign_item(&mut self, it: &ast::ForeignItem) {
|
fn visit_foreign_item(&mut self, it: &'a ast::ForeignItem) {
|
||||||
self.with_lint_attrs(&it.attrs, |cx| {
|
self.with_lint_attrs(&it.attrs, |cx| {
|
||||||
run_lints!(cx, check_foreign_item, early_passes, it);
|
run_lints!(cx, check_foreign_item, early_passes, it);
|
||||||
ast_visit::walk_foreign_item(cx, it);
|
ast_visit::walk_foreign_item(cx, it);
|
||||||
|
@ -972,24 +972,24 @@ impl<'a> ast_visit::Visitor for EarlyContext<'a> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_pat(&mut self, p: &ast::Pat) {
|
fn visit_pat(&mut self, p: &'a ast::Pat) {
|
||||||
run_lints!(self, check_pat, early_passes, p);
|
run_lints!(self, check_pat, early_passes, p);
|
||||||
ast_visit::walk_pat(self, p);
|
ast_visit::walk_pat(self, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_expr(&mut self, e: &ast::Expr) {
|
fn visit_expr(&mut self, e: &'a ast::Expr) {
|
||||||
self.with_lint_attrs(&e.attrs, |cx| {
|
self.with_lint_attrs(&e.attrs, |cx| {
|
||||||
run_lints!(cx, check_expr, early_passes, e);
|
run_lints!(cx, check_expr, early_passes, e);
|
||||||
ast_visit::walk_expr(cx, e);
|
ast_visit::walk_expr(cx, e);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_stmt(&mut self, s: &ast::Stmt) {
|
fn visit_stmt(&mut self, s: &'a ast::Stmt) {
|
||||||
run_lints!(self, check_stmt, early_passes, s);
|
run_lints!(self, check_stmt, early_passes, s);
|
||||||
ast_visit::walk_stmt(self, s);
|
ast_visit::walk_stmt(self, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_fn(&mut self, fk: ast_visit::FnKind, decl: &ast::FnDecl,
|
fn visit_fn(&mut self, fk: ast_visit::FnKind<'a>, decl: &'a ast::FnDecl,
|
||||||
span: Span, id: ast::NodeId) {
|
span: Span, id: ast::NodeId) {
|
||||||
run_lints!(self, check_fn, early_passes, fk, decl, span, id);
|
run_lints!(self, check_fn, early_passes, fk, decl, span, id);
|
||||||
ast_visit::walk_fn(self, fk, decl, span);
|
ast_visit::walk_fn(self, fk, decl, span);
|
||||||
|
@ -997,9 +997,9 @@ impl<'a> ast_visit::Visitor for EarlyContext<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_variant_data(&mut self,
|
fn visit_variant_data(&mut self,
|
||||||
s: &ast::VariantData,
|
s: &'a ast::VariantData,
|
||||||
ident: ast::Ident,
|
ident: ast::Ident,
|
||||||
g: &ast::Generics,
|
g: &'a ast::Generics,
|
||||||
item_id: ast::NodeId,
|
item_id: ast::NodeId,
|
||||||
_: Span) {
|
_: Span) {
|
||||||
run_lints!(self, check_struct_def, early_passes, s, ident, g, item_id);
|
run_lints!(self, check_struct_def, early_passes, s, ident, g, item_id);
|
||||||
|
@ -1007,14 +1007,14 @@ impl<'a> ast_visit::Visitor for EarlyContext<'a> {
|
||||||
run_lints!(self, check_struct_def_post, early_passes, s, ident, g, item_id);
|
run_lints!(self, check_struct_def_post, early_passes, s, ident, g, item_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_struct_field(&mut self, s: &ast::StructField) {
|
fn visit_struct_field(&mut self, s: &'a ast::StructField) {
|
||||||
self.with_lint_attrs(&s.attrs, |cx| {
|
self.with_lint_attrs(&s.attrs, |cx| {
|
||||||
run_lints!(cx, check_struct_field, early_passes, s);
|
run_lints!(cx, check_struct_field, early_passes, s);
|
||||||
ast_visit::walk_struct_field(cx, s);
|
ast_visit::walk_struct_field(cx, s);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_variant(&mut self, v: &ast::Variant, g: &ast::Generics, item_id: ast::NodeId) {
|
fn visit_variant(&mut self, v: &'a ast::Variant, g: &'a ast::Generics, item_id: ast::NodeId) {
|
||||||
self.with_lint_attrs(&v.node.attrs, |cx| {
|
self.with_lint_attrs(&v.node.attrs, |cx| {
|
||||||
run_lints!(cx, check_variant, early_passes, v, g);
|
run_lints!(cx, check_variant, early_passes, v, g);
|
||||||
ast_visit::walk_variant(cx, v, g, item_id);
|
ast_visit::walk_variant(cx, v, g, item_id);
|
||||||
|
@ -1022,7 +1022,7 @@ impl<'a> ast_visit::Visitor for EarlyContext<'a> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_ty(&mut self, t: &ast::Ty) {
|
fn visit_ty(&mut self, t: &'a ast::Ty) {
|
||||||
run_lints!(self, check_ty, early_passes, t);
|
run_lints!(self, check_ty, early_passes, t);
|
||||||
ast_visit::walk_ty(self, t);
|
ast_visit::walk_ty(self, t);
|
||||||
}
|
}
|
||||||
|
@ -1031,40 +1031,40 @@ impl<'a> ast_visit::Visitor for EarlyContext<'a> {
|
||||||
run_lints!(self, check_ident, early_passes, sp, id);
|
run_lints!(self, check_ident, early_passes, sp, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_mod(&mut self, m: &ast::Mod, s: Span, n: ast::NodeId) {
|
fn visit_mod(&mut self, m: &'a ast::Mod, s: Span, n: ast::NodeId) {
|
||||||
run_lints!(self, check_mod, early_passes, m, s, n);
|
run_lints!(self, check_mod, early_passes, m, s, n);
|
||||||
ast_visit::walk_mod(self, m);
|
ast_visit::walk_mod(self, m);
|
||||||
run_lints!(self, check_mod_post, early_passes, m, s, n);
|
run_lints!(self, check_mod_post, early_passes, m, s, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_local(&mut self, l: &ast::Local) {
|
fn visit_local(&mut self, l: &'a ast::Local) {
|
||||||
self.with_lint_attrs(&l.attrs, |cx| {
|
self.with_lint_attrs(&l.attrs, |cx| {
|
||||||
run_lints!(cx, check_local, early_passes, l);
|
run_lints!(cx, check_local, early_passes, l);
|
||||||
ast_visit::walk_local(cx, l);
|
ast_visit::walk_local(cx, l);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_block(&mut self, b: &ast::Block) {
|
fn visit_block(&mut self, b: &'a ast::Block) {
|
||||||
run_lints!(self, check_block, early_passes, b);
|
run_lints!(self, check_block, early_passes, b);
|
||||||
ast_visit::walk_block(self, b);
|
ast_visit::walk_block(self, b);
|
||||||
run_lints!(self, check_block_post, early_passes, b);
|
run_lints!(self, check_block_post, early_passes, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_arm(&mut self, a: &ast::Arm) {
|
fn visit_arm(&mut self, a: &'a ast::Arm) {
|
||||||
run_lints!(self, check_arm, early_passes, a);
|
run_lints!(self, check_arm, early_passes, a);
|
||||||
ast_visit::walk_arm(self, a);
|
ast_visit::walk_arm(self, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_expr_post(&mut self, e: &ast::Expr) {
|
fn visit_expr_post(&mut self, e: &'a ast::Expr) {
|
||||||
run_lints!(self, check_expr_post, early_passes, e);
|
run_lints!(self, check_expr_post, early_passes, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_generics(&mut self, g: &ast::Generics) {
|
fn visit_generics(&mut self, g: &'a ast::Generics) {
|
||||||
run_lints!(self, check_generics, early_passes, g);
|
run_lints!(self, check_generics, early_passes, g);
|
||||||
ast_visit::walk_generics(self, g);
|
ast_visit::walk_generics(self, g);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_trait_item(&mut self, trait_item: &ast::TraitItem) {
|
fn visit_trait_item(&mut self, trait_item: &'a ast::TraitItem) {
|
||||||
self.with_lint_attrs(&trait_item.attrs, |cx| {
|
self.with_lint_attrs(&trait_item.attrs, |cx| {
|
||||||
run_lints!(cx, check_trait_item, early_passes, trait_item);
|
run_lints!(cx, check_trait_item, early_passes, trait_item);
|
||||||
ast_visit::walk_trait_item(cx, trait_item);
|
ast_visit::walk_trait_item(cx, trait_item);
|
||||||
|
@ -1072,7 +1072,7 @@ impl<'a> ast_visit::Visitor for EarlyContext<'a> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_impl_item(&mut self, impl_item: &ast::ImplItem) {
|
fn visit_impl_item(&mut self, impl_item: &'a ast::ImplItem) {
|
||||||
self.with_lint_attrs(&impl_item.attrs, |cx| {
|
self.with_lint_attrs(&impl_item.attrs, |cx| {
|
||||||
run_lints!(cx, check_impl_item, early_passes, impl_item);
|
run_lints!(cx, check_impl_item, early_passes, impl_item);
|
||||||
ast_visit::walk_impl_item(cx, impl_item);
|
ast_visit::walk_impl_item(cx, impl_item);
|
||||||
|
@ -1080,25 +1080,25 @@ impl<'a> ast_visit::Visitor for EarlyContext<'a> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_lifetime(&mut self, lt: &ast::Lifetime) {
|
fn visit_lifetime(&mut self, lt: &'a ast::Lifetime) {
|
||||||
run_lints!(self, check_lifetime, early_passes, lt);
|
run_lints!(self, check_lifetime, early_passes, lt);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_lifetime_def(&mut self, lt: &ast::LifetimeDef) {
|
fn visit_lifetime_def(&mut self, lt: &'a ast::LifetimeDef) {
|
||||||
run_lints!(self, check_lifetime_def, early_passes, lt);
|
run_lints!(self, check_lifetime_def, early_passes, lt);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_path(&mut self, p: &ast::Path, id: ast::NodeId) {
|
fn visit_path(&mut self, p: &'a ast::Path, id: ast::NodeId) {
|
||||||
run_lints!(self, check_path, early_passes, p, id);
|
run_lints!(self, check_path, early_passes, p, id);
|
||||||
ast_visit::walk_path(self, p);
|
ast_visit::walk_path(self, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_path_list_item(&mut self, prefix: &ast::Path, item: &ast::PathListItem) {
|
fn visit_path_list_item(&mut self, prefix: &'a ast::Path, item: &'a ast::PathListItem) {
|
||||||
run_lints!(self, check_path_list_item, early_passes, item);
|
run_lints!(self, check_path_list_item, early_passes, item);
|
||||||
ast_visit::walk_path_list_item(self, prefix, item);
|
ast_visit::walk_path_list_item(self, prefix, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_attribute(&mut self, attr: &ast::Attribute) {
|
fn visit_attribute(&mut self, attr: &'a ast::Attribute) {
|
||||||
run_lints!(self, check_attribute, early_passes, attr);
|
run_lints!(self, check_attribute, early_passes, attr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,51 +131,104 @@ pub trait LintPass {
|
||||||
// contains a few lint-specific methods with no equivalent in `Visitor`.
|
// contains a few lint-specific methods with no equivalent in `Visitor`.
|
||||||
pub trait LateLintPass: LintPass {
|
pub trait LateLintPass: LintPass {
|
||||||
fn check_name(&mut self, _: &LateContext, _: Span, _: ast::Name) { }
|
fn check_name(&mut self, _: &LateContext, _: Span, _: ast::Name) { }
|
||||||
fn check_crate(&mut self, _: &LateContext, _: &hir::Crate) { }
|
fn check_crate<'a, 'tcx:'a >(&mut self, _: &'a LateContext<'a, 'tcx>, _: &'tcx hir::Crate) { }
|
||||||
fn check_crate_post(&mut self, _: &LateContext, _: &hir::Crate) { }
|
fn check_crate_post<'a, 'tcx: 'a>(&mut self,
|
||||||
fn check_mod(&mut self, _: &LateContext, _: &hir::Mod, _: Span, _: ast::NodeId) { }
|
_: &'a LateContext<'a, 'tcx>,
|
||||||
fn check_mod_post(&mut self, _: &LateContext, _: &hir::Mod, _: Span, _: ast::NodeId) { }
|
_: &'tcx hir::Crate) { }
|
||||||
fn check_foreign_item(&mut self, _: &LateContext, _: &hir::ForeignItem) { }
|
fn check_mod<'a, 'tcx: 'a>(&mut self,
|
||||||
fn check_foreign_item_post(&mut self, _: &LateContext, _: &hir::ForeignItem) { }
|
_: &'a LateContext<'a, 'tcx>,
|
||||||
fn check_item(&mut self, _: &LateContext, _: &hir::Item) { }
|
_: &'tcx hir::Mod,
|
||||||
fn check_item_post(&mut self, _: &LateContext, _: &hir::Item) { }
|
_: Span,
|
||||||
fn check_local(&mut self, _: &LateContext, _: &hir::Local) { }
|
_: ast::NodeId) { }
|
||||||
fn check_block(&mut self, _: &LateContext, _: &hir::Block) { }
|
fn check_mod_post<'a, 'tcx: 'a>(&mut self,
|
||||||
fn check_block_post(&mut self, _: &LateContext, _: &hir::Block) { }
|
_: &'a LateContext<'a, 'tcx>,
|
||||||
fn check_stmt(&mut self, _: &LateContext, _: &hir::Stmt) { }
|
_: &'tcx hir::Mod,
|
||||||
fn check_arm(&mut self, _: &LateContext, _: &hir::Arm) { }
|
_: Span,
|
||||||
fn check_pat(&mut self, _: &LateContext, _: &hir::Pat) { }
|
_: ast::NodeId) { }
|
||||||
fn check_decl(&mut self, _: &LateContext, _: &hir::Decl) { }
|
fn check_foreign_item<'a, 'tcx: 'a>(&mut self,
|
||||||
fn check_expr(&mut self, _: &LateContext, _: &hir::Expr) { }
|
_: &'a LateContext<'a, 'tcx>,
|
||||||
fn check_expr_post(&mut self, _: &LateContext, _: &hir::Expr) { }
|
_: &'tcx hir::ForeignItem) { }
|
||||||
fn check_ty(&mut self, _: &LateContext, _: &hir::Ty) { }
|
fn check_foreign_item_post<'a, 'tcx: 'a>(&mut self,
|
||||||
fn check_generics(&mut self, _: &LateContext, _: &hir::Generics) { }
|
_: &'a LateContext<'a, 'tcx>,
|
||||||
fn check_fn(&mut self, _: &LateContext,
|
_: &'tcx hir::ForeignItem) { }
|
||||||
_: FnKind, _: &hir::FnDecl, _: &hir::Expr, _: Span, _: ast::NodeId) { }
|
fn check_item<'a, 'tcx: 'a>(&mut self,
|
||||||
fn check_fn_post(&mut self, _: &LateContext,
|
_: &'a LateContext<'a, 'tcx>,
|
||||||
_: FnKind, _: &hir::FnDecl, _: &hir::Expr, _: Span, _: ast::NodeId) { }
|
_: &'tcx hir::Item) { }
|
||||||
fn check_trait_item(&mut self, _: &LateContext, _: &hir::TraitItem) { }
|
fn check_item_post<'a, 'tcx: 'a>(&mut self,
|
||||||
fn check_trait_item_post(&mut self, _: &LateContext, _: &hir::TraitItem) { }
|
_: &'a LateContext<'a, 'tcx>,
|
||||||
fn check_impl_item(&mut self, _: &LateContext, _: &hir::ImplItem) { }
|
_: &'tcx hir::Item) { }
|
||||||
fn check_impl_item_post(&mut self, _: &LateContext, _: &hir::ImplItem) { }
|
fn check_local<'a, 'tcx: 'a>(&mut self, _: &'a LateContext<'a, 'tcx>, _: &'tcx hir::Local) { }
|
||||||
fn check_struct_def(&mut self, _: &LateContext,
|
fn check_block<'a, 'tcx: 'a>(&mut self, _: &'a LateContext<'a, 'tcx>, _: &'tcx hir::Block) { }
|
||||||
_: &hir::VariantData, _: ast::Name, _: &hir::Generics, _: ast::NodeId) { }
|
fn check_block_post<'a, 'tcx: 'a>(&mut self,
|
||||||
fn check_struct_def_post(&mut self, _: &LateContext,
|
_: &'a LateContext<'a, 'tcx>,
|
||||||
_: &hir::VariantData, _: ast::Name, _: &hir::Generics, _: ast::NodeId) { }
|
_: &'tcx hir::Block) { }
|
||||||
fn check_struct_field(&mut self, _: &LateContext, _: &hir::StructField) { }
|
fn check_stmt<'a, 'tcx: 'a>(&mut self, _: &'a LateContext<'a, 'tcx>, _: &'tcx hir::Stmt) { }
|
||||||
fn check_variant(&mut self, _: &LateContext, _: &hir::Variant, _: &hir::Generics) { }
|
fn check_arm<'a, 'tcx: 'a>(&mut self, _: &'a LateContext<'a, 'tcx>, _: &'tcx hir::Arm) { }
|
||||||
fn check_variant_post(&mut self, _: &LateContext, _: &hir::Variant, _: &hir::Generics) { }
|
fn check_pat<'a, 'tcx: 'a>(&mut self, _: &'a LateContext<'a, 'tcx>, _: &'tcx hir::Pat) { }
|
||||||
fn check_lifetime(&mut self, _: &LateContext, _: &hir::Lifetime) { }
|
fn check_decl<'a, 'tcx: 'a>(&mut self, _: &'a LateContext<'a, 'tcx>, _: &'tcx hir::Decl) { }
|
||||||
fn check_lifetime_def(&mut self, _: &LateContext, _: &hir::LifetimeDef) { }
|
fn check_expr<'a, 'tcx: 'a>(&mut self, _: &'a LateContext<'a, 'tcx>, _: &'tcx hir::Expr) { }
|
||||||
fn check_path(&mut self, _: &LateContext, _: &hir::Path, _: ast::NodeId) { }
|
fn check_expr_post<'a, 'tcx: 'a>(&mut self,
|
||||||
fn check_attribute(&mut self, _: &LateContext, _: &ast::Attribute) { }
|
_: &'a LateContext<'a, 'tcx>,
|
||||||
|
_: &'tcx hir::Expr) { }
|
||||||
|
fn check_ty<'a, 'tcx: 'a>(&mut self, _: &'a LateContext<'a, 'tcx>, _: &'tcx hir::Ty) { }
|
||||||
|
fn check_generics<'a, 'tcx: 'a>(&mut self,
|
||||||
|
_: &'a LateContext<'a, 'tcx>,
|
||||||
|
_: &'tcx hir::Generics) { }
|
||||||
|
fn check_fn<'a, 'tcx: 'a>(&mut self, _: &'a LateContext<'a, 'tcx>,
|
||||||
|
_: FnKind<'tcx>, _: &'tcx hir::FnDecl, _: &'tcx hir::Expr, _: Span, _: ast::NodeId) { }
|
||||||
|
fn check_fn_post<'a, 'tcx: 'a>(&mut self, _: &'a LateContext<'a, 'tcx>,
|
||||||
|
_: FnKind<'tcx>, _: &'tcx hir::FnDecl, _: &'tcx hir::Expr, _: Span, _: ast::NodeId) { }
|
||||||
|
fn check_trait_item<'a, 'tcx: 'a>(&mut self,
|
||||||
|
_: &'a LateContext<'a, 'tcx>,
|
||||||
|
_: &'tcx hir::TraitItem) { }
|
||||||
|
fn check_trait_item_post<'a, 'tcx: 'a>(&mut self,
|
||||||
|
_: &'a LateContext<'a, 'tcx>,
|
||||||
|
_: &'tcx hir::TraitItem) { }
|
||||||
|
fn check_impl_item<'a, 'tcx: 'a>(&mut self,
|
||||||
|
_: &'a LateContext<'a, 'tcx>,
|
||||||
|
_: &'tcx hir::ImplItem) { }
|
||||||
|
fn check_impl_item_post<'a, 'tcx: 'a>(&mut self,
|
||||||
|
_: &'a LateContext<'a, 'tcx>,
|
||||||
|
_: &'tcx hir::ImplItem) { }
|
||||||
|
fn check_struct_def<'a, 'tcx: 'a>(&mut self, _: &'a LateContext<'a, 'tcx>,
|
||||||
|
_: &'tcx hir::VariantData, _: ast::Name, _: &'tcx hir::Generics, _: ast::NodeId) { }
|
||||||
|
fn check_struct_def_post<'a, 'tcx: 'a>(&mut self, _: &'a LateContext<'a, 'tcx>,
|
||||||
|
_: &'tcx hir::VariantData, _: ast::Name, _: &'tcx hir::Generics, _: ast::NodeId) { }
|
||||||
|
fn check_struct_field<'a, 'tcx: 'a>(&mut self,
|
||||||
|
_: &'a LateContext<'a, 'tcx>,
|
||||||
|
_: &'tcx hir::StructField) { }
|
||||||
|
fn check_variant<'a, 'tcx: 'a>(&mut self,
|
||||||
|
_: &'a LateContext<'a, 'tcx>,
|
||||||
|
_: &'tcx hir::Variant,
|
||||||
|
_: &'tcx hir::Generics) { }
|
||||||
|
fn check_variant_post<'a, 'tcx: 'a>(&mut self,
|
||||||
|
_: &'a LateContext<'a, 'tcx>,
|
||||||
|
_: &'tcx hir::Variant,
|
||||||
|
_: &'tcx hir::Generics) { }
|
||||||
|
fn check_lifetime<'a, 'tcx: 'a>(&mut self,
|
||||||
|
_: &'a LateContext<'a, 'tcx>,
|
||||||
|
_: &'tcx hir::Lifetime) { }
|
||||||
|
fn check_lifetime_def<'a, 'tcx: 'a>(&mut self,
|
||||||
|
_: &'a LateContext<'a, 'tcx>,
|
||||||
|
_: &'tcx hir::LifetimeDef) { }
|
||||||
|
fn check_path<'a, 'tcx: 'a>(&mut self,
|
||||||
|
_: &'a LateContext<'a, 'tcx>,
|
||||||
|
_: &'tcx hir::Path,
|
||||||
|
_: ast::NodeId) { }
|
||||||
|
fn check_attribute<'a, 'tcx: 'a>(&mut self,
|
||||||
|
_: &'a LateContext<'a, 'tcx>,
|
||||||
|
_: &'tcx ast::Attribute) { }
|
||||||
|
|
||||||
/// Called when entering a syntax node that can have lint attributes such
|
/// Called when entering a syntax node that can have lint attributes such
|
||||||
/// as `#[allow(...)]`. Called with *all* the attributes of that node.
|
/// as `#[allow(...)]`. Called with *all* the attributes of that node.
|
||||||
fn enter_lint_attrs(&mut self, _: &LateContext, _: &[ast::Attribute]) { }
|
fn enter_lint_attrs<'a, 'tcx: 'a>(&mut self,
|
||||||
|
_: &'a LateContext<'a, 'tcx>,
|
||||||
|
_: &'tcx [ast::Attribute]) { }
|
||||||
|
|
||||||
/// Counterpart to `enter_lint_attrs`.
|
/// Counterpart to `enter_lint_attrs`.
|
||||||
fn exit_lint_attrs(&mut self, _: &LateContext, _: &[ast::Attribute]) { }
|
fn exit_lint_attrs<'a, 'tcx: 'a>(&mut self,
|
||||||
|
_: &'a LateContext<'a, 'tcx>,
|
||||||
|
_: &'tcx [ast::Attribute]) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait EarlyLintPass: LintPass {
|
pub trait EarlyLintPass: LintPass {
|
||||||
|
|
|
@ -100,7 +100,7 @@ impl LintPass for NonCamelCaseTypes {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for NonCamelCaseTypes {
|
impl LateLintPass for NonCamelCaseTypes {
|
||||||
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
|
fn check_item<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item) {
|
||||||
let extern_repr_count = it.attrs
|
let extern_repr_count = it.attrs
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|attr| {
|
.filter(|attr| {
|
||||||
|
@ -133,7 +133,9 @@ impl LateLintPass for NonCamelCaseTypes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_generics(&mut self, cx: &LateContext, it: &hir::Generics) {
|
fn check_generics<'a, 'tcx: 'a>(&mut self,
|
||||||
|
cx: &LateContext<'a, 'tcx>,
|
||||||
|
it: &'tcx hir::Generics) {
|
||||||
for gen in it.ty_params.iter() {
|
for gen in it.ty_params.iter() {
|
||||||
self.check_case(cx, "type parameter", gen.name, gen.span);
|
self.check_case(cx, "type parameter", gen.name, gen.span);
|
||||||
}
|
}
|
||||||
|
@ -227,7 +229,7 @@ impl LintPass for NonSnakeCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for NonSnakeCase {
|
impl LateLintPass for NonSnakeCase {
|
||||||
fn check_crate(&mut self, cx: &LateContext, cr: &hir::Crate) {
|
fn check_crate<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, cr: &'tcx hir::Crate) {
|
||||||
let attr_crate_name = cr.attrs
|
let attr_crate_name = cr.attrs
|
||||||
.iter()
|
.iter()
|
||||||
.find(|at| at.check_name("crate_name"))
|
.find(|at| at.check_name("crate_name"))
|
||||||
|
@ -239,13 +241,13 @@ impl LateLintPass for NonSnakeCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_fn(&mut self,
|
fn check_fn<'a, 'tcx: 'a>(&mut self,
|
||||||
cx: &LateContext,
|
cx: &LateContext<'a, 'tcx>,
|
||||||
fk: FnKind,
|
fk: FnKind,
|
||||||
_: &hir::FnDecl,
|
_: &'tcx hir::FnDecl,
|
||||||
_: &hir::Expr,
|
_: &'tcx hir::Expr,
|
||||||
span: Span,
|
span: Span,
|
||||||
id: ast::NodeId) {
|
id: ast::NodeId) {
|
||||||
match fk {
|
match fk {
|
||||||
FnKind::Method(name, ..) => {
|
FnKind::Method(name, ..) => {
|
||||||
match method_context(cx, id, span) {
|
match method_context(cx, id, span) {
|
||||||
|
@ -265,13 +267,15 @@ impl LateLintPass for NonSnakeCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
|
fn check_item<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item) {
|
||||||
if let hir::ItemMod(_) = it.node {
|
if let hir::ItemMod(_) = it.node {
|
||||||
self.check_snake_case(cx, "module", &it.name.as_str(), Some(it.span));
|
self.check_snake_case(cx, "module", &it.name.as_str(), Some(it.span));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_trait_item(&mut self, cx: &LateContext, trait_item: &hir::TraitItem) {
|
fn check_trait_item<'a, 'tcx: 'a>(&mut self,
|
||||||
|
cx: &LateContext<'a, 'tcx>,
|
||||||
|
trait_item: &'tcx hir::TraitItem) {
|
||||||
if let hir::MethodTraitItem(_, None) = trait_item.node {
|
if let hir::MethodTraitItem(_, None) = trait_item.node {
|
||||||
self.check_snake_case(cx,
|
self.check_snake_case(cx,
|
||||||
"trait method",
|
"trait method",
|
||||||
|
@ -280,14 +284,16 @@ impl LateLintPass for NonSnakeCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_lifetime_def(&mut self, cx: &LateContext, t: &hir::LifetimeDef) {
|
fn check_lifetime_def<'a, 'tcx: 'a>(&mut self,
|
||||||
|
cx: &LateContext<'a, 'tcx>,
|
||||||
|
t: &'tcx hir::LifetimeDef) {
|
||||||
self.check_snake_case(cx,
|
self.check_snake_case(cx,
|
||||||
"lifetime",
|
"lifetime",
|
||||||
&t.lifetime.name.as_str(),
|
&t.lifetime.name.as_str(),
|
||||||
Some(t.lifetime.span));
|
Some(t.lifetime.span));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_pat(&mut self, cx: &LateContext, p: &hir::Pat) {
|
fn check_pat<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, p: &'tcx hir::Pat) {
|
||||||
// Exclude parameter names from foreign functions
|
// Exclude parameter names from foreign functions
|
||||||
let parent_node = cx.tcx.map.get_parent_node(p.id);
|
let parent_node = cx.tcx.map.get_parent_node(p.id);
|
||||||
if let hir::map::NodeForeignItem(item) = cx.tcx.map.get(parent_node) {
|
if let hir::map::NodeForeignItem(item) = cx.tcx.map.get(parent_node) {
|
||||||
|
@ -301,12 +307,12 @@ impl LateLintPass for NonSnakeCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_struct_def(&mut self,
|
fn check_struct_def<'a, 'tcx: 'a>(&mut self,
|
||||||
cx: &LateContext,
|
cx: &LateContext<'a, 'tcx>,
|
||||||
s: &hir::VariantData,
|
s: &'tcx hir::VariantData,
|
||||||
_: ast::Name,
|
_: ast::Name,
|
||||||
_: &hir::Generics,
|
_: &'tcx hir::Generics,
|
||||||
_: ast::NodeId) {
|
_: ast::NodeId) {
|
||||||
for sf in s.fields() {
|
for sf in s.fields() {
|
||||||
self.check_snake_case(cx, "structure field", &sf.name.as_str(), Some(sf.span));
|
self.check_snake_case(cx, "structure field", &sf.name.as_str(), Some(sf.span));
|
||||||
}
|
}
|
||||||
|
@ -349,7 +355,7 @@ impl LintPass for NonUpperCaseGlobals {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for NonUpperCaseGlobals {
|
impl LateLintPass for NonUpperCaseGlobals {
|
||||||
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
|
fn check_item<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item) {
|
||||||
match it.node {
|
match it.node {
|
||||||
hir::ItemStatic(..) => {
|
hir::ItemStatic(..) => {
|
||||||
NonUpperCaseGlobals::check_upper_case(cx, "static variable", it.name, it.span);
|
NonUpperCaseGlobals::check_upper_case(cx, "static variable", it.name, it.span);
|
||||||
|
@ -361,7 +367,9 @@ impl LateLintPass for NonUpperCaseGlobals {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_trait_item(&mut self, cx: &LateContext, ti: &hir::TraitItem) {
|
fn check_trait_item<'a, 'tcx: 'a>(&mut self,
|
||||||
|
cx: &LateContext<'a, 'tcx>,
|
||||||
|
ti: &'tcx hir::TraitItem) {
|
||||||
match ti.node {
|
match ti.node {
|
||||||
hir::ConstTraitItem(..) => {
|
hir::ConstTraitItem(..) => {
|
||||||
NonUpperCaseGlobals::check_upper_case(cx, "associated constant", ti.name, ti.span);
|
NonUpperCaseGlobals::check_upper_case(cx, "associated constant", ti.name, ti.span);
|
||||||
|
@ -370,7 +378,9 @@ impl LateLintPass for NonUpperCaseGlobals {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_impl_item(&mut self, cx: &LateContext, ii: &hir::ImplItem) {
|
fn check_impl_item<'a, 'tcx: 'a>(&mut self,
|
||||||
|
cx: &LateContext<'a, 'tcx>,
|
||||||
|
ii: &'tcx hir::ImplItem) {
|
||||||
match ii.node {
|
match ii.node {
|
||||||
hir::ImplItemKind::Const(..) => {
|
hir::ImplItemKind::Const(..) => {
|
||||||
NonUpperCaseGlobals::check_upper_case(cx, "associated constant", ii.name, ii.span);
|
NonUpperCaseGlobals::check_upper_case(cx, "associated constant", ii.name, ii.span);
|
||||||
|
@ -379,7 +389,7 @@ impl LateLintPass for NonUpperCaseGlobals {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_pat(&mut self, cx: &LateContext, p: &hir::Pat) {
|
fn check_pat<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, p: &'tcx hir::Pat) {
|
||||||
// Lint for constants that look like binding identifiers (#7526)
|
// Lint for constants that look like binding identifiers (#7526)
|
||||||
if let PatKind::Path(hir::QPath::Resolved(None, ref path)) = p.node {
|
if let PatKind::Path(hir::QPath::Resolved(None, ref path)) = p.node {
|
||||||
if !path.global && path.segments.len() == 1 && path.segments[0].parameters.is_empty() {
|
if !path.global && path.segments.len() == 1 && path.segments[0].parameters.is_empty() {
|
||||||
|
|
|
@ -70,7 +70,7 @@ impl LintPass for WhileTrue {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for WhileTrue {
|
impl LateLintPass for WhileTrue {
|
||||||
fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) {
|
fn check_expr<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx hir::Expr) {
|
||||||
if let hir::ExprWhile(ref cond, ..) = e.node {
|
if let hir::ExprWhile(ref cond, ..) = e.node {
|
||||||
if let hir::ExprLit(ref lit) = cond.node {
|
if let hir::ExprLit(ref lit) = cond.node {
|
||||||
if let ast::LitKind::Bool(true) = lit.node {
|
if let ast::LitKind::Bool(true) = lit.node {
|
||||||
|
@ -110,7 +110,7 @@ impl LintPass for BoxPointers {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for BoxPointers {
|
impl LateLintPass for BoxPointers {
|
||||||
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
|
fn check_item<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item) {
|
||||||
match it.node {
|
match it.node {
|
||||||
hir::ItemFn(..) |
|
hir::ItemFn(..) |
|
||||||
hir::ItemTy(..) |
|
hir::ItemTy(..) |
|
||||||
|
@ -137,7 +137,7 @@ impl LateLintPass for BoxPointers {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) {
|
fn check_expr<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx hir::Expr) {
|
||||||
let ty = cx.tcx.tables().node_id_to_type(e.id);
|
let ty = cx.tcx.tables().node_id_to_type(e.id);
|
||||||
self.check_heap_type(cx, e.span, ty);
|
self.check_heap_type(cx, e.span, ty);
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,7 @@ impl LintPass for NonShorthandFieldPatterns {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for NonShorthandFieldPatterns {
|
impl LateLintPass for NonShorthandFieldPatterns {
|
||||||
fn check_pat(&mut self, cx: &LateContext, pat: &hir::Pat) {
|
fn check_pat<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx hir::Pat) {
|
||||||
if let PatKind::Struct(_, ref field_pats, _) = pat.node {
|
if let PatKind::Struct(_, ref field_pats, _) = pat.node {
|
||||||
for fieldpat in field_pats {
|
for fieldpat in field_pats {
|
||||||
if fieldpat.node.is_shorthand {
|
if fieldpat.node.is_shorthand {
|
||||||
|
@ -195,7 +195,7 @@ impl LintPass for UnsafeCode {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for UnsafeCode {
|
impl LateLintPass for UnsafeCode {
|
||||||
fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) {
|
fn check_expr<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx hir::Expr) {
|
||||||
if let hir::ExprBlock(ref blk) = e.node {
|
if let hir::ExprBlock(ref blk) = e.node {
|
||||||
// Don't warn about generated blocks, that'll just pollute the output.
|
// Don't warn about generated blocks, that'll just pollute the output.
|
||||||
if blk.rules == hir::UnsafeBlock(hir::UserProvided) {
|
if blk.rules == hir::UnsafeBlock(hir::UserProvided) {
|
||||||
|
@ -204,7 +204,7 @@ impl LateLintPass for UnsafeCode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
|
fn check_item<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item) {
|
||||||
match it.node {
|
match it.node {
|
||||||
hir::ItemTrait(hir::Unsafety::Unsafe, ..) => {
|
hir::ItemTrait(hir::Unsafety::Unsafe, ..) => {
|
||||||
cx.span_lint(UNSAFE_CODE, it.span, "declaration of an `unsafe` trait")
|
cx.span_lint(UNSAFE_CODE, it.span, "declaration of an `unsafe` trait")
|
||||||
|
@ -218,13 +218,13 @@ impl LateLintPass for UnsafeCode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_fn(&mut self,
|
fn check_fn<'a, 'tcx: 'a>(&mut self,
|
||||||
cx: &LateContext,
|
cx: &LateContext<'a, 'tcx>,
|
||||||
fk: FnKind,
|
fk: FnKind<'tcx>,
|
||||||
_: &hir::FnDecl,
|
_: &'tcx hir::FnDecl,
|
||||||
_: &hir::Expr,
|
_: &'tcx hir::Expr,
|
||||||
span: Span,
|
span: Span,
|
||||||
_: ast::NodeId) {
|
_: ast::NodeId) {
|
||||||
match fk {
|
match fk {
|
||||||
FnKind::ItemFn(_, _, hir::Unsafety::Unsafe, ..) => {
|
FnKind::ItemFn(_, _, hir::Unsafety::Unsafe, ..) => {
|
||||||
cx.span_lint(UNSAFE_CODE, span, "declaration of an `unsafe` function")
|
cx.span_lint(UNSAFE_CODE, span, "declaration of an `unsafe` function")
|
||||||
|
@ -240,7 +240,9 @@ impl LateLintPass for UnsafeCode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_trait_item(&mut self, cx: &LateContext, trait_item: &hir::TraitItem) {
|
fn check_trait_item<'a, 'tcx: 'a>(&mut self,
|
||||||
|
cx: &LateContext<'a, 'tcx>,
|
||||||
|
trait_item: &'tcx hir::TraitItem) {
|
||||||
if let hir::MethodTraitItem(ref sig, None) = trait_item.node {
|
if let hir::MethodTraitItem(ref sig, None) = trait_item.node {
|
||||||
if sig.unsafety == hir::Unsafety::Unsafe {
|
if sig.unsafety == hir::Unsafety::Unsafe {
|
||||||
cx.span_lint(UNSAFE_CODE,
|
cx.span_lint(UNSAFE_CODE,
|
||||||
|
@ -328,7 +330,9 @@ impl LintPass for MissingDoc {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for MissingDoc {
|
impl LateLintPass for MissingDoc {
|
||||||
fn enter_lint_attrs(&mut self, _: &LateContext, attrs: &[ast::Attribute]) {
|
fn enter_lint_attrs<'a, 'tcx: 'a>(&mut self,
|
||||||
|
_: &LateContext<'a, 'tcx>,
|
||||||
|
attrs: &'tcx [ast::Attribute]) {
|
||||||
let doc_hidden = self.doc_hidden() ||
|
let doc_hidden = self.doc_hidden() ||
|
||||||
attrs.iter().any(|attr| {
|
attrs.iter().any(|attr| {
|
||||||
attr.check_name("doc") &&
|
attr.check_name("doc") &&
|
||||||
|
@ -340,34 +344,36 @@ impl LateLintPass for MissingDoc {
|
||||||
self.doc_hidden_stack.push(doc_hidden);
|
self.doc_hidden_stack.push(doc_hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exit_lint_attrs(&mut self, _: &LateContext, _: &[ast::Attribute]) {
|
fn exit_lint_attrs<'a, 'tcx: 'a>(&mut self,
|
||||||
|
_: &LateContext<'a, 'tcx>,
|
||||||
|
_attrs: &'tcx [ast::Attribute]) {
|
||||||
self.doc_hidden_stack.pop().expect("empty doc_hidden_stack");
|
self.doc_hidden_stack.pop().expect("empty doc_hidden_stack");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_struct_def(&mut self,
|
fn check_struct_def<'a, 'tcx: 'a>(&mut self,
|
||||||
_: &LateContext,
|
_: &LateContext<'a, 'tcx>,
|
||||||
_: &hir::VariantData,
|
_: &'tcx hir::VariantData,
|
||||||
_: ast::Name,
|
_: ast::Name,
|
||||||
_: &hir::Generics,
|
_: &'tcx hir::Generics,
|
||||||
item_id: ast::NodeId) {
|
item_id: ast::NodeId) {
|
||||||
self.struct_def_stack.push(item_id);
|
self.struct_def_stack.push(item_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_struct_def_post(&mut self,
|
fn check_struct_def_post<'a, 'tcx: 'a>(&mut self,
|
||||||
_: &LateContext,
|
_: &LateContext<'a, 'tcx>,
|
||||||
_: &hir::VariantData,
|
_: &'tcx hir::VariantData,
|
||||||
_: ast::Name,
|
_: ast::Name,
|
||||||
_: &hir::Generics,
|
_: &'tcx hir::Generics,
|
||||||
item_id: ast::NodeId) {
|
item_id: ast::NodeId) {
|
||||||
let popped = self.struct_def_stack.pop().expect("empty struct_def_stack");
|
let popped = self.struct_def_stack.pop().expect("empty struct_def_stack");
|
||||||
assert!(popped == item_id);
|
assert!(popped == item_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_crate(&mut self, cx: &LateContext, krate: &hir::Crate) {
|
fn check_crate<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, krate: &'tcx hir::Crate) {
|
||||||
self.check_missing_docs_attrs(cx, None, &krate.attrs, krate.span, "crate");
|
self.check_missing_docs_attrs(cx, None, &krate.attrs, krate.span, "crate");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
|
fn check_item<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item) {
|
||||||
let desc = match it.node {
|
let desc = match it.node {
|
||||||
hir::ItemFn(..) => "a function",
|
hir::ItemFn(..) => "a function",
|
||||||
hir::ItemMod(..) => "a module",
|
hir::ItemMod(..) => "a module",
|
||||||
|
@ -412,7 +418,9 @@ impl LateLintPass for MissingDoc {
|
||||||
self.check_missing_docs_attrs(cx, Some(it.id), &it.attrs, it.span, desc);
|
self.check_missing_docs_attrs(cx, Some(it.id), &it.attrs, it.span, desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_trait_item(&mut self, cx: &LateContext, trait_item: &hir::TraitItem) {
|
fn check_trait_item<'a, 'tcx: 'a>(&mut self,
|
||||||
|
cx: &LateContext<'a, 'tcx>,
|
||||||
|
trait_item: &'tcx hir::TraitItem) {
|
||||||
if self.private_traits.contains(&trait_item.id) {
|
if self.private_traits.contains(&trait_item.id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -430,7 +438,9 @@ impl LateLintPass for MissingDoc {
|
||||||
desc);
|
desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_impl_item(&mut self, cx: &LateContext, impl_item: &hir::ImplItem) {
|
fn check_impl_item<'a, 'tcx: 'a>(&mut self,
|
||||||
|
cx: &LateContext<'a, 'tcx>,
|
||||||
|
impl_item: &'tcx hir::ImplItem) {
|
||||||
// If the method is an impl for a trait, don't doc.
|
// If the method is an impl for a trait, don't doc.
|
||||||
if method_context(cx, impl_item.id, impl_item.span) == MethodLateContext::TraitImpl {
|
if method_context(cx, impl_item.id, impl_item.span) == MethodLateContext::TraitImpl {
|
||||||
return;
|
return;
|
||||||
|
@ -448,7 +458,9 @@ impl LateLintPass for MissingDoc {
|
||||||
desc);
|
desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_struct_field(&mut self, cx: &LateContext, sf: &hir::StructField) {
|
fn check_struct_field<'a, 'tcx: 'a>(&mut self,
|
||||||
|
cx: &LateContext<'a, 'tcx>,
|
||||||
|
sf: &'tcx hir::StructField) {
|
||||||
if !sf.is_positional() {
|
if !sf.is_positional() {
|
||||||
if sf.vis == hir::Public || self.in_variant {
|
if sf.vis == hir::Public || self.in_variant {
|
||||||
let cur_struct_def = *self.struct_def_stack
|
let cur_struct_def = *self.struct_def_stack
|
||||||
|
@ -463,7 +475,10 @@ impl LateLintPass for MissingDoc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_variant(&mut self, cx: &LateContext, v: &hir::Variant, _: &hir::Generics) {
|
fn check_variant<'a, 'tcx: 'a>(&mut self,
|
||||||
|
cx: &LateContext<'a, 'tcx>,
|
||||||
|
v: &'tcx hir::Variant,
|
||||||
|
_: &'tcx hir::Generics) {
|
||||||
self.check_missing_docs_attrs(cx,
|
self.check_missing_docs_attrs(cx,
|
||||||
Some(v.node.data.id()),
|
Some(v.node.data.id()),
|
||||||
&v.node.attrs,
|
&v.node.attrs,
|
||||||
|
@ -473,7 +488,10 @@ impl LateLintPass for MissingDoc {
|
||||||
self.in_variant = true;
|
self.in_variant = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_variant_post(&mut self, _: &LateContext, _: &hir::Variant, _: &hir::Generics) {
|
fn check_variant_post<'a, 'tcx: 'a>(&mut self,
|
||||||
|
_: &LateContext<'a, 'tcx>,
|
||||||
|
_: &'tcx hir::Variant,
|
||||||
|
_: &'tcx hir::Generics) {
|
||||||
assert!(self.in_variant);
|
assert!(self.in_variant);
|
||||||
self.in_variant = false;
|
self.in_variant = false;
|
||||||
}
|
}
|
||||||
|
@ -495,7 +513,7 @@ impl LintPass for MissingCopyImplementations {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for MissingCopyImplementations {
|
impl LateLintPass for MissingCopyImplementations {
|
||||||
fn check_item(&mut self, cx: &LateContext, item: &hir::Item) {
|
fn check_item<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) {
|
||||||
if !cx.access_levels.is_reachable(item.id) {
|
if !cx.access_levels.is_reachable(item.id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -564,7 +582,7 @@ impl LintPass for MissingDebugImplementations {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for MissingDebugImplementations {
|
impl LateLintPass for MissingDebugImplementations {
|
||||||
fn check_item(&mut self, cx: &LateContext, item: &hir::Item) {
|
fn check_item<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) {
|
||||||
if !cx.access_levels.is_reachable(item.id) {
|
if !cx.access_levels.is_reachable(item.id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -670,13 +688,13 @@ impl LintPass for UnconditionalRecursion {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for UnconditionalRecursion {
|
impl LateLintPass for UnconditionalRecursion {
|
||||||
fn check_fn(&mut self,
|
fn check_fn<'a, 'tcx: 'a>(&mut self,
|
||||||
cx: &LateContext,
|
cx: &LateContext<'a, 'tcx>,
|
||||||
fn_kind: FnKind,
|
fn_kind: FnKind<'tcx>,
|
||||||
_: &hir::FnDecl,
|
_: &'tcx hir::FnDecl,
|
||||||
blk: &hir::Expr,
|
blk: &'tcx hir::Expr,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
id: ast::NodeId) {
|
id: ast::NodeId) {
|
||||||
let method = match fn_kind {
|
let method = match fn_kind {
|
||||||
FnKind::ItemFn(..) => None,
|
FnKind::ItemFn(..) => None,
|
||||||
FnKind::Method(..) => {
|
FnKind::Method(..) => {
|
||||||
|
@ -933,7 +951,7 @@ impl LintPass for PluginAsLibrary {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for PluginAsLibrary {
|
impl LateLintPass for PluginAsLibrary {
|
||||||
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
|
fn check_item<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item) {
|
||||||
if cx.sess().plugin_registrar_fn.get().is_some() {
|
if cx.sess().plugin_registrar_fn.get().is_some() {
|
||||||
// We're compiling a plugin; it's fine to link other plugins.
|
// We're compiling a plugin; it's fine to link other plugins.
|
||||||
return;
|
return;
|
||||||
|
@ -999,7 +1017,7 @@ impl LintPass for InvalidNoMangleItems {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for InvalidNoMangleItems {
|
impl LateLintPass for InvalidNoMangleItems {
|
||||||
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
|
fn check_item<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item) {
|
||||||
match it.node {
|
match it.node {
|
||||||
hir::ItemFn(.., ref generics, _) => {
|
hir::ItemFn(.., ref generics, _) => {
|
||||||
if attr::contains_name(&it.attrs, "no_mangle") {
|
if attr::contains_name(&it.attrs, "no_mangle") {
|
||||||
|
@ -1053,7 +1071,7 @@ impl LintPass for MutableTransmutes {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for MutableTransmutes {
|
impl LateLintPass for MutableTransmutes {
|
||||||
fn check_expr(&mut self, cx: &LateContext, expr: &hir::Expr) {
|
fn check_expr<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
|
||||||
use syntax::abi::Abi::RustIntrinsic;
|
use syntax::abi::Abi::RustIntrinsic;
|
||||||
|
|
||||||
let msg = "mutating transmuted &mut T from &T may cause undefined behavior, \
|
let msg = "mutating transmuted &mut T from &T may cause undefined behavior, \
|
||||||
|
@ -1121,7 +1139,9 @@ impl LintPass for UnstableFeatures {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for UnstableFeatures {
|
impl LateLintPass for UnstableFeatures {
|
||||||
fn check_attribute(&mut self, ctx: &LateContext, attr: &ast::Attribute) {
|
fn check_attribute<'a, 'tcx: 'a>(&mut self,
|
||||||
|
ctx: &LateContext<'a, 'tcx>,
|
||||||
|
attr: &'tcx ast::Attribute) {
|
||||||
if attr.meta().check_name("feature") {
|
if attr.meta().check_name("feature") {
|
||||||
if let Some(items) = attr.meta().meta_item_list() {
|
if let Some(items) = attr.meta().meta_item_list() {
|
||||||
for item in items {
|
for item in items {
|
||||||
|
@ -1148,7 +1168,7 @@ impl LintPass for UnionsWithDropFields {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for UnionsWithDropFields {
|
impl LateLintPass for UnionsWithDropFields {
|
||||||
fn check_item(&mut self, ctx: &LateContext, item: &hir::Item) {
|
fn check_item<'a, 'tcx: 'a>(&mut self, ctx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) {
|
||||||
if let hir::ItemUnion(ref vdata, _) = item.node {
|
if let hir::ItemUnion(ref vdata, _) = item.node {
|
||||||
let param_env = &ty::ParameterEnvironment::for_item(ctx.tcx, item.id);
|
let param_env = &ty::ParameterEnvironment::for_item(ctx.tcx, item.id);
|
||||||
for field in vdata.fields() {
|
for field in vdata.fields() {
|
||||||
|
|
|
@ -104,7 +104,7 @@ impl LintPass for TypeLimits {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for TypeLimits {
|
impl LateLintPass for TypeLimits {
|
||||||
fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) {
|
fn check_expr<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx hir::Expr) {
|
||||||
match e.node {
|
match e.node {
|
||||||
hir::ExprUnary(hir::UnNeg, ref expr) => {
|
hir::ExprUnary(hir::UnNeg, ref expr) => {
|
||||||
if let hir::ExprLit(ref lit) = expr.node {
|
if let hir::ExprLit(ref lit) = expr.node {
|
||||||
|
@ -707,7 +707,7 @@ impl LintPass for ImproperCTypes {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for ImproperCTypes {
|
impl LateLintPass for ImproperCTypes {
|
||||||
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
|
fn check_item<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item) {
|
||||||
let mut vis = ImproperCTypesVisitor { cx: cx };
|
let mut vis = ImproperCTypesVisitor { cx: cx };
|
||||||
if let hir::ItemForeignMod(ref nmod) = it.node {
|
if let hir::ItemForeignMod(ref nmod) = it.node {
|
||||||
if nmod.abi != Abi::RustIntrinsic && nmod.abi != Abi::PlatformIntrinsic {
|
if nmod.abi != Abi::RustIntrinsic && nmod.abi != Abi::PlatformIntrinsic {
|
||||||
|
@ -735,7 +735,7 @@ impl LintPass for VariantSizeDifferences {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for VariantSizeDifferences {
|
impl LateLintPass for VariantSizeDifferences {
|
||||||
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
|
fn check_item<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item) {
|
||||||
if let hir::ItemEnum(ref enum_definition, ref gens) = it.node {
|
if let hir::ItemEnum(ref enum_definition, ref gens) = it.node {
|
||||||
if gens.ty_params.is_empty() {
|
if gens.ty_params.is_empty() {
|
||||||
// sizes only make sense for non-generic types
|
// sizes only make sense for non-generic types
|
||||||
|
|
|
@ -78,7 +78,7 @@ impl LintPass for UnusedMut {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for UnusedMut {
|
impl LateLintPass for UnusedMut {
|
||||||
fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) {
|
fn check_expr<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx hir::Expr) {
|
||||||
if let hir::ExprMatch(_, ref arms, _) = e.node {
|
if let hir::ExprMatch(_, ref arms, _) = e.node {
|
||||||
for a in arms {
|
for a in arms {
|
||||||
self.check_unused_mut_pat(cx, &a.pats)
|
self.check_unused_mut_pat(cx, &a.pats)
|
||||||
|
@ -86,7 +86,7 @@ impl LateLintPass for UnusedMut {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_stmt(&mut self, cx: &LateContext, s: &hir::Stmt) {
|
fn check_stmt<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, s: &'tcx hir::Stmt) {
|
||||||
if let hir::StmtDecl(ref d, _) = s.node {
|
if let hir::StmtDecl(ref d, _) = s.node {
|
||||||
if let hir::DeclLocal(ref l) = d.node {
|
if let hir::DeclLocal(ref l) = d.node {
|
||||||
self.check_unused_mut_pat(cx, slice::ref_slice(&l.pat));
|
self.check_unused_mut_pat(cx, slice::ref_slice(&l.pat));
|
||||||
|
@ -94,13 +94,13 @@ impl LateLintPass for UnusedMut {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_fn(&mut self,
|
fn check_fn<'a, 'tcx: 'a>(&mut self,
|
||||||
cx: &LateContext,
|
cx: &LateContext<'a, 'tcx>,
|
||||||
_: FnKind,
|
_: FnKind<'tcx>,
|
||||||
decl: &hir::FnDecl,
|
decl: &'tcx hir::FnDecl,
|
||||||
_: &hir::Expr,
|
_: &'tcx hir::Expr,
|
||||||
_: Span,
|
_: Span,
|
||||||
_: ast::NodeId) {
|
_: ast::NodeId) {
|
||||||
for a in &decl.inputs {
|
for a in &decl.inputs {
|
||||||
self.check_unused_mut_pat(cx, slice::ref_slice(&a.pat));
|
self.check_unused_mut_pat(cx, slice::ref_slice(&a.pat));
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ impl LintPass for UnusedResults {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for UnusedResults {
|
impl LateLintPass for UnusedResults {
|
||||||
fn check_stmt(&mut self, cx: &LateContext, s: &hir::Stmt) {
|
fn check_stmt<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, s: &'tcx hir::Stmt) {
|
||||||
let expr = match s.node {
|
let expr = match s.node {
|
||||||
hir::StmtSemi(ref expr, _) => &**expr,
|
hir::StmtSemi(ref expr, _) => &**expr,
|
||||||
_ => return,
|
_ => return,
|
||||||
|
@ -188,7 +188,7 @@ impl LintPass for UnusedUnsafe {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for UnusedUnsafe {
|
impl LateLintPass for UnusedUnsafe {
|
||||||
fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) {
|
fn check_expr<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx hir::Expr) {
|
||||||
if let hir::ExprBlock(ref blk) = e.node {
|
if let hir::ExprBlock(ref blk) = e.node {
|
||||||
// Don't warn about generated blocks, that'll just pollute the output.
|
// Don't warn about generated blocks, that'll just pollute the output.
|
||||||
if blk.rules == hir::UnsafeBlock(hir::UserProvided) &&
|
if blk.rules == hir::UnsafeBlock(hir::UserProvided) &&
|
||||||
|
@ -215,7 +215,7 @@ impl LintPass for PathStatements {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for PathStatements {
|
impl LateLintPass for PathStatements {
|
||||||
fn check_stmt(&mut self, cx: &LateContext, s: &hir::Stmt) {
|
fn check_stmt<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, s: &'tcx hir::Stmt) {
|
||||||
if let hir::StmtSemi(ref expr, _) = s.node {
|
if let hir::StmtSemi(ref expr, _) = s.node {
|
||||||
if let hir::ExprPath(_) = expr.node {
|
if let hir::ExprPath(_) = expr.node {
|
||||||
cx.span_lint(PATH_STATEMENTS, s.span, "path statement with no effect");
|
cx.span_lint(PATH_STATEMENTS, s.span, "path statement with no effect");
|
||||||
|
@ -240,7 +240,9 @@ impl LintPass for UnusedAttributes {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for UnusedAttributes {
|
impl LateLintPass for UnusedAttributes {
|
||||||
fn check_attribute(&mut self, cx: &LateContext, attr: &ast::Attribute) {
|
fn check_attribute<'a, 'tcx: 'a>(&mut self,
|
||||||
|
cx: &LateContext<'a, 'tcx>,
|
||||||
|
attr: &'tcx ast::Attribute) {
|
||||||
debug!("checking attribute: {:?}", attr);
|
debug!("checking attribute: {:?}", attr);
|
||||||
|
|
||||||
// Note that check_name() marks the attribute as used if it matches.
|
// Note that check_name() marks the attribute as used if it matches.
|
||||||
|
@ -434,7 +436,7 @@ impl LintPass for UnusedAllocation {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for UnusedAllocation {
|
impl LateLintPass for UnusedAllocation {
|
||||||
fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) {
|
fn check_expr<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx hir::Expr) {
|
||||||
match e.node {
|
match e.node {
|
||||||
hir::ExprBox(_) => {}
|
hir::ExprBox(_) => {}
|
||||||
_ => return,
|
_ => return,
|
||||||
|
|
|
@ -101,8 +101,8 @@ impl<'a> AstValidator<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Visitor for AstValidator<'a> {
|
impl<'a> Visitor<'a> for AstValidator<'a> {
|
||||||
fn visit_lifetime(&mut self, lt: &Lifetime) {
|
fn visit_lifetime(&mut self, lt: &'a Lifetime) {
|
||||||
if lt.name == "'_" {
|
if lt.name == "'_" {
|
||||||
self.session.add_lint(lint::builtin::LIFETIME_UNDERSCORE,
|
self.session.add_lint(lint::builtin::LIFETIME_UNDERSCORE,
|
||||||
lt.id,
|
lt.id,
|
||||||
|
@ -113,7 +113,7 @@ impl<'a> Visitor for AstValidator<'a> {
|
||||||
visit::walk_lifetime(self, lt)
|
visit::walk_lifetime(self, lt)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_expr(&mut self, expr: &Expr) {
|
fn visit_expr(&mut self, expr: &'a Expr) {
|
||||||
match expr.node {
|
match expr.node {
|
||||||
ExprKind::While(.., Some(ident)) |
|
ExprKind::While(.., Some(ident)) |
|
||||||
ExprKind::Loop(_, Some(ident)) |
|
ExprKind::Loop(_, Some(ident)) |
|
||||||
|
@ -129,7 +129,7 @@ impl<'a> Visitor for AstValidator<'a> {
|
||||||
visit::walk_expr(self, expr)
|
visit::walk_expr(self, expr)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_ty(&mut self, ty: &Ty) {
|
fn visit_ty(&mut self, ty: &'a Ty) {
|
||||||
match ty.node {
|
match ty.node {
|
||||||
TyKind::BareFn(ref bfty) => {
|
TyKind::BareFn(ref bfty) => {
|
||||||
self.check_decl_no_pat(&bfty.decl, |span, _| {
|
self.check_decl_no_pat(&bfty.decl, |span, _| {
|
||||||
|
@ -153,7 +153,7 @@ impl<'a> Visitor for AstValidator<'a> {
|
||||||
visit::walk_ty(self, ty)
|
visit::walk_ty(self, ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_path(&mut self, path: &Path, id: NodeId) {
|
fn visit_path(&mut self, path: &'a Path, id: NodeId) {
|
||||||
if path.global && path.segments.len() > 0 {
|
if path.global && path.segments.len() > 0 {
|
||||||
let ident = path.segments[0].identifier;
|
let ident = path.segments[0].identifier;
|
||||||
if token::Ident(ident).is_path_segment_keyword() {
|
if token::Ident(ident).is_path_segment_keyword() {
|
||||||
|
@ -167,7 +167,7 @@ impl<'a> Visitor for AstValidator<'a> {
|
||||||
visit::walk_path(self, path)
|
visit::walk_path(self, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_item(&mut self, item: &Item) {
|
fn visit_item(&mut self, item: &'a Item) {
|
||||||
match item.node {
|
match item.node {
|
||||||
ItemKind::Use(ref view_path) => {
|
ItemKind::Use(ref view_path) => {
|
||||||
let path = view_path.node.path();
|
let path = view_path.node.path();
|
||||||
|
@ -249,7 +249,7 @@ impl<'a> Visitor for AstValidator<'a> {
|
||||||
visit::walk_item(self, item)
|
visit::walk_item(self, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_foreign_item(&mut self, fi: &ForeignItem) {
|
fn visit_foreign_item(&mut self, fi: &'a ForeignItem) {
|
||||||
match fi.node {
|
match fi.node {
|
||||||
ForeignItemKind::Fn(ref decl, _) => {
|
ForeignItemKind::Fn(ref decl, _) => {
|
||||||
self.check_decl_no_pat(decl, |span, is_recent| {
|
self.check_decl_no_pat(decl, |span, is_recent| {
|
||||||
|
@ -272,7 +272,7 @@ impl<'a> Visitor for AstValidator<'a> {
|
||||||
visit::walk_foreign_item(self, fi)
|
visit::walk_foreign_item(self, fi)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_vis(&mut self, vis: &Visibility) {
|
fn visit_vis(&mut self, vis: &'a Visibility) {
|
||||||
match *vis {
|
match *vis {
|
||||||
Visibility::Restricted { ref path, .. } => {
|
Visibility::Restricted { ref path, .. } => {
|
||||||
if !path.segments.iter().all(|segment| segment.parameters.is_empty()) {
|
if !path.segments.iter().all(|segment| segment.parameters.is_empty()) {
|
||||||
|
|
|
@ -48,7 +48,7 @@ pub fn print_hir_stats(krate: &hir::Crate) {
|
||||||
collector.print("HIR STATS");
|
collector.print("HIR STATS");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_ast_stats(krate: &ast::Crate, title: &str) {
|
pub fn print_ast_stats<'v>(krate: &'v ast::Crate, title: &str) {
|
||||||
let mut collector = StatCollector {
|
let mut collector = StatCollector {
|
||||||
krate: None,
|
krate: None,
|
||||||
data: FxHashMap(),
|
data: FxHashMap(),
|
||||||
|
@ -245,133 +245,133 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'v> ast_visit::Visitor for StatCollector<'v> {
|
impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
|
||||||
|
|
||||||
fn visit_mod(&mut self, m: &ast::Mod, _s: Span, _n: NodeId) {
|
fn visit_mod(&mut self, m: &'v ast::Mod, _s: Span, _n: NodeId) {
|
||||||
self.record("Mod", Id::None, m);
|
self.record("Mod", Id::None, m);
|
||||||
ast_visit::walk_mod(self, m)
|
ast_visit::walk_mod(self, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_foreign_item(&mut self, i: &ast::ForeignItem) {
|
fn visit_foreign_item(&mut self, i: &'v ast::ForeignItem) {
|
||||||
self.record("ForeignItem", Id::None, i);
|
self.record("ForeignItem", Id::None, i);
|
||||||
ast_visit::walk_foreign_item(self, i)
|
ast_visit::walk_foreign_item(self, i)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_item(&mut self, i: &ast::Item) {
|
fn visit_item(&mut self, i: &'v ast::Item) {
|
||||||
self.record("Item", Id::None, i);
|
self.record("Item", Id::None, i);
|
||||||
ast_visit::walk_item(self, i)
|
ast_visit::walk_item(self, i)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_local(&mut self, l: &ast::Local) {
|
fn visit_local(&mut self, l: &'v ast::Local) {
|
||||||
self.record("Local", Id::None, l);
|
self.record("Local", Id::None, l);
|
||||||
ast_visit::walk_local(self, l)
|
ast_visit::walk_local(self, l)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_block(&mut self, b: &ast::Block) {
|
fn visit_block(&mut self, b: &'v ast::Block) {
|
||||||
self.record("Block", Id::None, b);
|
self.record("Block", Id::None, b);
|
||||||
ast_visit::walk_block(self, b)
|
ast_visit::walk_block(self, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_stmt(&mut self, s: &ast::Stmt) {
|
fn visit_stmt(&mut self, s: &'v ast::Stmt) {
|
||||||
self.record("Stmt", Id::None, s);
|
self.record("Stmt", Id::None, s);
|
||||||
ast_visit::walk_stmt(self, s)
|
ast_visit::walk_stmt(self, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_arm(&mut self, a: &ast::Arm) {
|
fn visit_arm(&mut self, a: &'v ast::Arm) {
|
||||||
self.record("Arm", Id::None, a);
|
self.record("Arm", Id::None, a);
|
||||||
ast_visit::walk_arm(self, a)
|
ast_visit::walk_arm(self, a)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_pat(&mut self, p: &ast::Pat) {
|
fn visit_pat(&mut self, p: &'v ast::Pat) {
|
||||||
self.record("Pat", Id::None, p);
|
self.record("Pat", Id::None, p);
|
||||||
ast_visit::walk_pat(self, p)
|
ast_visit::walk_pat(self, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_expr(&mut self, ex: &ast::Expr) {
|
fn visit_expr(&mut self, ex: &'v ast::Expr) {
|
||||||
self.record("Expr", Id::None, ex);
|
self.record("Expr", Id::None, ex);
|
||||||
ast_visit::walk_expr(self, ex)
|
ast_visit::walk_expr(self, ex)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_ty(&mut self, t: &ast::Ty) {
|
fn visit_ty(&mut self, t: &'v ast::Ty) {
|
||||||
self.record("Ty", Id::None, t);
|
self.record("Ty", Id::None, t);
|
||||||
ast_visit::walk_ty(self, t)
|
ast_visit::walk_ty(self, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_fn(&mut self,
|
fn visit_fn(&mut self,
|
||||||
fk: ast_visit::FnKind,
|
fk: ast_visit::FnKind<'v>,
|
||||||
fd: &ast::FnDecl,
|
fd: &'v ast::FnDecl,
|
||||||
s: Span,
|
s: Span,
|
||||||
_: NodeId) {
|
_: NodeId) {
|
||||||
self.record("FnDecl", Id::None, fd);
|
self.record("FnDecl", Id::None, fd);
|
||||||
ast_visit::walk_fn(self, fk, fd, s)
|
ast_visit::walk_fn(self, fk, fd, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_trait_item(&mut self, ti: &ast::TraitItem) {
|
fn visit_trait_item(&mut self, ti: &'v ast::TraitItem) {
|
||||||
self.record("TraitItem", Id::None, ti);
|
self.record("TraitItem", Id::None, ti);
|
||||||
ast_visit::walk_trait_item(self, ti)
|
ast_visit::walk_trait_item(self, ti)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_impl_item(&mut self, ii: &ast::ImplItem) {
|
fn visit_impl_item(&mut self, ii: &'v ast::ImplItem) {
|
||||||
self.record("ImplItem", Id::None, ii);
|
self.record("ImplItem", Id::None, ii);
|
||||||
ast_visit::walk_impl_item(self, ii)
|
ast_visit::walk_impl_item(self, ii)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_ty_param_bound(&mut self, bounds: &ast::TyParamBound) {
|
fn visit_ty_param_bound(&mut self, bounds: &'v ast::TyParamBound) {
|
||||||
self.record("TyParamBound", Id::None, bounds);
|
self.record("TyParamBound", Id::None, bounds);
|
||||||
ast_visit::walk_ty_param_bound(self, bounds)
|
ast_visit::walk_ty_param_bound(self, bounds)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_struct_field(&mut self, s: &ast::StructField) {
|
fn visit_struct_field(&mut self, s: &'v ast::StructField) {
|
||||||
self.record("StructField", Id::None, s);
|
self.record("StructField", Id::None, s);
|
||||||
ast_visit::walk_struct_field(self, s)
|
ast_visit::walk_struct_field(self, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_variant(&mut self,
|
fn visit_variant(&mut self,
|
||||||
v: &ast::Variant,
|
v: &'v ast::Variant,
|
||||||
g: &ast::Generics,
|
g: &'v ast::Generics,
|
||||||
item_id: NodeId) {
|
item_id: NodeId) {
|
||||||
self.record("Variant", Id::None, v);
|
self.record("Variant", Id::None, v);
|
||||||
ast_visit::walk_variant(self, v, g, item_id)
|
ast_visit::walk_variant(self, v, g, item_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_lifetime(&mut self, lifetime: &ast::Lifetime) {
|
fn visit_lifetime(&mut self, lifetime: &'v ast::Lifetime) {
|
||||||
self.record("Lifetime", Id::None, lifetime);
|
self.record("Lifetime", Id::None, lifetime);
|
||||||
ast_visit::walk_lifetime(self, lifetime)
|
ast_visit::walk_lifetime(self, lifetime)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_lifetime_def(&mut self, lifetime: &ast::LifetimeDef) {
|
fn visit_lifetime_def(&mut self, lifetime: &'v ast::LifetimeDef) {
|
||||||
self.record("LifetimeDef", Id::None, lifetime);
|
self.record("LifetimeDef", Id::None, lifetime);
|
||||||
ast_visit::walk_lifetime_def(self, lifetime)
|
ast_visit::walk_lifetime_def(self, lifetime)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_mac(&mut self, mac: &ast::Mac) {
|
fn visit_mac(&mut self, mac: &'v ast::Mac) {
|
||||||
self.record("Mac", Id::None, mac);
|
self.record("Mac", Id::None, mac);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_path_list_item(&mut self,
|
fn visit_path_list_item(&mut self,
|
||||||
prefix: &ast::Path,
|
prefix: &'v ast::Path,
|
||||||
item: &ast::PathListItem) {
|
item: &'v ast::PathListItem) {
|
||||||
self.record("PathListItem", Id::None, item);
|
self.record("PathListItem", Id::None, item);
|
||||||
ast_visit::walk_path_list_item(self, prefix, item)
|
ast_visit::walk_path_list_item(self, prefix, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_path_segment(&mut self,
|
fn visit_path_segment(&mut self,
|
||||||
path_span: Span,
|
path_span: Span,
|
||||||
path_segment: &ast::PathSegment) {
|
path_segment: &'v ast::PathSegment) {
|
||||||
self.record("PathSegment", Id::None, path_segment);
|
self.record("PathSegment", Id::None, path_segment);
|
||||||
ast_visit::walk_path_segment(self, path_span, path_segment)
|
ast_visit::walk_path_segment(self, path_span, path_segment)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_assoc_type_binding(&mut self, type_binding: &ast::TypeBinding) {
|
fn visit_assoc_type_binding(&mut self, type_binding: &'v ast::TypeBinding) {
|
||||||
self.record("TypeBinding", Id::None, type_binding);
|
self.record("TypeBinding", Id::None, type_binding);
|
||||||
ast_visit::walk_assoc_type_binding(self, type_binding)
|
ast_visit::walk_assoc_type_binding(self, type_binding)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_attribute(&mut self, attr: &ast::Attribute) {
|
fn visit_attribute(&mut self, attr: &'v ast::Attribute) {
|
||||||
self.record("Attribute", Id::None, attr);
|
self.record("Attribute", Id::None, attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_macro_def(&mut self, macro_def: &ast::MacroDef) {
|
fn visit_macro_def(&mut self, macro_def: &'v ast::MacroDef) {
|
||||||
self.record("MacroDef", Id::None, macro_def);
|
self.record("MacroDef", Id::None, macro_def);
|
||||||
ast_visit::walk_macro_def(self, macro_def)
|
ast_visit::walk_macro_def(self, macro_def)
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,8 +31,8 @@ struct CheckNoAsm<'a> {
|
||||||
sess: &'a Session,
|
sess: &'a Session,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Visitor for CheckNoAsm<'a> {
|
impl<'a> Visitor<'a> for CheckNoAsm<'a> {
|
||||||
fn visit_expr(&mut self, e: &ast::Expr) {
|
fn visit_expr(&mut self, e: &'a ast::Expr) {
|
||||||
match e.node {
|
match e.node {
|
||||||
ast::ExprKind::InlineAsm(_) => {
|
ast::ExprKind::InlineAsm(_) => {
|
||||||
span_err!(self.sess,
|
span_err!(self.sess,
|
||||||
|
|
|
@ -678,7 +678,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
||||||
|
|
||||||
macro_rules! method {
|
macro_rules! method {
|
||||||
($visit:ident: $ty:ty, $invoc:path, $walk:ident) => {
|
($visit:ident: $ty:ty, $invoc:path, $walk:ident) => {
|
||||||
fn $visit(&mut self, node: &$ty) {
|
fn $visit(&mut self, node: &'a $ty) {
|
||||||
if let $invoc(..) = node.node {
|
if let $invoc(..) = node.node {
|
||||||
self.visit_invoc(node.id);
|
self.visit_invoc(node.id);
|
||||||
} else {
|
} else {
|
||||||
|
@ -688,13 +688,13 @@ macro_rules! method {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b> Visitor for BuildReducedGraphVisitor<'a, 'b> {
|
impl<'a, 'b> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b> {
|
||||||
method!(visit_impl_item: ast::ImplItem, ast::ImplItemKind::Macro, walk_impl_item);
|
method!(visit_impl_item: ast::ImplItem, ast::ImplItemKind::Macro, walk_impl_item);
|
||||||
method!(visit_expr: ast::Expr, ast::ExprKind::Mac, walk_expr);
|
method!(visit_expr: ast::Expr, ast::ExprKind::Mac, walk_expr);
|
||||||
method!(visit_pat: ast::Pat, ast::PatKind::Mac, walk_pat);
|
method!(visit_pat: ast::Pat, ast::PatKind::Mac, walk_pat);
|
||||||
method!(visit_ty: ast::Ty, ast::TyKind::Mac, walk_ty);
|
method!(visit_ty: ast::Ty, ast::TyKind::Mac, walk_ty);
|
||||||
|
|
||||||
fn visit_item(&mut self, item: &Item) {
|
fn visit_item(&mut self, item: &'a Item) {
|
||||||
let macro_use = match item.node {
|
let macro_use = match item.node {
|
||||||
ItemKind::Mac(..) if item.id == ast::DUMMY_NODE_ID => return, // Scope placeholder
|
ItemKind::Mac(..) if item.id == ast::DUMMY_NODE_ID => return, // Scope placeholder
|
||||||
ItemKind::Mac(..) => {
|
ItemKind::Mac(..) => {
|
||||||
|
@ -713,7 +713,7 @@ impl<'a, 'b> Visitor for BuildReducedGraphVisitor<'a, 'b> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_stmt(&mut self, stmt: &ast::Stmt) {
|
fn visit_stmt(&mut self, stmt: &'a ast::Stmt) {
|
||||||
if let ast::StmtKind::Mac(..) = stmt.node {
|
if let ast::StmtKind::Mac(..) = stmt.node {
|
||||||
self.legacy_scope = LegacyScope::Expansion(self.visit_invoc(stmt.id));
|
self.legacy_scope = LegacyScope::Expansion(self.visit_invoc(stmt.id));
|
||||||
} else {
|
} else {
|
||||||
|
@ -721,12 +721,12 @@ impl<'a, 'b> Visitor for BuildReducedGraphVisitor<'a, 'b> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_foreign_item(&mut self, foreign_item: &ForeignItem) {
|
fn visit_foreign_item(&mut self, foreign_item: &'a ForeignItem) {
|
||||||
self.resolver.build_reduced_graph_for_foreign_item(foreign_item, self.expansion);
|
self.resolver.build_reduced_graph_for_foreign_item(foreign_item, self.expansion);
|
||||||
visit::walk_foreign_item(self, foreign_item);
|
visit::walk_foreign_item(self, foreign_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_block(&mut self, block: &Block) {
|
fn visit_block(&mut self, block: &'a Block) {
|
||||||
let (parent, legacy_scope) = (self.resolver.current_module, self.legacy_scope);
|
let (parent, legacy_scope) = (self.resolver.current_module, self.legacy_scope);
|
||||||
self.resolver.build_reduced_graph_for_block(block);
|
self.resolver.build_reduced_graph_for_block(block);
|
||||||
visit::walk_block(self, block);
|
visit::walk_block(self, block);
|
||||||
|
@ -734,7 +734,7 @@ impl<'a, 'b> Visitor for BuildReducedGraphVisitor<'a, 'b> {
|
||||||
self.legacy_scope = legacy_scope;
|
self.legacy_scope = legacy_scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_trait_item(&mut self, item: &TraitItem) {
|
fn visit_trait_item(&mut self, item: &'a TraitItem) {
|
||||||
let parent = self.resolver.current_module;
|
let parent = self.resolver.current_module;
|
||||||
let def_id = parent.def_id().unwrap();
|
let def_id = parent.def_id().unwrap();
|
||||||
|
|
||||||
|
|
|
@ -74,8 +74,8 @@ impl<'a, 'b> UnusedImportCheckVisitor<'a, 'b> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b> Visitor for UnusedImportCheckVisitor<'a, 'b> {
|
impl<'a, 'b> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b> {
|
||||||
fn visit_item(&mut self, item: &ast::Item) {
|
fn visit_item(&mut self, item: &'a ast::Item) {
|
||||||
visit::walk_item(self, item);
|
visit::walk_item(self, item);
|
||||||
// Ignore is_public import statements because there's no way to be sure
|
// Ignore is_public import statements because there's no way to be sure
|
||||||
// whether they're used or not. Also ignore imports with a dummy span
|
// whether they're used or not. Also ignore imports with a dummy span
|
||||||
|
|
|
@ -557,26 +557,28 @@ impl<T> ::std::ops::IndexMut<Namespace> for PerNS<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Visitor for Resolver<'a> {
|
impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> {
|
||||||
fn visit_item(&mut self, item: &Item) {
|
fn visit_item(&mut self, item: &'tcx Item) {
|
||||||
self.resolve_item(item);
|
self.resolve_item(item);
|
||||||
}
|
}
|
||||||
fn visit_arm(&mut self, arm: &Arm) {
|
fn visit_arm(&mut self, arm: &'tcx Arm) {
|
||||||
self.resolve_arm(arm);
|
self.resolve_arm(arm);
|
||||||
}
|
}
|
||||||
fn visit_block(&mut self, block: &Block) {
|
fn visit_block(&mut self, block: &'tcx Block) {
|
||||||
self.resolve_block(block);
|
self.resolve_block(block);
|
||||||
}
|
}
|
||||||
fn visit_expr(&mut self, expr: &Expr) {
|
fn visit_expr(&mut self, expr: &'tcx Expr) {
|
||||||
self.resolve_expr(expr, None);
|
self.resolve_expr(expr, None);
|
||||||
}
|
}
|
||||||
fn visit_local(&mut self, local: &Local) {
|
fn visit_local(&mut self, local: &'tcx Local) {
|
||||||
self.resolve_local(local);
|
self.resolve_local(local);
|
||||||
}
|
}
|
||||||
fn visit_ty(&mut self, ty: &Ty) {
|
fn visit_ty(&mut self, ty: &'tcx Ty) {
|
||||||
self.resolve_type(ty);
|
self.resolve_type(ty);
|
||||||
}
|
}
|
||||||
fn visit_poly_trait_ref(&mut self, tref: &ast::PolyTraitRef, m: &ast::TraitBoundModifier) {
|
fn visit_poly_trait_ref(&mut self,
|
||||||
|
tref: &'tcx ast::PolyTraitRef,
|
||||||
|
m: &'tcx ast::TraitBoundModifier) {
|
||||||
let ast::Path { ref segments, span, global } = tref.trait_ref.path;
|
let ast::Path { ref segments, span, global } = tref.trait_ref.path;
|
||||||
let path: Vec<_> = segments.iter().map(|seg| seg.identifier).collect();
|
let path: Vec<_> = segments.iter().map(|seg| seg.identifier).collect();
|
||||||
let def = self.resolve_trait_reference(&path, global, None, span);
|
let def = self.resolve_trait_reference(&path, global, None, span);
|
||||||
|
@ -584,8 +586,8 @@ impl<'a> Visitor for Resolver<'a> {
|
||||||
visit::walk_poly_trait_ref(self, tref, m);
|
visit::walk_poly_trait_ref(self, tref, m);
|
||||||
}
|
}
|
||||||
fn visit_variant(&mut self,
|
fn visit_variant(&mut self,
|
||||||
variant: &ast::Variant,
|
variant: &'tcx ast::Variant,
|
||||||
generics: &Generics,
|
generics: &'tcx Generics,
|
||||||
item_id: ast::NodeId) {
|
item_id: ast::NodeId) {
|
||||||
if let Some(ref dis_expr) = variant.node.disr_expr {
|
if let Some(ref dis_expr) = variant.node.disr_expr {
|
||||||
// resolve the discriminator expr as a constant
|
// resolve the discriminator expr as a constant
|
||||||
|
@ -601,7 +603,7 @@ impl<'a> Visitor for Resolver<'a> {
|
||||||
item_id,
|
item_id,
|
||||||
variant.span);
|
variant.span);
|
||||||
}
|
}
|
||||||
fn visit_foreign_item(&mut self, foreign_item: &ForeignItem) {
|
fn visit_foreign_item(&mut self, foreign_item: &'tcx ForeignItem) {
|
||||||
let type_parameters = match foreign_item.node {
|
let type_parameters = match foreign_item.node {
|
||||||
ForeignItemKind::Fn(_, ref generics) => {
|
ForeignItemKind::Fn(_, ref generics) => {
|
||||||
HasTypeParameters(generics, ItemRibKind)
|
HasTypeParameters(generics, ItemRibKind)
|
||||||
|
@ -613,8 +615,8 @@ impl<'a> Visitor for Resolver<'a> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
fn visit_fn(&mut self,
|
fn visit_fn(&mut self,
|
||||||
function_kind: FnKind,
|
function_kind: FnKind<'tcx>,
|
||||||
declaration: &FnDecl,
|
declaration: &'tcx FnDecl,
|
||||||
_: Span,
|
_: Span,
|
||||||
node_id: NodeId) {
|
node_id: NodeId) {
|
||||||
let rib_kind = match function_kind {
|
let rib_kind = match function_kind {
|
||||||
|
|
|
@ -345,7 +345,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_formals(&mut self, formals: &Vec<ast::Arg>, qualname: &str) {
|
fn process_formals(&mut self, formals: &'l [ast::Arg], qualname: &str) {
|
||||||
for arg in formals {
|
for arg in formals {
|
||||||
self.visit_pat(&arg.pat);
|
self.visit_pat(&arg.pat);
|
||||||
let mut collector = PathCollector::new();
|
let mut collector = PathCollector::new();
|
||||||
|
@ -379,12 +379,12 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_method(&mut self,
|
fn process_method(&mut self,
|
||||||
sig: &ast::MethodSig,
|
sig: &'l ast::MethodSig,
|
||||||
body: Option<&ast::Block>,
|
body: Option<&'l ast::Block>,
|
||||||
id: ast::NodeId,
|
id: ast::NodeId,
|
||||||
name: ast::Name,
|
name: ast::Name,
|
||||||
vis: Visibility,
|
vis: Visibility,
|
||||||
attrs: &[Attribute],
|
attrs: &'l [Attribute],
|
||||||
span: Span) {
|
span: Span) {
|
||||||
debug!("process_method: {}:{}", id, name);
|
debug!("process_method: {}:{}", id, name);
|
||||||
|
|
||||||
|
@ -465,7 +465,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_trait_ref(&mut self, trait_ref: &ast::TraitRef) {
|
fn process_trait_ref(&mut self, trait_ref: &'l ast::TraitRef) {
|
||||||
let trait_ref_data = self.save_ctxt.get_trait_ref_data(trait_ref, self.cur_scope);
|
let trait_ref_data = self.save_ctxt.get_trait_ref_data(trait_ref, self.cur_scope);
|
||||||
if let Some(trait_ref_data) = trait_ref_data {
|
if let Some(trait_ref_data) = trait_ref_data {
|
||||||
if !self.span.filter_generated(Some(trait_ref_data.span), trait_ref.path.span) {
|
if !self.span.filter_generated(Some(trait_ref_data.span), trait_ref.path.span) {
|
||||||
|
@ -488,7 +488,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
|
||||||
|
|
||||||
// Dump generic params bindings, then visit_generics
|
// Dump generic params bindings, then visit_generics
|
||||||
fn process_generic_params(&mut self,
|
fn process_generic_params(&mut self,
|
||||||
generics: &ast::Generics,
|
generics: &'l ast::Generics,
|
||||||
full_span: Span,
|
full_span: Span,
|
||||||
prefix: &str,
|
prefix: &str,
|
||||||
id: NodeId) {
|
id: NodeId) {
|
||||||
|
@ -522,10 +522,10 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_fn(&mut self,
|
fn process_fn(&mut self,
|
||||||
item: &ast::Item,
|
item: &'l ast::Item,
|
||||||
decl: &ast::FnDecl,
|
decl: &'l ast::FnDecl,
|
||||||
ty_params: &ast::Generics,
|
ty_params: &'l ast::Generics,
|
||||||
body: &ast::Block) {
|
body: &'l ast::Block) {
|
||||||
if let Some(fn_data) = self.save_ctxt.get_item_data(item) {
|
if let Some(fn_data) = self.save_ctxt.get_item_data(item) {
|
||||||
down_cast_data!(fn_data, FunctionData, item.span);
|
down_cast_data!(fn_data, FunctionData, item.span);
|
||||||
if !self.span.filter_generated(Some(fn_data.span), item.span) {
|
if !self.span.filter_generated(Some(fn_data.span), item.span) {
|
||||||
|
@ -547,7 +547,10 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
|
||||||
self.nest(item.id, |v| v.visit_block(&body));
|
self.nest(item.id, |v| v.visit_block(&body));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_static_or_const_item(&mut self, item: &ast::Item, typ: &ast::Ty, expr: &ast::Expr) {
|
fn process_static_or_const_item(&mut self,
|
||||||
|
item: &'l ast::Item,
|
||||||
|
typ: &'l ast::Ty,
|
||||||
|
expr: &'l ast::Expr) {
|
||||||
if let Some(var_data) = self.save_ctxt.get_item_data(item) {
|
if let Some(var_data) = self.save_ctxt.get_item_data(item) {
|
||||||
down_cast_data!(var_data, VariableData, item.span);
|
down_cast_data!(var_data, VariableData, item.span);
|
||||||
if !self.span.filter_generated(Some(var_data.span), item.span) {
|
if !self.span.filter_generated(Some(var_data.span), item.span) {
|
||||||
|
@ -562,11 +565,11 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
|
||||||
id: ast::NodeId,
|
id: ast::NodeId,
|
||||||
name: ast::Name,
|
name: ast::Name,
|
||||||
span: Span,
|
span: Span,
|
||||||
typ: &ast::Ty,
|
typ: &'l ast::Ty,
|
||||||
expr: &ast::Expr,
|
expr: &'l ast::Expr,
|
||||||
parent_id: DefId,
|
parent_id: DefId,
|
||||||
vis: Visibility,
|
vis: Visibility,
|
||||||
attrs: &[Attribute]) {
|
attrs: &'l [Attribute]) {
|
||||||
let qualname = format!("::{}", self.tcx.node_path_str(id));
|
let qualname = format!("::{}", self.tcx.node_path_str(id));
|
||||||
|
|
||||||
let sub_span = self.span.sub_span_after_keyword(span, keywords::Const);
|
let sub_span = self.span.sub_span_after_keyword(span, keywords::Const);
|
||||||
|
@ -594,9 +597,9 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
|
||||||
|
|
||||||
// FIXME tuple structs should generate tuple-specific data.
|
// FIXME tuple structs should generate tuple-specific data.
|
||||||
fn process_struct(&mut self,
|
fn process_struct(&mut self,
|
||||||
item: &ast::Item,
|
item: &'l ast::Item,
|
||||||
def: &ast::VariantData,
|
def: &'l ast::VariantData,
|
||||||
ty_params: &ast::Generics) {
|
ty_params: &'l ast::Generics) {
|
||||||
let name = item.ident.to_string();
|
let name = item.ident.to_string();
|
||||||
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
|
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
|
||||||
|
|
||||||
|
@ -641,9 +644,9 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_enum(&mut self,
|
fn process_enum(&mut self,
|
||||||
item: &ast::Item,
|
item: &'l ast::Item,
|
||||||
enum_definition: &ast::EnumDef,
|
enum_definition: &'l ast::EnumDef,
|
||||||
ty_params: &ast::Generics) {
|
ty_params: &'l ast::Generics) {
|
||||||
let enum_data = self.save_ctxt.get_item_data(item);
|
let enum_data = self.save_ctxt.get_item_data(item);
|
||||||
let enum_data = match enum_data {
|
let enum_data = match enum_data {
|
||||||
None => return,
|
None => return,
|
||||||
|
@ -721,11 +724,11 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_impl(&mut self,
|
fn process_impl(&mut self,
|
||||||
item: &ast::Item,
|
item: &'l ast::Item,
|
||||||
type_parameters: &ast::Generics,
|
type_parameters: &'l ast::Generics,
|
||||||
trait_ref: &Option<ast::TraitRef>,
|
trait_ref: &'l Option<ast::TraitRef>,
|
||||||
typ: &ast::Ty,
|
typ: &'l ast::Ty,
|
||||||
impl_items: &[ast::ImplItem]) {
|
impl_items: &'l [ast::ImplItem]) {
|
||||||
let mut has_self_ref = false;
|
let mut has_self_ref = false;
|
||||||
if let Some(impl_data) = self.save_ctxt.get_item_data(item) {
|
if let Some(impl_data) = self.save_ctxt.get_item_data(item) {
|
||||||
down_cast_data!(impl_data, ImplData, item.span);
|
down_cast_data!(impl_data, ImplData, item.span);
|
||||||
|
@ -764,10 +767,10 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_trait(&mut self,
|
fn process_trait(&mut self,
|
||||||
item: &ast::Item,
|
item: &'l ast::Item,
|
||||||
generics: &ast::Generics,
|
generics: &'l ast::Generics,
|
||||||
trait_refs: &ast::TyParamBounds,
|
trait_refs: &'l ast::TyParamBounds,
|
||||||
methods: &[ast::TraitItem]) {
|
methods: &'l [ast::TraitItem]) {
|
||||||
let name = item.ident.to_string();
|
let name = item.ident.to_string();
|
||||||
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
|
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
|
||||||
let mut val = name.clone();
|
let mut val = name.clone();
|
||||||
|
@ -938,11 +941,11 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_struct_lit(&mut self,
|
fn process_struct_lit(&mut self,
|
||||||
ex: &ast::Expr,
|
ex: &'l ast::Expr,
|
||||||
path: &ast::Path,
|
path: &'l ast::Path,
|
||||||
fields: &Vec<ast::Field>,
|
fields: &'l [ast::Field],
|
||||||
variant: &ty::VariantDef,
|
variant: &'l ty::VariantDef,
|
||||||
base: &Option<P<ast::Expr>>) {
|
base: &'l Option<P<ast::Expr>>) {
|
||||||
self.write_sub_paths_truncated(path, false);
|
self.write_sub_paths_truncated(path, false);
|
||||||
|
|
||||||
if let Some(struct_lit_data) = self.save_ctxt.get_expr_data(ex) {
|
if let Some(struct_lit_data) = self.save_ctxt.get_expr_data(ex) {
|
||||||
|
@ -969,7 +972,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
|
||||||
walk_list!(self, visit_expr, base);
|
walk_list!(self, visit_expr, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_method_call(&mut self, ex: &ast::Expr, args: &Vec<P<ast::Expr>>) {
|
fn process_method_call(&mut self, ex: &'l ast::Expr, args: &'l [P<ast::Expr>]) {
|
||||||
if let Some(mcd) = self.save_ctxt.get_expr_data(ex) {
|
if let Some(mcd) = self.save_ctxt.get_expr_data(ex) {
|
||||||
down_cast_data!(mcd, MethodCallData, ex.span);
|
down_cast_data!(mcd, MethodCallData, ex.span);
|
||||||
if !self.span.filter_generated(Some(mcd.span), ex.span) {
|
if !self.span.filter_generated(Some(mcd.span), ex.span) {
|
||||||
|
@ -981,7 +984,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
|
||||||
walk_list!(self, visit_expr, args);
|
walk_list!(self, visit_expr, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_pat(&mut self, p: &ast::Pat) {
|
fn process_pat(&mut self, p: &'l ast::Pat) {
|
||||||
match p.node {
|
match p.node {
|
||||||
PatKind::Struct(ref path, ref fields, _) => {
|
PatKind::Struct(ref path, ref fields, _) => {
|
||||||
visit::walk_path(self, path);
|
visit::walk_path(self, path);
|
||||||
|
@ -1014,7 +1017,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn process_var_decl(&mut self, p: &ast::Pat, value: String) {
|
fn process_var_decl(&mut self, p: &'l ast::Pat, value: String) {
|
||||||
// The local could declare multiple new vars, we must walk the
|
// The local could declare multiple new vars, we must walk the
|
||||||
// pattern and collect them all.
|
// pattern and collect them all.
|
||||||
let mut collector = PathCollector::new();
|
let mut collector = PathCollector::new();
|
||||||
|
@ -1105,7 +1108,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_trait_item(&mut self, trait_item: &ast::TraitItem, trait_id: DefId) {
|
fn process_trait_item(&mut self, trait_item: &'l ast::TraitItem, trait_id: DefId) {
|
||||||
self.process_macro_use(trait_item.span, trait_item.id);
|
self.process_macro_use(trait_item.span, trait_item.id);
|
||||||
match trait_item.node {
|
match trait_item.node {
|
||||||
ast::TraitItemKind::Const(ref ty, Some(ref expr)) => {
|
ast::TraitItemKind::Const(ref ty, Some(ref expr)) => {
|
||||||
|
@ -1133,7 +1136,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_impl_item(&mut self, impl_item: &ast::ImplItem, impl_id: DefId) {
|
fn process_impl_item(&mut self, impl_item: &'l ast::ImplItem, impl_id: DefId) {
|
||||||
self.process_macro_use(impl_item.span, impl_item.id);
|
self.process_macro_use(impl_item.span, impl_item.id);
|
||||||
match impl_item.node {
|
match impl_item.node {
|
||||||
ast::ImplItemKind::Const(ref ty, ref expr) => {
|
ast::ImplItemKind::Const(ref ty, ref expr) => {
|
||||||
|
@ -1161,8 +1164,8 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor for DumpVisitor<'l, 'tcx, 'll, D> {
|
impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'l> for DumpVisitor<'l, 'tcx, 'll, D> {
|
||||||
fn visit_item(&mut self, item: &ast::Item) {
|
fn visit_item(&mut self, item: &'l ast::Item) {
|
||||||
use syntax::ast::ItemKind::*;
|
use syntax::ast::ItemKind::*;
|
||||||
self.process_macro_use(item.span, item.id);
|
self.process_macro_use(item.span, item.id);
|
||||||
match item.node {
|
match item.node {
|
||||||
|
@ -1306,7 +1309,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor for DumpVisitor<'l, 'tcx, 'll, D>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_generics(&mut self, generics: &ast::Generics) {
|
fn visit_generics(&mut self, generics: &'l ast::Generics) {
|
||||||
for param in generics.ty_params.iter() {
|
for param in generics.ty_params.iter() {
|
||||||
for bound in param.bounds.iter() {
|
for bound in param.bounds.iter() {
|
||||||
if let ast::TraitTyParamBound(ref trait_ref, _) = *bound {
|
if let ast::TraitTyParamBound(ref trait_ref, _) = *bound {
|
||||||
|
@ -1319,7 +1322,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor for DumpVisitor<'l, 'tcx, 'll, D>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_ty(&mut self, t: &ast::Ty) {
|
fn visit_ty(&mut self, t: &'l ast::Ty) {
|
||||||
self.process_macro_use(t.span, t.id);
|
self.process_macro_use(t.span, t.id);
|
||||||
match t.node {
|
match t.node {
|
||||||
ast::TyKind::Path(_, ref path) => {
|
ast::TyKind::Path(_, ref path) => {
|
||||||
|
@ -1343,7 +1346,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor for DumpVisitor<'l, 'tcx, 'll, D>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_expr(&mut self, ex: &ast::Expr) {
|
fn visit_expr(&mut self, ex: &'l ast::Expr) {
|
||||||
self.process_macro_use(ex.span, ex.id);
|
self.process_macro_use(ex.span, ex.id);
|
||||||
match ex.node {
|
match ex.node {
|
||||||
ast::ExprKind::Call(ref _f, ref _args) => {
|
ast::ExprKind::Call(ref _f, ref _args) => {
|
||||||
|
@ -1451,17 +1454,17 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor for DumpVisitor<'l, 'tcx, 'll, D>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_mac(&mut self, mac: &ast::Mac) {
|
fn visit_mac(&mut self, mac: &'l ast::Mac) {
|
||||||
// These shouldn't exist in the AST at this point, log a span bug.
|
// These shouldn't exist in the AST at this point, log a span bug.
|
||||||
span_bug!(mac.span, "macro invocation should have been expanded out of AST");
|
span_bug!(mac.span, "macro invocation should have been expanded out of AST");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_pat(&mut self, p: &ast::Pat) {
|
fn visit_pat(&mut self, p: &'l ast::Pat) {
|
||||||
self.process_macro_use(p.span, p.id);
|
self.process_macro_use(p.span, p.id);
|
||||||
self.process_pat(p);
|
self.process_pat(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_arm(&mut self, arm: &ast::Arm) {
|
fn visit_arm(&mut self, arm: &'l ast::Arm) {
|
||||||
let mut collector = PathCollector::new();
|
let mut collector = PathCollector::new();
|
||||||
for pattern in &arm.pats {
|
for pattern in &arm.pats {
|
||||||
// collect paths from the arm's patterns
|
// collect paths from the arm's patterns
|
||||||
|
@ -1524,12 +1527,12 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor for DumpVisitor<'l, 'tcx, 'll, D>
|
||||||
self.visit_expr(&arm.body);
|
self.visit_expr(&arm.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_stmt(&mut self, s: &ast::Stmt) {
|
fn visit_stmt(&mut self, s: &'l ast::Stmt) {
|
||||||
self.process_macro_use(s.span, s.id);
|
self.process_macro_use(s.span, s.id);
|
||||||
visit::walk_stmt(self, s)
|
visit::walk_stmt(self, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_local(&mut self, l: &ast::Local) {
|
fn visit_local(&mut self, l: &'l ast::Local) {
|
||||||
self.process_macro_use(l.span, l.id);
|
self.process_macro_use(l.span, l.id);
|
||||||
let value = l.init.as_ref().map(|i| self.span.snippet(i.span)).unwrap_or(String::new());
|
let value = l.init.as_ref().map(|i| self.span.snippet(i.span)).unwrap_or(String::new());
|
||||||
self.process_var_decl(&l.pat, value);
|
self.process_var_decl(&l.pat, value);
|
||||||
|
|
|
@ -741,7 +741,7 @@ impl PathCollector {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Visitor for PathCollector {
|
impl<'a> Visitor<'a> for PathCollector {
|
||||||
fn visit_pat(&mut self, p: &ast::Pat) {
|
fn visit_pat(&mut self, p: &ast::Pat) {
|
||||||
match p.node {
|
match p.node {
|
||||||
PatKind::Struct(ref path, ..) => {
|
PatKind::Struct(ref path, ..) => {
|
||||||
|
|
|
@ -85,7 +85,7 @@ macro_rules! expansions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn visit_with<V: Visitor>(&self, visitor: &mut V) {
|
pub fn visit_with<'a, V: Visitor<'a>>(&'a self, visitor: &mut V) {
|
||||||
match *self {
|
match *self {
|
||||||
Expansion::OptExpr(Some(ref expr)) => visitor.visit_expr(expr),
|
Expansion::OptExpr(Some(ref expr)) => visitor.visit_expr(expr),
|
||||||
Expansion::OptExpr(None) => {}
|
Expansion::OptExpr(None) => {}
|
||||||
|
|
|
@ -1014,7 +1014,7 @@ fn starts_with_digit(s: &str) -> bool {
|
||||||
s.as_bytes().first().cloned().map_or(false, |b| b >= b'0' && b <= b'9')
|
s.as_bytes().first().cloned().map_or(false, |b| b >= b'0' && b <= b'9')
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Visitor for PostExpansionVisitor<'a> {
|
impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
||||||
fn visit_attribute(&mut self, attr: &ast::Attribute) {
|
fn visit_attribute(&mut self, attr: &ast::Attribute) {
|
||||||
if !self.context.cm.span_allows_unstable(attr.span) {
|
if !self.context.cm.span_allows_unstable(attr.span) {
|
||||||
// check for gated attributes
|
// check for gated attributes
|
||||||
|
@ -1035,7 +1035,7 @@ impl<'a> Visitor for PostExpansionVisitor<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_item(&mut self, i: &ast::Item) {
|
fn visit_item(&mut self, i: &'a ast::Item) {
|
||||||
match i.node {
|
match i.node {
|
||||||
ast::ItemKind::ExternCrate(_) => {
|
ast::ItemKind::ExternCrate(_) => {
|
||||||
if attr::contains_name(&i.attrs[..], "macro_reexport") {
|
if attr::contains_name(&i.attrs[..], "macro_reexport") {
|
||||||
|
@ -1128,7 +1128,7 @@ impl<'a> Visitor for PostExpansionVisitor<'a> {
|
||||||
visit::walk_item(self, i);
|
visit::walk_item(self, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_foreign_item(&mut self, i: &ast::ForeignItem) {
|
fn visit_foreign_item(&mut self, i: &'a ast::ForeignItem) {
|
||||||
let links_to_llvm = match attr::first_attr_value_str_by_name(&i.attrs, "link_name") {
|
let links_to_llvm = match attr::first_attr_value_str_by_name(&i.attrs, "link_name") {
|
||||||
Some(val) => val.as_str().starts_with("llvm."),
|
Some(val) => val.as_str().starts_with("llvm."),
|
||||||
_ => false
|
_ => false
|
||||||
|
@ -1141,7 +1141,7 @@ impl<'a> Visitor for PostExpansionVisitor<'a> {
|
||||||
visit::walk_foreign_item(self, i)
|
visit::walk_foreign_item(self, i)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_ty(&mut self, ty: &ast::Ty) {
|
fn visit_ty(&mut self, ty: &'a ast::Ty) {
|
||||||
match ty.node {
|
match ty.node {
|
||||||
ast::TyKind::BareFn(ref bare_fn_ty) => {
|
ast::TyKind::BareFn(ref bare_fn_ty) => {
|
||||||
self.check_abi(bare_fn_ty.abi, ty.span);
|
self.check_abi(bare_fn_ty.abi, ty.span);
|
||||||
|
@ -1159,7 +1159,7 @@ impl<'a> Visitor for PostExpansionVisitor<'a> {
|
||||||
visit::walk_ty(self, ty)
|
visit::walk_ty(self, ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_fn_ret_ty(&mut self, ret_ty: &ast::FunctionRetTy) {
|
fn visit_fn_ret_ty(&mut self, ret_ty: &'a ast::FunctionRetTy) {
|
||||||
if let ast::FunctionRetTy::Ty(ref output_ty) = *ret_ty {
|
if let ast::FunctionRetTy::Ty(ref output_ty) = *ret_ty {
|
||||||
match output_ty.node {
|
match output_ty.node {
|
||||||
ast::TyKind::Never => return,
|
ast::TyKind::Never => return,
|
||||||
|
@ -1169,7 +1169,7 @@ impl<'a> Visitor for PostExpansionVisitor<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_expr(&mut self, e: &ast::Expr) {
|
fn visit_expr(&mut self, e: &'a ast::Expr) {
|
||||||
match e.node {
|
match e.node {
|
||||||
ast::ExprKind::Box(_) => {
|
ast::ExprKind::Box(_) => {
|
||||||
gate_feature_post!(&self, box_syntax, e.span, EXPLAIN_BOX_SYNTAX);
|
gate_feature_post!(&self, box_syntax, e.span, EXPLAIN_BOX_SYNTAX);
|
||||||
|
@ -1208,7 +1208,7 @@ impl<'a> Visitor for PostExpansionVisitor<'a> {
|
||||||
visit::walk_expr(self, e);
|
visit::walk_expr(self, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_pat(&mut self, pattern: &ast::Pat) {
|
fn visit_pat(&mut self, pattern: &'a ast::Pat) {
|
||||||
match pattern.node {
|
match pattern.node {
|
||||||
PatKind::Slice(_, Some(_), ref last) if !last.is_empty() => {
|
PatKind::Slice(_, Some(_), ref last) if !last.is_empty() => {
|
||||||
gate_feature_post!(&self, advanced_slice_patterns,
|
gate_feature_post!(&self, advanced_slice_patterns,
|
||||||
|
@ -1242,8 +1242,8 @@ impl<'a> Visitor for PostExpansionVisitor<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_fn(&mut self,
|
fn visit_fn(&mut self,
|
||||||
fn_kind: FnKind,
|
fn_kind: FnKind<'a>,
|
||||||
fn_decl: &ast::FnDecl,
|
fn_decl: &'a ast::FnDecl,
|
||||||
span: Span,
|
span: Span,
|
||||||
_node_id: NodeId) {
|
_node_id: NodeId) {
|
||||||
// check for const fn declarations
|
// check for const fn declarations
|
||||||
|
@ -1269,7 +1269,7 @@ impl<'a> Visitor for PostExpansionVisitor<'a> {
|
||||||
visit::walk_fn(self, fn_kind, fn_decl, span);
|
visit::walk_fn(self, fn_kind, fn_decl, span);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_trait_item(&mut self, ti: &ast::TraitItem) {
|
fn visit_trait_item(&mut self, ti: &'a ast::TraitItem) {
|
||||||
match ti.node {
|
match ti.node {
|
||||||
ast::TraitItemKind::Const(..) => {
|
ast::TraitItemKind::Const(..) => {
|
||||||
gate_feature_post!(&self, associated_consts,
|
gate_feature_post!(&self, associated_consts,
|
||||||
|
@ -1293,7 +1293,7 @@ impl<'a> Visitor for PostExpansionVisitor<'a> {
|
||||||
visit::walk_trait_item(self, ti);
|
visit::walk_trait_item(self, ti);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_impl_item(&mut self, ii: &ast::ImplItem) {
|
fn visit_impl_item(&mut self, ii: &'a ast::ImplItem) {
|
||||||
if ii.defaultness == ast::Defaultness::Default {
|
if ii.defaultness == ast::Defaultness::Default {
|
||||||
gate_feature_post!(&self, specialization,
|
gate_feature_post!(&self, specialization,
|
||||||
ii.span,
|
ii.span,
|
||||||
|
@ -1316,7 +1316,7 @@ impl<'a> Visitor for PostExpansionVisitor<'a> {
|
||||||
visit::walk_impl_item(self, ii);
|
visit::walk_impl_item(self, ii);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_vis(&mut self, vis: &ast::Visibility) {
|
fn visit_vis(&mut self, vis: &'a ast::Visibility) {
|
||||||
let span = match *vis {
|
let span = match *vis {
|
||||||
ast::Visibility::Crate(span) => span,
|
ast::Visibility::Crate(span) => span,
|
||||||
ast::Visibility::Restricted { ref path, .. } => path.span,
|
ast::Visibility::Restricted { ref path, .. } => path.span,
|
||||||
|
@ -1327,7 +1327,7 @@ impl<'a> Visitor for PostExpansionVisitor<'a> {
|
||||||
visit::walk_vis(self, vis)
|
visit::walk_vis(self, vis)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_generics(&mut self, g: &ast::Generics) {
|
fn visit_generics(&mut self, g: &'a ast::Generics) {
|
||||||
for t in &g.ty_params {
|
for t in &g.ty_params {
|
||||||
if !t.attrs.is_empty() {
|
if !t.attrs.is_empty() {
|
||||||
gate_feature_post!(&self, generic_param_attrs, t.attrs[0].span,
|
gate_feature_post!(&self, generic_param_attrs, t.attrs[0].span,
|
||||||
|
@ -1337,7 +1337,7 @@ impl<'a> Visitor for PostExpansionVisitor<'a> {
|
||||||
visit::walk_generics(self, g)
|
visit::walk_generics(self, g)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_lifetime_def(&mut self, lifetime_def: &ast::LifetimeDef) {
|
fn visit_lifetime_def(&mut self, lifetime_def: &'a ast::LifetimeDef) {
|
||||||
if !lifetime_def.attrs.is_empty() {
|
if !lifetime_def.attrs.is_empty() {
|
||||||
gate_feature_post!(&self, generic_param_attrs, lifetime_def.attrs[0].span,
|
gate_feature_post!(&self, generic_param_attrs, lifetime_def.attrs[0].span,
|
||||||
"attributes on lifetime bindings are experimental");
|
"attributes on lifetime bindings are experimental");
|
||||||
|
|
|
@ -940,8 +940,8 @@ mod tests {
|
||||||
struct PatIdentVisitor {
|
struct PatIdentVisitor {
|
||||||
spans: Vec<Span>
|
spans: Vec<Span>
|
||||||
}
|
}
|
||||||
impl ::visit::Visitor for PatIdentVisitor {
|
impl<'a> ::visit::Visitor<'a> for PatIdentVisitor {
|
||||||
fn visit_pat(&mut self, p: &ast::Pat) {
|
fn visit_pat(&mut self, p: &'a ast::Pat) {
|
||||||
match p.node {
|
match p.node {
|
||||||
PatKind::Ident(_ , ref spannedident, _) => {
|
PatKind::Ident(_ , ref spannedident, _) => {
|
||||||
self.spans.push(spannedident.span.clone());
|
self.spans.push(spannedident.span.clone());
|
||||||
|
|
|
@ -44,29 +44,29 @@ struct ShowSpanVisitor<'a> {
|
||||||
mode: Mode,
|
mode: Mode,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Visitor for ShowSpanVisitor<'a> {
|
impl<'a> Visitor<'a> for ShowSpanVisitor<'a> {
|
||||||
fn visit_expr(&mut self, e: &ast::Expr) {
|
fn visit_expr(&mut self, e: &'a ast::Expr) {
|
||||||
if let Mode::Expression = self.mode {
|
if let Mode::Expression = self.mode {
|
||||||
self.span_diagnostic.span_warn(e.span, "expression");
|
self.span_diagnostic.span_warn(e.span, "expression");
|
||||||
}
|
}
|
||||||
visit::walk_expr(self, e);
|
visit::walk_expr(self, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_pat(&mut self, p: &ast::Pat) {
|
fn visit_pat(&mut self, p: &'a ast::Pat) {
|
||||||
if let Mode::Pattern = self.mode {
|
if let Mode::Pattern = self.mode {
|
||||||
self.span_diagnostic.span_warn(p.span, "pattern");
|
self.span_diagnostic.span_warn(p.span, "pattern");
|
||||||
}
|
}
|
||||||
visit::walk_pat(self, p);
|
visit::walk_pat(self, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_ty(&mut self, t: &ast::Ty) {
|
fn visit_ty(&mut self, t: &'a ast::Ty) {
|
||||||
if let Mode::Type = self.mode {
|
if let Mode::Type = self.mode {
|
||||||
self.span_diagnostic.span_warn(t.span, "type");
|
self.span_diagnostic.span_warn(t.span, "type");
|
||||||
}
|
}
|
||||||
visit::walk_ty(self, t);
|
visit::walk_ty(self, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_mac(&mut self, mac: &ast::Mac) {
|
fn visit_mac(&mut self, mac: &'a ast::Mac) {
|
||||||
visit::walk_mac(self, mac);
|
visit::walk_mac(self, mac);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ impl NodeCounter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Visitor for NodeCounter {
|
impl<'ast> Visitor<'ast> for NodeCounter {
|
||||||
fn visit_ident(&mut self, span: Span, ident: Ident) {
|
fn visit_ident(&mut self, span: Span, ident: Ident) {
|
||||||
self.count += 1;
|
self.count += 1;
|
||||||
walk_ident(self, span, ident);
|
walk_ident(self, span, ident);
|
||||||
|
|
|
@ -49,56 +49,56 @@ pub enum FnKind<'a> {
|
||||||
/// explicitly, you need to override each method. (And you also need
|
/// explicitly, you need to override each method. (And you also need
|
||||||
/// to monitor future changes to `Visitor` in case a new method with a
|
/// to monitor future changes to `Visitor` in case a new method with a
|
||||||
/// new default implementation gets introduced.)
|
/// new default implementation gets introduced.)
|
||||||
pub trait Visitor: Sized {
|
pub trait Visitor<'ast>: Sized {
|
||||||
fn visit_name(&mut self, _span: Span, _name: Name) {
|
fn visit_name(&mut self, _span: Span, _name: Name) {
|
||||||
// Nothing to do.
|
// Nothing to do.
|
||||||
}
|
}
|
||||||
fn visit_ident(&mut self, span: Span, ident: Ident) {
|
fn visit_ident(&mut self, span: Span, ident: Ident) {
|
||||||
walk_ident(self, span, ident);
|
walk_ident(self, span, ident);
|
||||||
}
|
}
|
||||||
fn visit_mod(&mut self, m: &Mod, _s: Span, _n: NodeId) { walk_mod(self, m) }
|
fn visit_mod(&mut self, m: &'ast Mod, _s: Span, _n: NodeId) { walk_mod(self, m) }
|
||||||
fn visit_foreign_item(&mut self, i: &ForeignItem) { walk_foreign_item(self, i) }
|
fn visit_foreign_item(&mut self, i: &'ast ForeignItem) { walk_foreign_item(self, i) }
|
||||||
fn visit_item(&mut self, i: &Item) { walk_item(self, i) }
|
fn visit_item(&mut self, i: &'ast Item) { walk_item(self, i) }
|
||||||
fn visit_local(&mut self, l: &Local) { walk_local(self, l) }
|
fn visit_local(&mut self, l: &'ast Local) { walk_local(self, l) }
|
||||||
fn visit_block(&mut self, b: &Block) { walk_block(self, b) }
|
fn visit_block(&mut self, b: &'ast Block) { walk_block(self, b) }
|
||||||
fn visit_stmt(&mut self, s: &Stmt) { walk_stmt(self, s) }
|
fn visit_stmt(&mut self, s: &'ast Stmt) { walk_stmt(self, s) }
|
||||||
fn visit_arm(&mut self, a: &Arm) { walk_arm(self, a) }
|
fn visit_arm(&mut self, a: &'ast Arm) { walk_arm(self, a) }
|
||||||
fn visit_pat(&mut self, p: &Pat) { walk_pat(self, p) }
|
fn visit_pat(&mut self, p: &'ast Pat) { walk_pat(self, p) }
|
||||||
fn visit_expr(&mut self, ex: &Expr) { walk_expr(self, ex) }
|
fn visit_expr(&mut self, ex: &'ast Expr) { walk_expr(self, ex) }
|
||||||
fn visit_expr_post(&mut self, _ex: &Expr) { }
|
fn visit_expr_post(&mut self, _ex: &'ast Expr) { }
|
||||||
fn visit_ty(&mut self, t: &Ty) { walk_ty(self, t) }
|
fn visit_ty(&mut self, t: &'ast Ty) { walk_ty(self, t) }
|
||||||
fn visit_generics(&mut self, g: &Generics) { walk_generics(self, g) }
|
fn visit_generics(&mut self, g: &'ast Generics) { walk_generics(self, g) }
|
||||||
fn visit_fn(&mut self, fk: FnKind, fd: &FnDecl, s: Span, _: NodeId) {
|
fn visit_fn(&mut self, fk: FnKind<'ast>, fd: &'ast FnDecl, s: Span, _: NodeId) {
|
||||||
walk_fn(self, fk, fd, s)
|
walk_fn(self, fk, fd, s)
|
||||||
}
|
}
|
||||||
fn visit_trait_item(&mut self, ti: &TraitItem) { walk_trait_item(self, ti) }
|
fn visit_trait_item(&mut self, ti: &'ast TraitItem) { walk_trait_item(self, ti) }
|
||||||
fn visit_impl_item(&mut self, ii: &ImplItem) { walk_impl_item(self, ii) }
|
fn visit_impl_item(&mut self, ii: &'ast ImplItem) { walk_impl_item(self, ii) }
|
||||||
fn visit_trait_ref(&mut self, t: &TraitRef) { walk_trait_ref(self, t) }
|
fn visit_trait_ref(&mut self, t: &'ast TraitRef) { walk_trait_ref(self, t) }
|
||||||
fn visit_ty_param_bound(&mut self, bounds: &TyParamBound) {
|
fn visit_ty_param_bound(&mut self, bounds: &'ast TyParamBound) {
|
||||||
walk_ty_param_bound(self, bounds)
|
walk_ty_param_bound(self, bounds)
|
||||||
}
|
}
|
||||||
fn visit_poly_trait_ref(&mut self, t: &PolyTraitRef, m: &TraitBoundModifier) {
|
fn visit_poly_trait_ref(&mut self, t: &'ast PolyTraitRef, m: &'ast TraitBoundModifier) {
|
||||||
walk_poly_trait_ref(self, t, m)
|
walk_poly_trait_ref(self, t, m)
|
||||||
}
|
}
|
||||||
fn visit_variant_data(&mut self, s: &VariantData, _: Ident,
|
fn visit_variant_data(&mut self, s: &'ast VariantData, _: Ident,
|
||||||
_: &Generics, _: NodeId, _: Span) {
|
_: &'ast Generics, _: NodeId, _: Span) {
|
||||||
walk_struct_def(self, s)
|
walk_struct_def(self, s)
|
||||||
}
|
}
|
||||||
fn visit_struct_field(&mut self, s: &StructField) { walk_struct_field(self, s) }
|
fn visit_struct_field(&mut self, s: &'ast StructField) { walk_struct_field(self, s) }
|
||||||
fn visit_enum_def(&mut self, enum_definition: &EnumDef,
|
fn visit_enum_def(&mut self, enum_definition: &'ast EnumDef,
|
||||||
generics: &Generics, item_id: NodeId, _: Span) {
|
generics: &'ast Generics, item_id: NodeId, _: Span) {
|
||||||
walk_enum_def(self, enum_definition, generics, item_id)
|
walk_enum_def(self, enum_definition, generics, item_id)
|
||||||
}
|
}
|
||||||
fn visit_variant(&mut self, v: &Variant, g: &Generics, item_id: NodeId) {
|
fn visit_variant(&mut self, v: &'ast Variant, g: &'ast Generics, item_id: NodeId) {
|
||||||
walk_variant(self, v, g, item_id)
|
walk_variant(self, v, g, item_id)
|
||||||
}
|
}
|
||||||
fn visit_lifetime(&mut self, lifetime: &Lifetime) {
|
fn visit_lifetime(&mut self, lifetime: &'ast Lifetime) {
|
||||||
walk_lifetime(self, lifetime)
|
walk_lifetime(self, lifetime)
|
||||||
}
|
}
|
||||||
fn visit_lifetime_def(&mut self, lifetime: &LifetimeDef) {
|
fn visit_lifetime_def(&mut self, lifetime: &'ast LifetimeDef) {
|
||||||
walk_lifetime_def(self, lifetime)
|
walk_lifetime_def(self, lifetime)
|
||||||
}
|
}
|
||||||
fn visit_mac(&mut self, _mac: &Mac) {
|
fn visit_mac(&mut self, _mac: &'ast Mac) {
|
||||||
panic!("visit_mac disabled by default");
|
panic!("visit_mac disabled by default");
|
||||||
// NB: see note about macros above.
|
// NB: see note about macros above.
|
||||||
// if you really want a visitor that
|
// if you really want a visitor that
|
||||||
|
@ -106,29 +106,29 @@ pub trait Visitor: Sized {
|
||||||
// definition in your trait impl:
|
// definition in your trait impl:
|
||||||
// visit::walk_mac(self, _mac)
|
// visit::walk_mac(self, _mac)
|
||||||
}
|
}
|
||||||
fn visit_path(&mut self, path: &Path, _id: NodeId) {
|
fn visit_path(&mut self, path: &'ast Path, _id: NodeId) {
|
||||||
walk_path(self, path)
|
walk_path(self, path)
|
||||||
}
|
}
|
||||||
fn visit_path_list_item(&mut self, prefix: &Path, item: &PathListItem) {
|
fn visit_path_list_item(&mut self, prefix: &'ast Path, item: &'ast PathListItem) {
|
||||||
walk_path_list_item(self, prefix, item)
|
walk_path_list_item(self, prefix, item)
|
||||||
}
|
}
|
||||||
fn visit_path_segment(&mut self, path_span: Span, path_segment: &PathSegment) {
|
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'ast PathSegment) {
|
||||||
walk_path_segment(self, path_span, path_segment)
|
walk_path_segment(self, path_span, path_segment)
|
||||||
}
|
}
|
||||||
fn visit_path_parameters(&mut self, path_span: Span, path_parameters: &PathParameters) {
|
fn visit_path_parameters(&mut self, path_span: Span, path_parameters: &'ast PathParameters) {
|
||||||
walk_path_parameters(self, path_span, path_parameters)
|
walk_path_parameters(self, path_span, path_parameters)
|
||||||
}
|
}
|
||||||
fn visit_assoc_type_binding(&mut self, type_binding: &TypeBinding) {
|
fn visit_assoc_type_binding(&mut self, type_binding: &'ast TypeBinding) {
|
||||||
walk_assoc_type_binding(self, type_binding)
|
walk_assoc_type_binding(self, type_binding)
|
||||||
}
|
}
|
||||||
fn visit_attribute(&mut self, _attr: &Attribute) {}
|
fn visit_attribute(&mut self, _attr: &'ast Attribute) {}
|
||||||
fn visit_macro_def(&mut self, macro_def: &MacroDef) {
|
fn visit_macro_def(&mut self, macro_def: &'ast MacroDef) {
|
||||||
walk_macro_def(self, macro_def)
|
walk_macro_def(self, macro_def)
|
||||||
}
|
}
|
||||||
fn visit_vis(&mut self, vis: &Visibility) {
|
fn visit_vis(&mut self, vis: &'ast Visibility) {
|
||||||
walk_vis(self, vis)
|
walk_vis(self, vis)
|
||||||
}
|
}
|
||||||
fn visit_fn_ret_ty(&mut self, ret_ty: &FunctionRetTy) {
|
fn visit_fn_ret_ty(&mut self, ret_ty: &'ast FunctionRetTy) {
|
||||||
walk_fn_ret_ty(self, ret_ty)
|
walk_fn_ret_ty(self, ret_ty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,45 +147,46 @@ macro_rules! walk_list {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_opt_name<V: Visitor>(visitor: &mut V, span: Span, opt_name: Option<Name>) {
|
pub fn walk_opt_name<'a, V: Visitor<'a>>(visitor: &mut V, span: Span, opt_name: Option<Name>) {
|
||||||
if let Some(name) = opt_name {
|
if let Some(name) = opt_name {
|
||||||
visitor.visit_name(span, name);
|
visitor.visit_name(span, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_opt_ident<V: Visitor>(visitor: &mut V, span: Span, opt_ident: Option<Ident>) {
|
pub fn walk_opt_ident<'a, V: Visitor<'a>>(visitor: &mut V, span: Span, opt_ident: Option<Ident>) {
|
||||||
if let Some(ident) = opt_ident {
|
if let Some(ident) = opt_ident {
|
||||||
visitor.visit_ident(span, ident);
|
visitor.visit_ident(span, ident);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_opt_sp_ident<V: Visitor>(visitor: &mut V, opt_sp_ident: &Option<Spanned<Ident>>) {
|
pub fn walk_opt_sp_ident<'a, V: Visitor<'a>>(visitor: &mut V,
|
||||||
|
opt_sp_ident: &Option<Spanned<Ident>>) {
|
||||||
if let Some(ref sp_ident) = *opt_sp_ident {
|
if let Some(ref sp_ident) = *opt_sp_ident {
|
||||||
visitor.visit_ident(sp_ident.span, sp_ident.node);
|
visitor.visit_ident(sp_ident.span, sp_ident.node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_ident<V: Visitor>(visitor: &mut V, span: Span, ident: Ident) {
|
pub fn walk_ident<'a, V: Visitor<'a>>(visitor: &mut V, span: Span, ident: Ident) {
|
||||||
visitor.visit_name(span, ident.name);
|
visitor.visit_name(span, ident.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_crate<V: Visitor>(visitor: &mut V, krate: &Crate) {
|
pub fn walk_crate<'a, V: Visitor<'a>>(visitor: &mut V, krate: &'a Crate) {
|
||||||
visitor.visit_mod(&krate.module, krate.span, CRATE_NODE_ID);
|
visitor.visit_mod(&krate.module, krate.span, CRATE_NODE_ID);
|
||||||
walk_list!(visitor, visit_attribute, &krate.attrs);
|
walk_list!(visitor, visit_attribute, &krate.attrs);
|
||||||
walk_list!(visitor, visit_macro_def, &krate.exported_macros);
|
walk_list!(visitor, visit_macro_def, &krate.exported_macros);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_macro_def<V: Visitor>(visitor: &mut V, macro_def: &MacroDef) {
|
pub fn walk_macro_def<'a, V: Visitor<'a>>(visitor: &mut V, macro_def: &'a MacroDef) {
|
||||||
visitor.visit_ident(macro_def.span, macro_def.ident);
|
visitor.visit_ident(macro_def.span, macro_def.ident);
|
||||||
walk_opt_ident(visitor, macro_def.span, macro_def.imported_from);
|
walk_opt_ident(visitor, macro_def.span, macro_def.imported_from);
|
||||||
walk_list!(visitor, visit_attribute, ¯o_def.attrs);
|
walk_list!(visitor, visit_attribute, ¯o_def.attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_mod<V: Visitor>(visitor: &mut V, module: &Mod) {
|
pub fn walk_mod<'a, V: Visitor<'a>>(visitor: &mut V, module: &'a Mod) {
|
||||||
walk_list!(visitor, visit_item, &module.items);
|
walk_list!(visitor, visit_item, &module.items);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_local<V: Visitor>(visitor: &mut V, local: &Local) {
|
pub fn walk_local<'a, V: Visitor<'a>>(visitor: &mut V, local: &'a Local) {
|
||||||
for attr in local.attrs.iter() {
|
for attr in local.attrs.iter() {
|
||||||
visitor.visit_attribute(attr);
|
visitor.visit_attribute(attr);
|
||||||
}
|
}
|
||||||
|
@ -194,28 +195,30 @@ pub fn walk_local<V: Visitor>(visitor: &mut V, local: &Local) {
|
||||||
walk_list!(visitor, visit_expr, &local.init);
|
walk_list!(visitor, visit_expr, &local.init);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_lifetime<V: Visitor>(visitor: &mut V, lifetime: &Lifetime) {
|
pub fn walk_lifetime<'a, V: Visitor<'a>>(visitor: &mut V, lifetime: &'a Lifetime) {
|
||||||
visitor.visit_name(lifetime.span, lifetime.name);
|
visitor.visit_name(lifetime.span, lifetime.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_lifetime_def<V: Visitor>(visitor: &mut V, lifetime_def: &LifetimeDef) {
|
pub fn walk_lifetime_def<'a, V: Visitor<'a>>(visitor: &mut V, lifetime_def: &'a LifetimeDef) {
|
||||||
visitor.visit_lifetime(&lifetime_def.lifetime);
|
visitor.visit_lifetime(&lifetime_def.lifetime);
|
||||||
walk_list!(visitor, visit_lifetime, &lifetime_def.bounds);
|
walk_list!(visitor, visit_lifetime, &lifetime_def.bounds);
|
||||||
walk_list!(visitor, visit_attribute, &*lifetime_def.attrs);
|
walk_list!(visitor, visit_attribute, &*lifetime_def.attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_poly_trait_ref<V>(visitor: &mut V, trait_ref: &PolyTraitRef, _: &TraitBoundModifier)
|
pub fn walk_poly_trait_ref<'a, V>(visitor: &mut V,
|
||||||
where V: Visitor,
|
trait_ref: &'a PolyTraitRef,
|
||||||
|
_: &TraitBoundModifier)
|
||||||
|
where V: Visitor<'a>,
|
||||||
{
|
{
|
||||||
walk_list!(visitor, visit_lifetime_def, &trait_ref.bound_lifetimes);
|
walk_list!(visitor, visit_lifetime_def, &trait_ref.bound_lifetimes);
|
||||||
visitor.visit_trait_ref(&trait_ref.trait_ref);
|
visitor.visit_trait_ref(&trait_ref.trait_ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_trait_ref<V: Visitor>(visitor: &mut V, trait_ref: &TraitRef) {
|
pub fn walk_trait_ref<'a, V: Visitor<'a>>(visitor: &mut V, trait_ref: &'a TraitRef) {
|
||||||
visitor.visit_path(&trait_ref.path, trait_ref.ref_id)
|
visitor.visit_path(&trait_ref.path, trait_ref.ref_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_item<V: Visitor>(visitor: &mut V, item: &Item) {
|
pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
|
||||||
visitor.visit_vis(&item.vis);
|
visitor.visit_vis(&item.vis);
|
||||||
visitor.visit_ident(item.span, item.ident);
|
visitor.visit_ident(item.span, item.ident);
|
||||||
match item.node {
|
match item.node {
|
||||||
|
@ -294,15 +297,18 @@ pub fn walk_item<V: Visitor>(visitor: &mut V, item: &Item) {
|
||||||
walk_list!(visitor, visit_attribute, &item.attrs);
|
walk_list!(visitor, visit_attribute, &item.attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_enum_def<V: Visitor>(visitor: &mut V,
|
pub fn walk_enum_def<'a, V: Visitor<'a>>(visitor: &mut V,
|
||||||
enum_definition: &EnumDef,
|
enum_definition: &'a EnumDef,
|
||||||
generics: &Generics,
|
generics: &'a Generics,
|
||||||
item_id: NodeId) {
|
item_id: NodeId) {
|
||||||
walk_list!(visitor, visit_variant, &enum_definition.variants, generics, item_id);
|
walk_list!(visitor, visit_variant, &enum_definition.variants, generics, item_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_variant<V>(visitor: &mut V, variant: &Variant, generics: &Generics, item_id: NodeId)
|
pub fn walk_variant<'a, V>(visitor: &mut V,
|
||||||
where V: Visitor,
|
variant: &'a Variant,
|
||||||
|
generics: &'a Generics,
|
||||||
|
item_id: NodeId)
|
||||||
|
where V: Visitor<'a>,
|
||||||
{
|
{
|
||||||
visitor.visit_ident(variant.span, variant.node.name);
|
visitor.visit_ident(variant.span, variant.node.name);
|
||||||
visitor.visit_variant_data(&variant.node.data, variant.node.name,
|
visitor.visit_variant_data(&variant.node.data, variant.node.name,
|
||||||
|
@ -311,7 +317,7 @@ pub fn walk_variant<V>(visitor: &mut V, variant: &Variant, generics: &Generics,
|
||||||
walk_list!(visitor, visit_attribute, &variant.node.attrs);
|
walk_list!(visitor, visit_attribute, &variant.node.attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_ty<V: Visitor>(visitor: &mut V, typ: &Ty) {
|
pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) {
|
||||||
match typ.node {
|
match typ.node {
|
||||||
TyKind::Slice(ref ty) | TyKind::Paren(ref ty) => {
|
TyKind::Slice(ref ty) | TyKind::Paren(ref ty) => {
|
||||||
visitor.visit_ty(ty)
|
visitor.visit_ty(ty)
|
||||||
|
@ -361,24 +367,30 @@ pub fn walk_ty<V: Visitor>(visitor: &mut V, typ: &Ty) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_path<V: Visitor>(visitor: &mut V, path: &Path) {
|
pub fn walk_path<'a, V: Visitor<'a>>(visitor: &mut V, path: &'a Path) {
|
||||||
for segment in &path.segments {
|
for segment in &path.segments {
|
||||||
visitor.visit_path_segment(path.span, segment);
|
visitor.visit_path_segment(path.span, segment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_path_list_item<V: Visitor>(visitor: &mut V, _prefix: &Path, item: &PathListItem) {
|
pub fn walk_path_list_item<'a, V: Visitor<'a>>(visitor: &mut V,
|
||||||
|
_prefix: &Path,
|
||||||
|
item: &'a PathListItem) {
|
||||||
visitor.visit_ident(item.span, item.node.name);
|
visitor.visit_ident(item.span, item.node.name);
|
||||||
walk_opt_ident(visitor, item.span, item.node.rename);
|
walk_opt_ident(visitor, item.span, item.node.rename);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_path_segment<V: Visitor>(visitor: &mut V, path_span: Span, segment: &PathSegment) {
|
pub fn walk_path_segment<'a, V: Visitor<'a>>(visitor: &mut V,
|
||||||
|
path_span: Span,
|
||||||
|
segment: &'a PathSegment) {
|
||||||
visitor.visit_ident(path_span, segment.identifier);
|
visitor.visit_ident(path_span, segment.identifier);
|
||||||
visitor.visit_path_parameters(path_span, &segment.parameters);
|
visitor.visit_path_parameters(path_span, &segment.parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_path_parameters<V>(visitor: &mut V, _path_span: Span, path_parameters: &PathParameters)
|
pub fn walk_path_parameters<'a, V>(visitor: &mut V,
|
||||||
where V: Visitor,
|
_path_span: Span,
|
||||||
|
path_parameters: &'a PathParameters)
|
||||||
|
where V: Visitor<'a>,
|
||||||
{
|
{
|
||||||
match *path_parameters {
|
match *path_parameters {
|
||||||
PathParameters::AngleBracketed(ref data) => {
|
PathParameters::AngleBracketed(ref data) => {
|
||||||
|
@ -393,12 +405,13 @@ pub fn walk_path_parameters<V>(visitor: &mut V, _path_span: Span, path_parameter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_assoc_type_binding<V: Visitor>(visitor: &mut V, type_binding: &TypeBinding) {
|
pub fn walk_assoc_type_binding<'a, V: Visitor<'a>>(visitor: &mut V,
|
||||||
|
type_binding: &'a TypeBinding) {
|
||||||
visitor.visit_ident(type_binding.span, type_binding.ident);
|
visitor.visit_ident(type_binding.span, type_binding.ident);
|
||||||
visitor.visit_ty(&type_binding.ty);
|
visitor.visit_ty(&type_binding.ty);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_pat<V: Visitor>(visitor: &mut V, pattern: &Pat) {
|
pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) {
|
||||||
match pattern.node {
|
match pattern.node {
|
||||||
PatKind::TupleStruct(ref path, ref children, _) => {
|
PatKind::TupleStruct(ref path, ref children, _) => {
|
||||||
visitor.visit_path(path, pattern.id);
|
visitor.visit_path(path, pattern.id);
|
||||||
|
@ -443,7 +456,7 @@ pub fn walk_pat<V: Visitor>(visitor: &mut V, pattern: &Pat) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_foreign_item<V: Visitor>(visitor: &mut V, foreign_item: &ForeignItem) {
|
pub fn walk_foreign_item<'a, V: Visitor<'a>>(visitor: &mut V, foreign_item: &'a ForeignItem) {
|
||||||
visitor.visit_vis(&foreign_item.vis);
|
visitor.visit_vis(&foreign_item.vis);
|
||||||
visitor.visit_ident(foreign_item.span, foreign_item.ident);
|
visitor.visit_ident(foreign_item.span, foreign_item.ident);
|
||||||
|
|
||||||
|
@ -458,7 +471,7 @@ pub fn walk_foreign_item<V: Visitor>(visitor: &mut V, foreign_item: &ForeignItem
|
||||||
walk_list!(visitor, visit_attribute, &foreign_item.attrs);
|
walk_list!(visitor, visit_attribute, &foreign_item.attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_ty_param_bound<V: Visitor>(visitor: &mut V, bound: &TyParamBound) {
|
pub fn walk_ty_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a TyParamBound) {
|
||||||
match *bound {
|
match *bound {
|
||||||
TraitTyParamBound(ref typ, ref modifier) => {
|
TraitTyParamBound(ref typ, ref modifier) => {
|
||||||
visitor.visit_poly_trait_ref(typ, modifier);
|
visitor.visit_poly_trait_ref(typ, modifier);
|
||||||
|
@ -469,7 +482,7 @@ pub fn walk_ty_param_bound<V: Visitor>(visitor: &mut V, bound: &TyParamBound) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_generics<V: Visitor>(visitor: &mut V, generics: &Generics) {
|
pub fn walk_generics<'a, V: Visitor<'a>>(visitor: &mut V, generics: &'a Generics) {
|
||||||
for param in &generics.ty_params {
|
for param in &generics.ty_params {
|
||||||
visitor.visit_ident(param.span, param.ident);
|
visitor.visit_ident(param.span, param.ident);
|
||||||
walk_list!(visitor, visit_ty_param_bound, ¶m.bounds);
|
walk_list!(visitor, visit_ty_param_bound, ¶m.bounds);
|
||||||
|
@ -504,13 +517,13 @@ pub fn walk_generics<V: Visitor>(visitor: &mut V, generics: &Generics) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_fn_ret_ty<V: Visitor>(visitor: &mut V, ret_ty: &FunctionRetTy) {
|
pub fn walk_fn_ret_ty<'a, V: Visitor<'a>>(visitor: &mut V, ret_ty: &'a FunctionRetTy) {
|
||||||
if let FunctionRetTy::Ty(ref output_ty) = *ret_ty {
|
if let FunctionRetTy::Ty(ref output_ty) = *ret_ty {
|
||||||
visitor.visit_ty(output_ty)
|
visitor.visit_ty(output_ty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_fn_decl<V: Visitor>(visitor: &mut V, function_declaration: &FnDecl) {
|
pub fn walk_fn_decl<'a, V: Visitor<'a>>(visitor: &mut V, function_declaration: &'a FnDecl) {
|
||||||
for argument in &function_declaration.inputs {
|
for argument in &function_declaration.inputs {
|
||||||
visitor.visit_pat(&argument.pat);
|
visitor.visit_pat(&argument.pat);
|
||||||
visitor.visit_ty(&argument.ty)
|
visitor.visit_ty(&argument.ty)
|
||||||
|
@ -518,8 +531,8 @@ pub fn walk_fn_decl<V: Visitor>(visitor: &mut V, function_declaration: &FnDecl)
|
||||||
visitor.visit_fn_ret_ty(&function_declaration.output)
|
visitor.visit_fn_ret_ty(&function_declaration.output)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_fn<V>(visitor: &mut V, kind: FnKind, declaration: &FnDecl, _span: Span)
|
pub fn walk_fn<'a, V>(visitor: &mut V, kind: FnKind<'a>, declaration: &'a FnDecl, _span: Span)
|
||||||
where V: Visitor,
|
where V: Visitor<'a>,
|
||||||
{
|
{
|
||||||
match kind {
|
match kind {
|
||||||
FnKind::ItemFn(_, generics, _, _, _, _, body) => {
|
FnKind::ItemFn(_, generics, _, _, _, _, body) => {
|
||||||
|
@ -539,7 +552,7 @@ pub fn walk_fn<V>(visitor: &mut V, kind: FnKind, declaration: &FnDecl, _span: Sp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_trait_item<V: Visitor>(visitor: &mut V, trait_item: &TraitItem) {
|
pub fn walk_trait_item<'a, V: Visitor<'a>>(visitor: &mut V, trait_item: &'a TraitItem) {
|
||||||
visitor.visit_ident(trait_item.span, trait_item.ident);
|
visitor.visit_ident(trait_item.span, trait_item.ident);
|
||||||
walk_list!(visitor, visit_attribute, &trait_item.attrs);
|
walk_list!(visitor, visit_attribute, &trait_item.attrs);
|
||||||
match trait_item.node {
|
match trait_item.node {
|
||||||
|
@ -565,7 +578,7 @@ pub fn walk_trait_item<V: Visitor>(visitor: &mut V, trait_item: &TraitItem) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_impl_item<V: Visitor>(visitor: &mut V, impl_item: &ImplItem) {
|
pub fn walk_impl_item<'a, V: Visitor<'a>>(visitor: &mut V, impl_item: &'a ImplItem) {
|
||||||
visitor.visit_vis(&impl_item.vis);
|
visitor.visit_vis(&impl_item.vis);
|
||||||
visitor.visit_ident(impl_item.span, impl_item.ident);
|
visitor.visit_ident(impl_item.span, impl_item.ident);
|
||||||
walk_list!(visitor, visit_attribute, &impl_item.attrs);
|
walk_list!(visitor, visit_attribute, &impl_item.attrs);
|
||||||
|
@ -587,22 +600,22 @@ pub fn walk_impl_item<V: Visitor>(visitor: &mut V, impl_item: &ImplItem) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_struct_def<V: Visitor>(visitor: &mut V, struct_definition: &VariantData) {
|
pub fn walk_struct_def<'a, V: Visitor<'a>>(visitor: &mut V, struct_definition: &'a VariantData) {
|
||||||
walk_list!(visitor, visit_struct_field, struct_definition.fields());
|
walk_list!(visitor, visit_struct_field, struct_definition.fields());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_struct_field<V: Visitor>(visitor: &mut V, struct_field: &StructField) {
|
pub fn walk_struct_field<'a, V: Visitor<'a>>(visitor: &mut V, struct_field: &'a StructField) {
|
||||||
visitor.visit_vis(&struct_field.vis);
|
visitor.visit_vis(&struct_field.vis);
|
||||||
walk_opt_ident(visitor, struct_field.span, struct_field.ident);
|
walk_opt_ident(visitor, struct_field.span, struct_field.ident);
|
||||||
visitor.visit_ty(&struct_field.ty);
|
visitor.visit_ty(&struct_field.ty);
|
||||||
walk_list!(visitor, visit_attribute, &struct_field.attrs);
|
walk_list!(visitor, visit_attribute, &struct_field.attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_block<V: Visitor>(visitor: &mut V, block: &Block) {
|
pub fn walk_block<'a, V: Visitor<'a>>(visitor: &mut V, block: &'a Block) {
|
||||||
walk_list!(visitor, visit_stmt, &block.stmts);
|
walk_list!(visitor, visit_stmt, &block.stmts);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_stmt<V: Visitor>(visitor: &mut V, statement: &Stmt) {
|
pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) {
|
||||||
match statement.node {
|
match statement.node {
|
||||||
StmtKind::Local(ref local) => visitor.visit_local(local),
|
StmtKind::Local(ref local) => visitor.visit_local(local),
|
||||||
StmtKind::Item(ref item) => visitor.visit_item(item),
|
StmtKind::Item(ref item) => visitor.visit_item(item),
|
||||||
|
@ -619,11 +632,11 @@ pub fn walk_stmt<V: Visitor>(visitor: &mut V, statement: &Stmt) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_mac<V: Visitor>(_: &mut V, _: &Mac) {
|
pub fn walk_mac<'a, V: Visitor<'a>>(_: &mut V, _: &Mac) {
|
||||||
// Empty!
|
// Empty!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_expr<V: Visitor>(visitor: &mut V, expression: &Expr) {
|
pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
|
||||||
for attr in expression.attrs.iter() {
|
for attr in expression.attrs.iter() {
|
||||||
visitor.visit_attribute(attr);
|
visitor.visit_attribute(attr);
|
||||||
}
|
}
|
||||||
|
@ -776,14 +789,14 @@ pub fn walk_expr<V: Visitor>(visitor: &mut V, expression: &Expr) {
|
||||||
visitor.visit_expr_post(expression)
|
visitor.visit_expr_post(expression)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_arm<V: Visitor>(visitor: &mut V, arm: &Arm) {
|
pub fn walk_arm<'a, V: Visitor<'a>>(visitor: &mut V, arm: &'a Arm) {
|
||||||
walk_list!(visitor, visit_pat, &arm.pats);
|
walk_list!(visitor, visit_pat, &arm.pats);
|
||||||
walk_list!(visitor, visit_expr, &arm.guard);
|
walk_list!(visitor, visit_expr, &arm.guard);
|
||||||
visitor.visit_expr(&arm.body);
|
visitor.visit_expr(&arm.body);
|
||||||
walk_list!(visitor, visit_attribute, &arm.attrs);
|
walk_list!(visitor, visit_attribute, &arm.attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_vis<V: Visitor>(visitor: &mut V, vis: &Visibility) {
|
pub fn walk_vis<'a, V: Visitor<'a>>(visitor: &mut V, vis: &'a Visibility) {
|
||||||
if let Visibility::Restricted { ref path, id } = *vis {
|
if let Visibility::Restricted { ref path, id } = *vis {
|
||||||
visitor.visit_path(path, id);
|
visitor.visit_path(path, id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ use syntax::visit::Visitor;
|
||||||
|
|
||||||
struct MarkAttrs<'a>(&'a [ast::Name]);
|
struct MarkAttrs<'a>(&'a [ast::Name]);
|
||||||
|
|
||||||
impl<'a> Visitor for MarkAttrs<'a> {
|
impl<'a> Visitor<'a> for MarkAttrs<'a> {
|
||||||
fn visit_attribute(&mut self, attr: &Attribute) {
|
fn visit_attribute(&mut self, attr: &Attribute) {
|
||||||
if self.0.contains(&attr.name()) {
|
if self.0.contains(&attr.name()) {
|
||||||
mark_used(attr);
|
mark_used(attr);
|
||||||
|
@ -101,4 +101,3 @@ impl MultiItemModifier for CustomDerive {
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -361,8 +361,8 @@ fn find_type_parameters(ty: &ast::Ty,
|
||||||
types: Vec<P<ast::Ty>>,
|
types: Vec<P<ast::Ty>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b> visit::Visitor for Visitor<'a, 'b> {
|
impl<'a, 'b> visit::Visitor<'a> for Visitor<'a, 'b> {
|
||||||
fn visit_ty(&mut self, ty: &ast::Ty) {
|
fn visit_ty(&mut self, ty: &'a ast::Ty) {
|
||||||
match ty.node {
|
match ty.node {
|
||||||
ast::TyKind::Path(_, ref path) if !path.global => {
|
ast::TyKind::Path(_, ref path) if !path.global => {
|
||||||
if let Some(segment) = path.segments.first() {
|
if let Some(segment) = path.segments.first() {
|
||||||
|
|
|
@ -52,14 +52,17 @@ pub fn modify(sess: &ParseSess,
|
||||||
let ecfg = ExpansionConfig::default("proc_macro".to_string());
|
let ecfg = ExpansionConfig::default("proc_macro".to_string());
|
||||||
let mut cx = ExtCtxt::new(sess, ecfg, resolver);
|
let mut cx = ExtCtxt::new(sess, ecfg, resolver);
|
||||||
|
|
||||||
let mut collect = CollectCustomDerives {
|
let derives = {
|
||||||
derives: Vec::new(),
|
let mut collect = CollectCustomDerives {
|
||||||
in_root: true,
|
derives: Vec::new(),
|
||||||
handler: handler,
|
in_root: true,
|
||||||
is_proc_macro_crate: is_proc_macro_crate,
|
handler: handler,
|
||||||
is_test_crate: is_test_crate,
|
is_proc_macro_crate: is_proc_macro_crate,
|
||||||
|
is_test_crate: is_test_crate,
|
||||||
|
};
|
||||||
|
visit::walk_crate(&mut collect, &krate);
|
||||||
|
collect.derives
|
||||||
};
|
};
|
||||||
visit::walk_crate(&mut collect, &krate);
|
|
||||||
|
|
||||||
if !is_proc_macro_crate {
|
if !is_proc_macro_crate {
|
||||||
return krate
|
return krate
|
||||||
|
@ -79,7 +82,7 @@ pub fn modify(sess: &ParseSess,
|
||||||
return krate;
|
return krate;
|
||||||
}
|
}
|
||||||
|
|
||||||
krate.module.items.push(mk_registrar(&mut cx, &collect.derives));
|
krate.module.items.push(mk_registrar(&mut cx, &derives));
|
||||||
|
|
||||||
if krate.exported_macros.len() > 0 {
|
if krate.exported_macros.len() > 0 {
|
||||||
handler.err("cannot export macro_rules! macros from a `proc-macro` \
|
handler.err("cannot export macro_rules! macros from a `proc-macro` \
|
||||||
|
@ -103,8 +106,8 @@ impl<'a> CollectCustomDerives<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Visitor for CollectCustomDerives<'a> {
|
impl<'a> Visitor<'a> for CollectCustomDerives<'a> {
|
||||||
fn visit_item(&mut self, item: &ast::Item) {
|
fn visit_item(&mut self, item: &'a ast::Item) {
|
||||||
// First up, make sure we're checking a bare function. If we're not then
|
// First up, make sure we're checking a bare function. If we're not then
|
||||||
// we're just not interested in this item.
|
// we're just not interested in this item.
|
||||||
//
|
//
|
||||||
|
@ -240,7 +243,7 @@ impl<'a> Visitor for CollectCustomDerives<'a> {
|
||||||
visit::walk_item(self, item);
|
visit::walk_item(self, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_mod(&mut self, m: &ast::Mod, _s: Span, id: NodeId) {
|
fn visit_mod(&mut self, m: &'a ast::Mod, _s: Span, id: NodeId) {
|
||||||
let mut prev_in_root = self.in_root;
|
let mut prev_in_root = self.in_root;
|
||||||
if id != ast::CRATE_NODE_ID {
|
if id != ast::CRATE_NODE_ID {
|
||||||
prev_in_root = mem::replace(&mut self.in_root, false);
|
prev_in_root = mem::replace(&mut self.in_root, false);
|
||||||
|
|
|
@ -33,7 +33,7 @@ impl LintPass for Pass {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for Pass {
|
impl LateLintPass for Pass {
|
||||||
fn check_crate(&mut self, cx: &LateContext, krate: &hir::Crate) {
|
fn check_crate<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, krate: &'tcx hir::Crate) {
|
||||||
if !attr::contains_name(&krate.attrs, "crate_okay") {
|
if !attr::contains_name(&krate.attrs, "crate_okay") {
|
||||||
cx.span_lint(CRATE_NOT_OKAY, krate.span,
|
cx.span_lint(CRATE_NOT_OKAY, krate.span,
|
||||||
"crate is not marked with #![crate_okay]");
|
"crate is not marked with #![crate_okay]");
|
||||||
|
|
|
@ -35,7 +35,7 @@ impl LintPass for Pass {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for Pass {
|
impl LateLintPass for Pass {
|
||||||
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
|
fn check_item<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item) {
|
||||||
match &*it.name.as_str() {
|
match &*it.name.as_str() {
|
||||||
"lintme" => cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'"),
|
"lintme" => cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'"),
|
||||||
"pleaselintme" => cx.span_lint(PLEASE_LINT, it.span, "item is named 'pleaselintme'"),
|
"pleaselintme" => cx.span_lint(PLEASE_LINT, it.span, "item is named 'pleaselintme'"),
|
||||||
|
|
|
@ -33,7 +33,7 @@ impl LintPass for Pass {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for Pass {
|
impl LateLintPass for Pass {
|
||||||
fn check_crate(&mut self, cx: &LateContext, krate: &hir::Crate) {
|
fn check_crate<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, krate: &'tcx hir::Crate) {
|
||||||
if !attr::contains_name(&krate.attrs, "crate_okay") {
|
if !attr::contains_name(&krate.attrs, "crate_okay") {
|
||||||
cx.span_lint(CRATE_NOT_OKAY, krate.span,
|
cx.span_lint(CRATE_NOT_OKAY, krate.span,
|
||||||
"crate is not marked with #![crate_okay]");
|
"crate is not marked with #![crate_okay]");
|
||||||
|
|
|
@ -35,7 +35,7 @@ impl LintPass for Pass {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for Pass {
|
impl LateLintPass for Pass {
|
||||||
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
|
fn check_item<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item) {
|
||||||
match &*it.name.as_str() {
|
match &*it.name.as_str() {
|
||||||
"lintme" => cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'"),
|
"lintme" => cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'"),
|
||||||
"pleaselintme" => cx.span_lint(PLEASE_LINT, it.span, "item is named 'pleaselintme'"),
|
"pleaselintme" => cx.span_lint(PLEASE_LINT, it.span, "item is named 'pleaselintme'"),
|
||||||
|
|
|
@ -40,9 +40,9 @@ impl LintPass for Pass {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for Pass {
|
impl LateLintPass for Pass {
|
||||||
fn check_fn(&mut self, cx: &LateContext,
|
fn check_fn<'a, 'tcx: 'a>(&mut self, cx: &LateContext<'a, 'tcx>,
|
||||||
fk: FnKind, _: &hir::FnDecl, expr: &hir::Expr,
|
fk: FnKind<'tcx>, _: &'tcx hir::FnDecl, expr: &'tcx hir::Expr,
|
||||||
span: Span, node: ast::NodeId)
|
span: Span, node: ast::NodeId)
|
||||||
{
|
{
|
||||||
if let FnKind::Closure(..) = fk { return }
|
if let FnKind::Closure(..) = fk { return }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue