Skip to content

Commit 7b06438

Browse files
committed
Auto merge of #38191 - oli-obk:clippy_is_sad, r=eddyb
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
2 parents 535b6d3 + 0f7a18b commit 7b06438

File tree

32 files changed

+417
-365
lines changed

32 files changed

+417
-365
lines changed

src/librustc/hir/check_attr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ impl<'a> CheckAttrVisitor<'a> {
129129
}
130130
}
131131

132-
impl<'a> Visitor for CheckAttrVisitor<'a> {
133-
fn visit_item(&mut self, item: &ast::Item) {
132+
impl<'a> Visitor<'a> for CheckAttrVisitor<'a> {
133+
fn visit_item(&mut self, item: &'a ast::Item) {
134134
let target = Target::from_item(item);
135135
for attr in &item.attrs {
136136
self.check_attribute(attr, target);

src/librustc/hir/lowering.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,14 @@ impl<'a> LoweringContext<'a> {
143143
lctx: &'lcx mut LoweringContext<'interner>,
144144
}
145145

146-
impl<'lcx, 'interner> Visitor for ItemLowerer<'lcx, 'interner> {
147-
fn visit_item(&mut self, item: &Item) {
146+
impl<'lcx, 'interner> Visitor<'lcx> for ItemLowerer<'lcx, 'interner> {
147+
fn visit_item(&mut self, item: &'lcx Item) {
148148
let hir_item = self.lctx.lower_item(item);
149149
self.lctx.items.insert(item.id, hir_item);
150150
visit::walk_item(self, item);
151151
}
152152

153-
fn visit_impl_item(&mut self, item: &ImplItem) {
153+
fn visit_impl_item(&mut self, item: &'lcx ImplItem) {
154154
let id = self.lctx.lower_impl_item_ref(item).id;
155155
let hir_item = self.lctx.lower_impl_item(item);
156156
self.lctx.impl_items.insert(id, hir_item);

src/librustc/hir/map/def_collector.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ impl<'a> DefCollector<'a> {
135135
}
136136
}
137137

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

142142
// Pick the def data. This need not be unique, but the more
@@ -211,7 +211,7 @@ impl<'a> visit::Visitor for DefCollector<'a> {
211211
});
212212
}
213213

214-
fn visit_foreign_item(&mut self, foreign_item: &ForeignItem) {
214+
fn visit_foreign_item(&mut self, foreign_item: &'a ForeignItem) {
215215
let def = self.create_def(foreign_item.id,
216216
DefPathData::ValueNs(foreign_item.ident.name.as_str()));
217217

@@ -220,15 +220,15 @@ impl<'a> visit::Visitor for DefCollector<'a> {
220220
});
221221
}
222222

223-
fn visit_generics(&mut self, generics: &Generics) {
223+
fn visit_generics(&mut self, generics: &'a Generics) {
224224
for ty_param in generics.ty_params.iter() {
225225
self.create_def(ty_param.id, DefPathData::TypeParam(ty_param.ident.name.as_str()));
226226
}
227227

228228
visit::walk_generics(self, generics);
229229
}
230230

231-
fn visit_trait_item(&mut self, ti: &TraitItem) {
231+
fn visit_trait_item(&mut self, ti: &'a TraitItem) {
232232
let def_data = match ti.node {
233233
TraitItemKind::Method(..) | TraitItemKind::Const(..) =>
234234
DefPathData::ValueNs(ti.ident.name.as_str()),
@@ -246,7 +246,7 @@ impl<'a> visit::Visitor for DefCollector<'a> {
246246
});
247247
}
248248

249-
fn visit_impl_item(&mut self, ii: &ImplItem) {
249+
fn visit_impl_item(&mut self, ii: &'a ImplItem) {
250250
let def_data = match ii.node {
251251
ImplItemKind::Method(..) | ImplItemKind::Const(..) =>
252252
DefPathData::ValueNs(ii.ident.name.as_str()),
@@ -264,7 +264,7 @@ impl<'a> visit::Visitor for DefCollector<'a> {
264264
});
265265
}
266266

267-
fn visit_pat(&mut self, pat: &Pat) {
267+
fn visit_pat(&mut self, pat: &'a Pat) {
268268
let parent_def = self.parent_def;
269269

270270
match pat.node {
@@ -280,7 +280,7 @@ impl<'a> visit::Visitor for DefCollector<'a> {
280280
self.parent_def = parent_def;
281281
}
282282

283-
fn visit_expr(&mut self, expr: &Expr) {
283+
fn visit_expr(&mut self, expr: &'a Expr) {
284284
let parent_def = self.parent_def;
285285

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

300-
fn visit_ty(&mut self, ty: &Ty) {
300+
fn visit_ty(&mut self, ty: &'a Ty) {
301301
match ty.node {
302302
TyKind::Mac(..) => return self.visit_macro_invoc(ty.id, false),
303303
TyKind::Array(_, ref length) => self.visit_ast_const_integer(length),
@@ -309,15 +309,15 @@ impl<'a> visit::Visitor for DefCollector<'a> {
309309
visit::walk_ty(self, ty);
310310
}
311311

312-
fn visit_lifetime_def(&mut self, def: &LifetimeDef) {
312+
fn visit_lifetime_def(&mut self, def: &'a LifetimeDef) {
313313
self.create_def(def.lifetime.id, DefPathData::LifetimeDef(def.lifetime.name.as_str()));
314314
}
315315

316-
fn visit_macro_def(&mut self, macro_def: &MacroDef) {
316+
fn visit_macro_def(&mut self, macro_def: &'a MacroDef) {
317317
self.create_def(macro_def.id, DefPathData::MacroDef(macro_def.ident.name.as_str()));
318318
}
319319

320-
fn visit_stmt(&mut self, stmt: &Stmt) {
320+
fn visit_stmt(&mut self, stmt: &'a Stmt) {
321321
match stmt.node {
322322
StmtKind::Mac(..) => self.visit_macro_invoc(stmt.id, false),
323323
_ => visit::walk_stmt(self, stmt),

src/librustc/lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,4 @@ impl LintPass for HardwiredLints {
262262
}
263263
}
264264

265-
impl LateLintPass for HardwiredLints {}
265+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HardwiredLints {}

src/librustc/lint/context.rs

+36-36
Original file line numberDiff line numberDiff line change
@@ -496,13 +496,13 @@ pub fn raw_struct_lint<'a, S>(sess: &'a Session,
496496
err
497497
}
498498

499-
pub trait LintContext: Sized {
499+
pub trait LintContext<'tcx>: Sized {
500500
fn sess(&self) -> &Session;
501501
fn lints(&self) -> &LintStore;
502502
fn mut_lints(&mut self) -> &mut LintStore;
503503
fn level_stack(&mut self) -> &mut Vec<(LintId, LevelSource)>;
504-
fn enter_attrs(&mut self, attrs: &[ast::Attribute]);
505-
fn exit_attrs(&mut self, attrs: &[ast::Attribute]);
504+
fn enter_attrs(&mut self, attrs: &'tcx [ast::Attribute]);
505+
fn exit_attrs(&mut self, attrs: &'tcx [ast::Attribute]);
506506

507507
/// Get the level of `lint` at the current position of the lint
508508
/// traversal.
@@ -606,7 +606,7 @@ pub trait LintContext: Sized {
606606
/// current lint context, call the provided function, then reset the
607607
/// lints in effect to their previous state.
608608
fn with_lint_attrs<F>(&mut self,
609-
attrs: &[ast::Attribute],
609+
attrs: &'tcx [ast::Attribute],
610610
f: F)
611611
where F: FnOnce(&mut Self),
612612
{
@@ -729,7 +729,7 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> {
729729
}
730730
}
731731

732-
impl<'a, 'tcx> LintContext for LateContext<'a, 'tcx> {
732+
impl<'a, 'tcx> LintContext<'tcx> for LateContext<'a, 'tcx> {
733733
/// Get the overall compiler `Session` object.
734734
fn sess(&self) -> &Session {
735735
&self.tcx.sess
@@ -747,18 +747,18 @@ impl<'a, 'tcx> LintContext for LateContext<'a, 'tcx> {
747747
&mut self.level_stack
748748
}
749749

750-
fn enter_attrs(&mut self, attrs: &[ast::Attribute]) {
750+
fn enter_attrs(&mut self, attrs: &'tcx [ast::Attribute]) {
751751
debug!("late context: enter_attrs({:?})", attrs);
752752
run_lints!(self, enter_lint_attrs, late_passes, attrs);
753753
}
754754

755-
fn exit_attrs(&mut self, attrs: &[ast::Attribute]) {
755+
fn exit_attrs(&mut self, attrs: &'tcx [ast::Attribute]) {
756756
debug!("late context: exit_attrs({:?})", attrs);
757757
run_lints!(self, exit_lint_attrs, late_passes, attrs);
758758
}
759759
}
760760

761-
impl<'a> LintContext for EarlyContext<'a> {
761+
impl<'a> LintContext<'a> for EarlyContext<'a> {
762762
/// Get the overall compiler `Session` object.
763763
fn sess(&self) -> &Session {
764764
&self.sess
@@ -776,12 +776,12 @@ impl<'a> LintContext for EarlyContext<'a> {
776776
&mut self.level_stack
777777
}
778778

779-
fn enter_attrs(&mut self, attrs: &[ast::Attribute]) {
779+
fn enter_attrs(&mut self, attrs: &'a [ast::Attribute]) {
780780
debug!("early context: enter_attrs({:?})", attrs);
781781
run_lints!(self, enter_lint_attrs, early_passes, attrs);
782782
}
783783

784-
fn exit_attrs(&mut self, attrs: &[ast::Attribute]) {
784+
fn exit_attrs(&mut self, attrs: &'a [ast::Attribute]) {
785785
debug!("early context: exit_attrs({:?})", attrs);
786786
run_lints!(self, exit_lint_attrs, early_passes, attrs);
787787
}
@@ -949,80 +949,80 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> {
949949
hir_visit::walk_path(self, p);
950950
}
951951

952-
fn visit_attribute(&mut self, attr: &ast::Attribute) {
952+
fn visit_attribute(&mut self, attr: &'tcx ast::Attribute) {
953953
check_lint_name_attribute(self, attr);
954954
run_lints!(self, check_attribute, late_passes, attr);
955955
}
956956
}
957957

958-
impl<'a> ast_visit::Visitor for EarlyContext<'a> {
959-
fn visit_item(&mut self, it: &ast::Item) {
958+
impl<'a> ast_visit::Visitor<'a> for EarlyContext<'a> {
959+
fn visit_item(&mut self, it: &'a ast::Item) {
960960
self.with_lint_attrs(&it.attrs, |cx| {
961961
run_lints!(cx, check_item, early_passes, it);
962962
ast_visit::walk_item(cx, it);
963963
run_lints!(cx, check_item_post, early_passes, it);
964964
})
965965
}
966966

967-
fn visit_foreign_item(&mut self, it: &ast::ForeignItem) {
967+
fn visit_foreign_item(&mut self, it: &'a ast::ForeignItem) {
968968
self.with_lint_attrs(&it.attrs, |cx| {
969969
run_lints!(cx, check_foreign_item, early_passes, it);
970970
ast_visit::walk_foreign_item(cx, it);
971971
run_lints!(cx, check_foreign_item_post, early_passes, it);
972972
})
973973
}
974974

975-
fn visit_pat(&mut self, p: &ast::Pat) {
975+
fn visit_pat(&mut self, p: &'a ast::Pat) {
976976
run_lints!(self, check_pat, early_passes, p);
977977
ast_visit::walk_pat(self, p);
978978
}
979979

980-
fn visit_expr(&mut self, e: &ast::Expr) {
980+
fn visit_expr(&mut self, e: &'a ast::Expr) {
981981
self.with_lint_attrs(&e.attrs, |cx| {
982982
run_lints!(cx, check_expr, early_passes, e);
983983
ast_visit::walk_expr(cx, e);
984984
})
985985
}
986986

987-
fn visit_stmt(&mut self, s: &ast::Stmt) {
987+
fn visit_stmt(&mut self, s: &'a ast::Stmt) {
988988
run_lints!(self, check_stmt, early_passes, s);
989989
ast_visit::walk_stmt(self, s);
990990
}
991991

992-
fn visit_fn(&mut self, fk: ast_visit::FnKind, decl: &ast::FnDecl,
992+
fn visit_fn(&mut self, fk: ast_visit::FnKind<'a>, decl: &'a ast::FnDecl,
993993
span: Span, id: ast::NodeId) {
994994
run_lints!(self, check_fn, early_passes, fk, decl, span, id);
995995
ast_visit::walk_fn(self, fk, decl, span);
996996
run_lints!(self, check_fn_post, early_passes, fk, decl, span, id);
997997
}
998998

999999
fn visit_variant_data(&mut self,
1000-
s: &ast::VariantData,
1000+
s: &'a ast::VariantData,
10011001
ident: ast::Ident,
1002-
g: &ast::Generics,
1002+
g: &'a ast::Generics,
10031003
item_id: ast::NodeId,
10041004
_: Span) {
10051005
run_lints!(self, check_struct_def, early_passes, s, ident, g, item_id);
10061006
ast_visit::walk_struct_def(self, s);
10071007
run_lints!(self, check_struct_def_post, early_passes, s, ident, g, item_id);
10081008
}
10091009

1010-
fn visit_struct_field(&mut self, s: &ast::StructField) {
1010+
fn visit_struct_field(&mut self, s: &'a ast::StructField) {
10111011
self.with_lint_attrs(&s.attrs, |cx| {
10121012
run_lints!(cx, check_struct_field, early_passes, s);
10131013
ast_visit::walk_struct_field(cx, s);
10141014
})
10151015
}
10161016

1017-
fn visit_variant(&mut self, v: &ast::Variant, g: &ast::Generics, item_id: ast::NodeId) {
1017+
fn visit_variant(&mut self, v: &'a ast::Variant, g: &'a ast::Generics, item_id: ast::NodeId) {
10181018
self.with_lint_attrs(&v.node.attrs, |cx| {
10191019
run_lints!(cx, check_variant, early_passes, v, g);
10201020
ast_visit::walk_variant(cx, v, g, item_id);
10211021
run_lints!(cx, check_variant_post, early_passes, v, g);
10221022
})
10231023
}
10241024

1025-
fn visit_ty(&mut self, t: &ast::Ty) {
1025+
fn visit_ty(&mut self, t: &'a ast::Ty) {
10261026
run_lints!(self, check_ty, early_passes, t);
10271027
ast_visit::walk_ty(self, t);
10281028
}
@@ -1031,74 +1031,74 @@ impl<'a> ast_visit::Visitor for EarlyContext<'a> {
10311031
run_lints!(self, check_ident, early_passes, sp, id);
10321032
}
10331033

1034-
fn visit_mod(&mut self, m: &ast::Mod, s: Span, n: ast::NodeId) {
1034+
fn visit_mod(&mut self, m: &'a ast::Mod, s: Span, n: ast::NodeId) {
10351035
run_lints!(self, check_mod, early_passes, m, s, n);
10361036
ast_visit::walk_mod(self, m);
10371037
run_lints!(self, check_mod_post, early_passes, m, s, n);
10381038
}
10391039

1040-
fn visit_local(&mut self, l: &ast::Local) {
1040+
fn visit_local(&mut self, l: &'a ast::Local) {
10411041
self.with_lint_attrs(&l.attrs, |cx| {
10421042
run_lints!(cx, check_local, early_passes, l);
10431043
ast_visit::walk_local(cx, l);
10441044
})
10451045
}
10461046

1047-
fn visit_block(&mut self, b: &ast::Block) {
1047+
fn visit_block(&mut self, b: &'a ast::Block) {
10481048
run_lints!(self, check_block, early_passes, b);
10491049
ast_visit::walk_block(self, b);
10501050
run_lints!(self, check_block_post, early_passes, b);
10511051
}
10521052

1053-
fn visit_arm(&mut self, a: &ast::Arm) {
1053+
fn visit_arm(&mut self, a: &'a ast::Arm) {
10541054
run_lints!(self, check_arm, early_passes, a);
10551055
ast_visit::walk_arm(self, a);
10561056
}
10571057

1058-
fn visit_expr_post(&mut self, e: &ast::Expr) {
1058+
fn visit_expr_post(&mut self, e: &'a ast::Expr) {
10591059
run_lints!(self, check_expr_post, early_passes, e);
10601060
}
10611061

1062-
fn visit_generics(&mut self, g: &ast::Generics) {
1062+
fn visit_generics(&mut self, g: &'a ast::Generics) {
10631063
run_lints!(self, check_generics, early_passes, g);
10641064
ast_visit::walk_generics(self, g);
10651065
}
10661066

1067-
fn visit_trait_item(&mut self, trait_item: &ast::TraitItem) {
1067+
fn visit_trait_item(&mut self, trait_item: &'a ast::TraitItem) {
10681068
self.with_lint_attrs(&trait_item.attrs, |cx| {
10691069
run_lints!(cx, check_trait_item, early_passes, trait_item);
10701070
ast_visit::walk_trait_item(cx, trait_item);
10711071
run_lints!(cx, check_trait_item_post, early_passes, trait_item);
10721072
});
10731073
}
10741074

1075-
fn visit_impl_item(&mut self, impl_item: &ast::ImplItem) {
1075+
fn visit_impl_item(&mut self, impl_item: &'a ast::ImplItem) {
10761076
self.with_lint_attrs(&impl_item.attrs, |cx| {
10771077
run_lints!(cx, check_impl_item, early_passes, impl_item);
10781078
ast_visit::walk_impl_item(cx, impl_item);
10791079
run_lints!(cx, check_impl_item_post, early_passes, impl_item);
10801080
});
10811081
}
10821082

1083-
fn visit_lifetime(&mut self, lt: &ast::Lifetime) {
1083+
fn visit_lifetime(&mut self, lt: &'a ast::Lifetime) {
10841084
run_lints!(self, check_lifetime, early_passes, lt);
10851085
}
10861086

1087-
fn visit_lifetime_def(&mut self, lt: &ast::LifetimeDef) {
1087+
fn visit_lifetime_def(&mut self, lt: &'a ast::LifetimeDef) {
10881088
run_lints!(self, check_lifetime_def, early_passes, lt);
10891089
}
10901090

1091-
fn visit_path(&mut self, p: &ast::Path, id: ast::NodeId) {
1091+
fn visit_path(&mut self, p: &'a ast::Path, id: ast::NodeId) {
10921092
run_lints!(self, check_path, early_passes, p, id);
10931093
ast_visit::walk_path(self, p);
10941094
}
10951095

1096-
fn visit_path_list_item(&mut self, prefix: &ast::Path, item: &ast::PathListItem) {
1096+
fn visit_path_list_item(&mut self, prefix: &'a ast::Path, item: &'a ast::PathListItem) {
10971097
run_lints!(self, check_path_list_item, early_passes, item);
10981098
ast_visit::walk_path_list_item(self, prefix, item);
10991099
}
11001100

1101-
fn visit_attribute(&mut self, attr: &ast::Attribute) {
1101+
fn visit_attribute(&mut self, attr: &'a ast::Attribute) {
11021102
run_lints!(self, check_attribute, early_passes, attr);
11031103
}
11041104
}

0 commit comments

Comments
 (0)