Skip to content

Commit e3e5bd9

Browse files
committed
Cleanup lifetimes around EarlyContextAndPass and EarlyCheckNode
1 parent c448e35 commit e3e5bd9

File tree

1 file changed

+44
-58
lines changed

1 file changed

+44
-58
lines changed

Diff for: compiler/rustc_lint/src/early.rs

+44-58
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ macro_rules! lint_callback { ($cx:expr, $f:ident, $($args:expr),*) => ({
2727

2828
/// Implements the AST traversal for early lint passes. `T` provides the
2929
/// `check_*` methods.
30-
pub struct EarlyContextAndPass<'a, 'b, T: EarlyLintPass> {
31-
context: EarlyContext<'a>,
32-
tcx: Option<TyCtxt<'b>>,
30+
pub struct EarlyContextAndPass<'ecx, 'tcx, T: EarlyLintPass> {
31+
context: EarlyContext<'ecx>,
32+
tcx: Option<TyCtxt<'tcx>>,
3333
pass: T,
3434
}
3535

36-
impl<'a, 'b, T: EarlyLintPass> EarlyContextAndPass<'a, 'b, T> {
36+
impl<'ecx, 'tcx, T: EarlyLintPass> EarlyContextAndPass<'ecx, 'tcx, T> {
3737
// This always-inlined function is for the hot call site.
3838
#[inline(always)]
3939
#[allow(rustc::diagnostic_outside_of_impl)]
@@ -54,7 +54,7 @@ impl<'a, 'b, T: EarlyLintPass> EarlyContextAndPass<'a, 'b, T> {
5454
/// Merge the lints specified by any lint attributes into the
5555
/// current lint context, call the provided function, then reset the
5656
/// lints in effect to their previous state.
57-
fn with_lint_attrs<F>(&mut self, id: ast::NodeId, attrs: &'a [ast::Attribute], f: F)
57+
fn with_lint_attrs<F>(&mut self, id: ast::NodeId, attrs: &'_ [ast::Attribute], f: F)
5858
where
5959
F: FnOnce(&mut Self),
6060
{
@@ -72,65 +72,67 @@ impl<'a, 'b, T: EarlyLintPass> EarlyContextAndPass<'a, 'b, T> {
7272
}
7373
}
7474

75-
impl<'a, 'b, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, 'b, T> {
76-
fn visit_coroutine_kind(&mut self, coroutine_kind: &'a ast::CoroutineKind) -> Self::Result {
75+
impl<'ast, 'ecx, 'tcx, T: EarlyLintPass> ast_visit::Visitor<'ast>
76+
for EarlyContextAndPass<'ecx, 'tcx, T>
77+
{
78+
fn visit_coroutine_kind(&mut self, coroutine_kind: &'ast ast::CoroutineKind) -> Self::Result {
7779
self.check_id(coroutine_kind.closure_id());
7880
}
7981

80-
fn visit_param(&mut self, param: &'a ast::Param) {
82+
fn visit_param(&mut self, param: &'ast ast::Param) {
8183
self.with_lint_attrs(param.id, &param.attrs, |cx| {
8284
lint_callback!(cx, check_param, param);
8385
ast_visit::walk_param(cx, param);
8486
});
8587
}
8688

87-
fn visit_item(&mut self, it: &'a ast::Item) {
89+
fn visit_item(&mut self, it: &'ast ast::Item) {
8890
self.with_lint_attrs(it.id, &it.attrs, |cx| {
8991
lint_callback!(cx, check_item, it);
9092
ast_visit::walk_item(cx, it);
9193
lint_callback!(cx, check_item_post, it);
9294
})
9395
}
9496

95-
fn visit_foreign_item(&mut self, it: &'a ast::ForeignItem) {
97+
fn visit_foreign_item(&mut self, it: &'ast ast::ForeignItem) {
9698
self.with_lint_attrs(it.id, &it.attrs, |cx| {
9799
ast_visit::walk_item(cx, it);
98100
})
99101
}
100102

101-
fn visit_pat(&mut self, p: &'a ast::Pat) {
103+
fn visit_pat(&mut self, p: &'ast ast::Pat) {
102104
lint_callback!(self, check_pat, p);
103105
self.check_id(p.id);
104106
ast_visit::walk_pat(self, p);
105107
lint_callback!(self, check_pat_post, p);
106108
}
107109

108-
fn visit_pat_field(&mut self, field: &'a ast::PatField) {
110+
fn visit_pat_field(&mut self, field: &'ast ast::PatField) {
109111
self.with_lint_attrs(field.id, &field.attrs, |cx| {
110112
ast_visit::walk_pat_field(cx, field);
111113
});
112114
}
113115

114-
fn visit_anon_const(&mut self, c: &'a ast::AnonConst) {
116+
fn visit_anon_const(&mut self, c: &'ast ast::AnonConst) {
115117
self.check_id(c.id);
116118
ast_visit::walk_anon_const(self, c);
117119
}
118120

119-
fn visit_expr(&mut self, e: &'a ast::Expr) {
121+
fn visit_expr(&mut self, e: &'ast ast::Expr) {
120122
self.with_lint_attrs(e.id, &e.attrs, |cx| {
121123
lint_callback!(cx, check_expr, e);
122124
ast_visit::walk_expr(cx, e);
123125
lint_callback!(cx, check_expr_post, e);
124126
})
125127
}
126128

127-
fn visit_expr_field(&mut self, f: &'a ast::ExprField) {
129+
fn visit_expr_field(&mut self, f: &'ast ast::ExprField) {
128130
self.with_lint_attrs(f.id, &f.attrs, |cx| {
129131
ast_visit::walk_expr_field(cx, f);
130132
})
131133
}
132134

133-
fn visit_stmt(&mut self, s: &'a ast::Stmt) {
135+
fn visit_stmt(&mut self, s: &'ast ast::Stmt) {
134136
// Add the statement's lint attributes to our
135137
// current state when checking the statement itself.
136138
// This allows us to handle attributes like
@@ -150,33 +152,33 @@ impl<'a, 'b, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a
150152
ast_visit::walk_stmt(self, s);
151153
}
152154

153-
fn visit_fn(&mut self, fk: ast_visit::FnKind<'a>, span: Span, id: ast::NodeId) {
155+
fn visit_fn(&mut self, fk: ast_visit::FnKind<'ast>, span: Span, id: ast::NodeId) {
154156
lint_callback!(self, check_fn, fk, span, id);
155157
self.check_id(id);
156158
ast_visit::walk_fn(self, fk);
157159
}
158160

159-
fn visit_variant_data(&mut self, s: &'a ast::VariantData) {
161+
fn visit_variant_data(&mut self, s: &'ast ast::VariantData) {
160162
if let Some(ctor_node_id) = s.ctor_node_id() {
161163
self.check_id(ctor_node_id);
162164
}
163165
ast_visit::walk_struct_def(self, s);
164166
}
165167

166-
fn visit_field_def(&mut self, s: &'a ast::FieldDef) {
168+
fn visit_field_def(&mut self, s: &'ast ast::FieldDef) {
167169
self.with_lint_attrs(s.id, &s.attrs, |cx| {
168170
ast_visit::walk_field_def(cx, s);
169171
})
170172
}
171173

172-
fn visit_variant(&mut self, v: &'a ast::Variant) {
174+
fn visit_variant(&mut self, v: &'ast ast::Variant) {
173175
self.with_lint_attrs(v.id, &v.attrs, |cx| {
174176
lint_callback!(cx, check_variant, v);
175177
ast_visit::walk_variant(cx, v);
176178
})
177179
}
178180

179-
fn visit_ty(&mut self, t: &'a ast::Ty) {
181+
fn visit_ty(&mut self, t: &'ast ast::Ty) {
180182
lint_callback!(self, check_ty, t);
181183
self.check_id(t.id);
182184
ast_visit::walk_ty(self, t);
@@ -186,55 +188,55 @@ impl<'a, 'b, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a
186188
lint_callback!(self, check_ident, ident);
187189
}
188190

189-
fn visit_local(&mut self, l: &'a ast::Local) {
191+
fn visit_local(&mut self, l: &'ast ast::Local) {
190192
self.with_lint_attrs(l.id, &l.attrs, |cx| {
191193
lint_callback!(cx, check_local, l);
192194
ast_visit::walk_local(cx, l);
193195
})
194196
}
195197

196-
fn visit_block(&mut self, b: &'a ast::Block) {
198+
fn visit_block(&mut self, b: &'ast ast::Block) {
197199
lint_callback!(self, check_block, b);
198200
self.check_id(b.id);
199201
ast_visit::walk_block(self, b);
200202
}
201203

202-
fn visit_arm(&mut self, a: &'a ast::Arm) {
204+
fn visit_arm(&mut self, a: &'ast ast::Arm) {
203205
self.with_lint_attrs(a.id, &a.attrs, |cx| {
204206
lint_callback!(cx, check_arm, a);
205207
ast_visit::walk_arm(cx, a);
206208
})
207209
}
208210

209-
fn visit_generic_arg(&mut self, arg: &'a ast::GenericArg) {
211+
fn visit_generic_arg(&mut self, arg: &'ast ast::GenericArg) {
210212
lint_callback!(self, check_generic_arg, arg);
211213
ast_visit::walk_generic_arg(self, arg);
212214
}
213215

214-
fn visit_generic_param(&mut self, param: &'a ast::GenericParam) {
216+
fn visit_generic_param(&mut self, param: &'ast ast::GenericParam) {
215217
self.with_lint_attrs(param.id, &param.attrs, |cx| {
216218
lint_callback!(cx, check_generic_param, param);
217219
ast_visit::walk_generic_param(cx, param);
218220
});
219221
}
220222

221-
fn visit_generics(&mut self, g: &'a ast::Generics) {
223+
fn visit_generics(&mut self, g: &'ast ast::Generics) {
222224
lint_callback!(self, check_generics, g);
223225
ast_visit::walk_generics(self, g);
224226
}
225227

226-
fn visit_where_predicate(&mut self, p: &'a ast::WherePredicate) {
228+
fn visit_where_predicate(&mut self, p: &'ast ast::WherePredicate) {
227229
lint_callback!(self, enter_where_predicate, p);
228230
ast_visit::walk_where_predicate(self, p);
229231
lint_callback!(self, exit_where_predicate, p);
230232
}
231233

232-
fn visit_poly_trait_ref(&mut self, t: &'a ast::PolyTraitRef) {
234+
fn visit_poly_trait_ref(&mut self, t: &'ast ast::PolyTraitRef) {
233235
lint_callback!(self, check_poly_trait_ref, t);
234236
ast_visit::walk_poly_trait_ref(self, t);
235237
}
236238

237-
fn visit_assoc_item(&mut self, item: &'a ast::AssocItem, ctxt: ast_visit::AssocCtxt) {
239+
fn visit_assoc_item(&mut self, item: &'ast ast::AssocItem, ctxt: ast_visit::AssocCtxt) {
238240
self.with_lint_attrs(item.id, &item.attrs, |cx| {
239241
match ctxt {
240242
ast_visit::AssocCtxt::Trait => {
@@ -248,32 +250,32 @@ impl<'a, 'b, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a
248250
});
249251
}
250252

251-
fn visit_lifetime(&mut self, lt: &'a ast::Lifetime, _: ast_visit::LifetimeCtxt) {
253+
fn visit_lifetime(&mut self, lt: &'ast ast::Lifetime, _: ast_visit::LifetimeCtxt) {
252254
self.check_id(lt.id);
253255
ast_visit::walk_lifetime(self, lt);
254256
}
255257

256-
fn visit_path(&mut self, p: &'a ast::Path, id: ast::NodeId) {
258+
fn visit_path(&mut self, p: &'ast ast::Path, id: ast::NodeId) {
257259
self.check_id(id);
258260
ast_visit::walk_path(self, p);
259261
}
260262

261-
fn visit_path_segment(&mut self, s: &'a ast::PathSegment) {
263+
fn visit_path_segment(&mut self, s: &'ast ast::PathSegment) {
262264
self.check_id(s.id);
263265
ast_visit::walk_path_segment(self, s);
264266
}
265267

266-
fn visit_attribute(&mut self, attr: &'a ast::Attribute) {
268+
fn visit_attribute(&mut self, attr: &'ast ast::Attribute) {
267269
lint_callback!(self, check_attribute, attr);
268270
ast_visit::walk_attribute(self, attr);
269271
}
270272

271-
fn visit_mac_def(&mut self, mac: &'a ast::MacroDef, id: ast::NodeId) {
273+
fn visit_mac_def(&mut self, mac: &'ast ast::MacroDef, id: ast::NodeId) {
272274
lint_callback!(self, check_mac_def, mac);
273275
self.check_id(id);
274276
}
275277

276-
fn visit_mac_call(&mut self, mac: &'a ast::MacCall) {
278+
fn visit_mac_call(&mut self, mac: &'ast ast::MacCall) {
277279
lint_callback!(self, check_mac, mac);
278280
ast_visit::walk_mac(self, mac);
279281
}
@@ -315,28 +317,18 @@ crate::early_lint_methods!(impl_early_lint_pass, []);
315317
/// This trait generalizes over those nodes.
316318
pub trait EarlyCheckNode<'a>: Copy {
317319
fn id(self) -> ast::NodeId;
318-
fn attrs<'b>(self) -> &'b [ast::Attribute]
319-
where
320-
'a: 'b;
321-
fn check<'b, 'c, T: EarlyLintPass>(self, cx: &mut EarlyContextAndPass<'b, 'c, T>)
322-
where
323-
'a: 'b;
320+
fn attrs(self) -> &'a [ast::Attribute];
321+
fn check<'ecx, 'tcx, T: EarlyLintPass>(self, cx: &mut EarlyContextAndPass<'ecx, 'tcx, T>);
324322
}
325323

326324
impl<'a> EarlyCheckNode<'a> for (&'a ast::Crate, &'a [ast::Attribute]) {
327325
fn id(self) -> ast::NodeId {
328326
ast::CRATE_NODE_ID
329327
}
330-
fn attrs<'b>(self) -> &'b [ast::Attribute]
331-
where
332-
'a: 'b,
333-
{
328+
fn attrs(self) -> &'a [ast::Attribute] {
334329
self.1
335330
}
336-
fn check<'b, 'c, T: EarlyLintPass>(self, cx: &mut EarlyContextAndPass<'b, 'c, T>)
337-
where
338-
'a: 'b,
339-
{
331+
fn check<'ecx, 'tcx, T: EarlyLintPass>(self, cx: &mut EarlyContextAndPass<'ecx, 'tcx, T>) {
340332
lint_callback!(cx, check_crate, self.0);
341333
ast_visit::walk_crate(cx, self.0);
342334
lint_callback!(cx, check_crate_post, self.0);
@@ -347,16 +339,10 @@ impl<'a> EarlyCheckNode<'a> for (ast::NodeId, &'a [ast::Attribute], &'a [P<ast::
347339
fn id(self) -> ast::NodeId {
348340
self.0
349341
}
350-
fn attrs<'b>(self) -> &'b [ast::Attribute]
351-
where
352-
'a: 'b,
353-
{
342+
fn attrs(self) -> &'a [ast::Attribute] {
354343
self.1
355344
}
356-
fn check<'b, 'c, T: EarlyLintPass>(self, cx: &mut EarlyContextAndPass<'b, 'c, T>)
357-
where
358-
'a: 'b,
359-
{
345+
fn check<'ecx, 'tcx, T: EarlyLintPass>(self, cx: &mut EarlyContextAndPass<'ecx, 'tcx, T>) {
360346
walk_list!(cx, visit_attribute, self.1);
361347
walk_list!(cx, visit_item, self.2);
362348
}

0 commit comments

Comments
 (0)