Skip to content

Commit

Permalink
Auto merge of #38191 - oli-obk:clippy_is_sad, r=eddyb
Browse files Browse the repository at this point in the history
annotate stricter lifetimes on LateLintPass methods to allow them to forward to a Visitor

this unblocks clippy (rustup blocked after #37918)

clippy has lots of lints that internally call an `intravisit::Visitor`, but the current lifetimes on `LateLintPass` methods conflicted with the required lifetimes (there was no connection between the HIR elements and the `TyCtxt`)

r? @Manishearth
  • Loading branch information
bors committed Dec 7, 2016
2 parents 535b6d3 + 0f7a18b commit 7b06438
Show file tree
Hide file tree
Showing 32 changed files with 417 additions and 365 deletions.
4 changes: 2 additions & 2 deletions src/librustc/hir/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ impl<'a> CheckAttrVisitor<'a> {
}
}

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

impl<'lcx, 'interner> Visitor for ItemLowerer<'lcx, 'interner> {
fn visit_item(&mut self, item: &Item) {
impl<'lcx, 'interner> Visitor<'lcx> for ItemLowerer<'lcx, 'interner> {
fn visit_item(&mut self, item: &'lcx Item) {
let hir_item = self.lctx.lower_item(item);
self.lctx.items.insert(item.id, hir_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 hir_item = self.lctx.lower_impl_item(item);
self.lctx.impl_items.insert(id, hir_item);
Expand Down
24 changes: 12 additions & 12 deletions src/librustc/hir/map/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ impl<'a> DefCollector<'a> {
}
}

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

// Pick the def data. This need not be unique, but the more
Expand Down Expand Up @@ -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,
DefPathData::ValueNs(foreign_item.ident.name.as_str()));

Expand All @@ -220,15 +220,15 @@ 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() {
self.create_def(ty_param.id, DefPathData::TypeParam(ty_param.ident.name.as_str()));
}

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 {
TraitItemKind::Method(..) | TraitItemKind::Const(..) =>
DefPathData::ValueNs(ti.ident.name.as_str()),
Expand All @@ -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 {
ImplItemKind::Method(..) | ImplItemKind::Const(..) =>
DefPathData::ValueNs(ii.ident.name.as_str()),
Expand All @@ -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;

match pat.node {
Expand All @@ -280,7 +280,7 @@ impl<'a> visit::Visitor for DefCollector<'a> {
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;

match expr.node {
Expand All @@ -297,7 +297,7 @@ impl<'a> visit::Visitor for DefCollector<'a> {
self.parent_def = parent_def;
}

fn visit_ty(&mut self, ty: &Ty) {
fn visit_ty(&mut self, ty: &'a Ty) {
match ty.node {
TyKind::Mac(..) => return self.visit_macro_invoc(ty.id, false),
TyKind::Array(_, ref length) => self.visit_ast_const_integer(length),
Expand All @@ -309,15 +309,15 @@ impl<'a> visit::Visitor for DefCollector<'a> {
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()));
}

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()));
}

fn visit_stmt(&mut self, stmt: &Stmt) {
fn visit_stmt(&mut self, stmt: &'a Stmt) {
match stmt.node {
StmtKind::Mac(..) => self.visit_macro_invoc(stmt.id, false),
_ => visit::walk_stmt(self, stmt),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,4 @@ impl LintPass for HardwiredLints {
}
}

impl LateLintPass for HardwiredLints {}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HardwiredLints {}
72 changes: 36 additions & 36 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,13 +496,13 @@ pub fn raw_struct_lint<'a, S>(sess: &'a Session,
err
}

pub trait LintContext: Sized {
pub trait LintContext<'tcx>: Sized {
fn sess(&self) -> &Session;
fn lints(&self) -> &LintStore;
fn mut_lints(&mut self) -> &mut LintStore;
fn level_stack(&mut self) -> &mut Vec<(LintId, LevelSource)>;
fn enter_attrs(&mut self, attrs: &[ast::Attribute]);
fn exit_attrs(&mut self, attrs: &[ast::Attribute]);
fn enter_attrs(&mut self, attrs: &'tcx [ast::Attribute]);
fn exit_attrs(&mut self, attrs: &'tcx [ast::Attribute]);

/// Get the level of `lint` at the current position of the lint
/// traversal.
Expand Down Expand Up @@ -606,7 +606,7 @@ pub trait LintContext: Sized {
/// current lint context, call the provided function, then reset the
/// lints in effect to their previous state.
fn with_lint_attrs<F>(&mut self,
attrs: &[ast::Attribute],
attrs: &'tcx [ast::Attribute],
f: F)
where F: FnOnce(&mut Self),
{
Expand Down Expand Up @@ -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.
fn sess(&self) -> &Session {
&self.tcx.sess
Expand All @@ -747,18 +747,18 @@ impl<'a, 'tcx> LintContext for LateContext<'a, 'tcx> {
&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);
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);
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.
fn sess(&self) -> &Session {
&self.sess
Expand All @@ -776,12 +776,12 @@ impl<'a> LintContext for EarlyContext<'a> {
&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);
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);
run_lints!(self, exit_lint_attrs, early_passes, attrs);
}
Expand Down Expand Up @@ -949,80 +949,80 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> {
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);
run_lints!(self, check_attribute, late_passes, attr);
}
}

impl<'a> ast_visit::Visitor for EarlyContext<'a> {
fn visit_item(&mut self, it: &ast::Item) {
impl<'a> ast_visit::Visitor<'a> for EarlyContext<'a> {
fn visit_item(&mut self, it: &'a ast::Item) {
self.with_lint_attrs(&it.attrs, |cx| {
run_lints!(cx, check_item, early_passes, it);
ast_visit::walk_item(cx, it);
run_lints!(cx, check_item_post, early_passes, it);
})
}

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| {
run_lints!(cx, check_foreign_item, early_passes, it);
ast_visit::walk_foreign_item(cx, it);
run_lints!(cx, check_foreign_item_post, early_passes, it);
})
}

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);
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| {
run_lints!(cx, check_expr, early_passes, 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);
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) {
run_lints!(self, check_fn, early_passes, fk, decl, span, id);
ast_visit::walk_fn(self, fk, decl, span);
run_lints!(self, check_fn_post, early_passes, fk, decl, span, id);
}

fn visit_variant_data(&mut self,
s: &ast::VariantData,
s: &'a ast::VariantData,
ident: ast::Ident,
g: &ast::Generics,
g: &'a ast::Generics,
item_id: ast::NodeId,
_: Span) {
run_lints!(self, check_struct_def, early_passes, s, ident, g, item_id);
ast_visit::walk_struct_def(self, s);
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| {
run_lints!(cx, check_struct_field, early_passes, 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| {
run_lints!(cx, check_variant, early_passes, v, g);
ast_visit::walk_variant(cx, v, g, item_id);
run_lints!(cx, check_variant_post, early_passes, v, g);
})
}

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);
ast_visit::walk_ty(self, t);
}
Expand All @@ -1031,74 +1031,74 @@ impl<'a> ast_visit::Visitor for EarlyContext<'a> {
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);
ast_visit::walk_mod(self, m);
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| {
run_lints!(cx, check_local, early_passes, 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);
ast_visit::walk_block(self, 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);
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);
}

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);
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| {
run_lints!(cx, check_trait_item, early_passes, trait_item);
ast_visit::walk_trait_item(cx, trait_item);
run_lints!(cx, check_trait_item_post, early_passes, trait_item);
});
}

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| {
run_lints!(cx, check_impl_item, early_passes, impl_item);
ast_visit::walk_impl_item(cx, impl_item);
run_lints!(cx, check_impl_item_post, early_passes, impl_item);
});
}

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);
}

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);
}

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);
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);
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);
}
}
Expand Down
Loading

0 comments on commit 7b06438

Please sign in to comment.