Skip to content

Commit b0d374a

Browse files
authored
Rollup merge of #63854 - c410-f3r:attrs-visit, r=petrochenkov
Modifies how Arg, Arm, Field, FieldPattern and Variant are visited Part of the necessary work to accomplish #63468.
2 parents 7059f05 + 6a3d517 commit b0d374a

File tree

11 files changed

+147
-145
lines changed

11 files changed

+147
-145
lines changed

src/librustc/hir/map/def_collector.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -154,20 +154,19 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
154154
});
155155
}
156156

157-
fn visit_variant(&mut self, v: &'a Variant, g: &'a Generics, item_id: NodeId) {
157+
fn visit_variant(&mut self, v: &'a Variant) {
158158
let def = self.create_def(v.id,
159159
DefPathData::TypeNs(v.ident.as_interned_str()),
160160
v.span);
161161
self.with_parent(def, |this| {
162162
if let Some(ctor_hir_id) = v.data.ctor_id() {
163163
this.create_def(ctor_hir_id, DefPathData::Ctor, v.span);
164164
}
165-
visit::walk_variant(this, v, g, item_id)
165+
visit::walk_variant(this, v)
166166
});
167167
}
168168

169-
fn visit_variant_data(&mut self, data: &'a VariantData, _: Ident,
170-
_: &'a Generics, _: NodeId, _: Span) {
169+
fn visit_variant_data(&mut self, data: &'a VariantData) {
171170
for (index, field) in data.fields().iter().enumerate() {
172171
let name = field.ident.map(|ident| ident.name)
173172
.unwrap_or_else(|| sym::integer(index));

src/librustc/lint/context.rs

+15-20
Original file line numberDiff line numberDiff line change
@@ -1040,13 +1040,13 @@ for LateContextAndPass<'a, 'tcx, T> {
10401040

10411041
fn visit_variant_data(&mut self,
10421042
s: &'tcx hir::VariantData,
1043-
name: ast::Name,
1044-
g: &'tcx hir::Generics,
1045-
item_id: hir::HirId,
1043+
_: ast::Name,
1044+
_: &'tcx hir::Generics,
1045+
_: hir::HirId,
10461046
_: Span) {
1047-
lint_callback!(self, check_struct_def, s, name, g, item_id);
1047+
lint_callback!(self, check_struct_def, s);
10481048
hir_visit::walk_struct_def(self, s);
1049-
lint_callback!(self, check_struct_def_post, s, name, g, item_id);
1049+
lint_callback!(self, check_struct_def_post, s);
10501050
}
10511051

10521052
fn visit_struct_field(&mut self, s: &'tcx hir::StructField) {
@@ -1061,9 +1061,9 @@ for LateContextAndPass<'a, 'tcx, T> {
10611061
g: &'tcx hir::Generics,
10621062
item_id: hir::HirId) {
10631063
self.with_lint_attrs(v.id, &v.attrs, |cx| {
1064-
lint_callback!(cx, check_variant, v, g);
1064+
lint_callback!(cx, check_variant, v);
10651065
hir_visit::walk_variant(cx, v, g, item_id);
1066-
lint_callback!(cx, check_variant_post, v, g);
1066+
lint_callback!(cx, check_variant_post, v);
10671067
})
10681068
}
10691069

@@ -1214,18 +1214,13 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
12141214
run_early_pass!(self, check_fn_post, fk, decl, span, id);
12151215
}
12161216

1217-
fn visit_variant_data(&mut self,
1218-
s: &'a ast::VariantData,
1219-
ident: ast::Ident,
1220-
g: &'a ast::Generics,
1221-
item_id: ast::NodeId,
1222-
_: Span) {
1223-
run_early_pass!(self, check_struct_def, s, ident, g, item_id);
1217+
fn visit_variant_data(&mut self, s: &'a ast::VariantData) {
1218+
run_early_pass!(self, check_struct_def, s);
12241219
if let Some(ctor_hir_id) = s.ctor_id() {
12251220
self.check_id(ctor_hir_id);
12261221
}
12271222
ast_visit::walk_struct_def(self, s);
1228-
run_early_pass!(self, check_struct_def_post, s, ident, g, item_id);
1223+
run_early_pass!(self, check_struct_def_post, s);
12291224
}
12301225

12311226
fn visit_struct_field(&mut self, s: &'a ast::StructField) {
@@ -1235,11 +1230,11 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
12351230
})
12361231
}
12371232

1238-
fn visit_variant(&mut self, v: &'a ast::Variant, g: &'a ast::Generics, item_id: ast::NodeId) {
1239-
self.with_lint_attrs(item_id, &v.attrs, |cx| {
1240-
run_early_pass!(cx, check_variant, v, g);
1241-
ast_visit::walk_variant(cx, v, g, item_id);
1242-
run_early_pass!(cx, check_variant_post, v, g);
1233+
fn visit_variant(&mut self, v: &'a ast::Variant) {
1234+
self.with_lint_attrs(v.id, &v.attrs, |cx| {
1235+
run_early_pass!(cx, check_variant, v);
1236+
ast_visit::walk_variant(cx, v);
1237+
run_early_pass!(cx, check_variant_post, v);
12431238
})
12441239
}
12451240

src/librustc/lint/mod.rs

+8-28
Original file line numberDiff line numberDiff line change
@@ -248,21 +248,11 @@ macro_rules! late_lint_methods {
248248
fn check_trait_item_post(a: &$hir hir::TraitItem);
249249
fn check_impl_item(a: &$hir hir::ImplItem);
250250
fn check_impl_item_post(a: &$hir hir::ImplItem);
251-
fn check_struct_def(
252-
a: &$hir hir::VariantData,
253-
b: ast::Name,
254-
c: &$hir hir::Generics,
255-
d: hir::HirId
256-
);
257-
fn check_struct_def_post(
258-
a: &$hir hir::VariantData,
259-
b: ast::Name,
260-
c: &$hir hir::Generics,
261-
d: hir::HirId
262-
);
251+
fn check_struct_def(a: &$hir hir::VariantData);
252+
fn check_struct_def_post(a: &$hir hir::VariantData);
263253
fn check_struct_field(a: &$hir hir::StructField);
264-
fn check_variant(a: &$hir hir::Variant, b: &$hir hir::Generics);
265-
fn check_variant_post(a: &$hir hir::Variant, b: &$hir hir::Generics);
254+
fn check_variant(a: &$hir hir::Variant);
255+
fn check_variant_post(a: &$hir hir::Variant);
266256
fn check_lifetime(a: &$hir hir::Lifetime);
267257
fn check_path(a: &$hir hir::Path, b: hir::HirId);
268258
fn check_attribute(a: &$hir ast::Attribute);
@@ -395,21 +385,11 @@ macro_rules! early_lint_methods {
395385
fn check_trait_item_post(a: &ast::TraitItem);
396386
fn check_impl_item(a: &ast::ImplItem);
397387
fn check_impl_item_post(a: &ast::ImplItem);
398-
fn check_struct_def(
399-
a: &ast::VariantData,
400-
b: ast::Ident,
401-
c: &ast::Generics,
402-
d: ast::NodeId
403-
);
404-
fn check_struct_def_post(
405-
a: &ast::VariantData,
406-
b: ast::Ident,
407-
c: &ast::Generics,
408-
d: ast::NodeId
409-
);
388+
fn check_struct_def(a: &ast::VariantData);
389+
fn check_struct_def_post(a: &ast::VariantData);
410390
fn check_struct_field(a: &ast::StructField);
411-
fn check_variant(a: &ast::Variant, b: &ast::Generics);
412-
fn check_variant_post(a: &ast::Variant, b: &ast::Generics);
391+
fn check_variant(a: &ast::Variant);
392+
fn check_variant_post(a: &ast::Variant);
413393
fn check_lifetime(a: &ast::Lifetime);
414394
fn check_path(a: &ast::Path, b: ast::NodeId);
415395
fn check_attribute(a: &ast::Attribute);

src/librustc_lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
482482
}
483483
}
484484

485-
fn check_variant(&mut self, cx: &LateContext<'_, '_>, v: &hir::Variant, _: &hir::Generics) {
485+
fn check_variant(&mut self, cx: &LateContext<'_, '_>, v: &hir::Variant) {
486486
self.check_missing_docs_attrs(cx,
487487
Some(v.id),
488488
&v.attrs,

src/librustc_lint/nonstandard_style.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl EarlyLintPass for NonCamelCaseTypes {
146146
}
147147
}
148148

149-
fn check_variant(&mut self, cx: &EarlyContext<'_>, v: &ast::Variant, _: &ast::Generics) {
149+
fn check_variant(&mut self, cx: &EarlyContext<'_>, v: &ast::Variant) {
150150
self.check_case(cx, "variant", &v.ident);
151151
}
152152

@@ -350,9 +350,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
350350
&mut self,
351351
cx: &LateContext<'_, '_>,
352352
s: &hir::VariantData,
353-
_: ast::Name,
354-
_: &hir::Generics,
355-
_: hir::HirId,
356353
) {
357354
for sf in s.fields() {
358355
self.check_snake_case(cx, "structure field", &sf.ident);

src/librustc_passes/ast_validation.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
813813
visit::walk_poly_trait_ref(self, t, m);
814814
}
815815

816-
fn visit_variant_data(&mut self, s: &'a VariantData, _: Ident,
817-
_: &'a Generics, _: NodeId, _: Span) {
816+
fn visit_variant_data(&mut self, s: &'a VariantData) {
818817
self.with_banned_assoc_ty_bound(|this| visit::walk_struct_def(this, s))
819818
}
820819

src/librustc_passes/hir_stats.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,9 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
334334
ast_visit::walk_struct_field(self, s)
335335
}
336336

337-
fn visit_variant(&mut self,
338-
v: &'v ast::Variant,
339-
g: &'v ast::Generics,
340-
item_id: NodeId) {
337+
fn visit_variant(&mut self, v: &'v ast::Variant) {
341338
self.record("Variant", Id::None, v);
342-
ast_visit::walk_variant(self, v, g, item_id)
339+
ast_visit::walk_variant(self, v)
343340
}
344341

345342
fn visit_lifetime(&mut self, lifetime: &'v ast::Lifetime) {

src/libsyntax/ext/expand.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1209,9 +1209,13 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
12091209
}
12101210
}
12111211

1212-
fn visit_generic_params(&mut self, params: &mut Vec<ast::GenericParam>) {
1213-
self.cfg.configure_generic_params(params);
1214-
noop_visit_generic_params(params, self);
1212+
fn flat_map_generic_param(
1213+
&mut self,
1214+
param: ast::GenericParam
1215+
) -> SmallVec<[ast::GenericParam; 1]>
1216+
{
1217+
let param = configure!(self, param);
1218+
noop_flat_map_generic_param(param, self)
12151219
}
12161220

12171221
fn visit_attribute(&mut self, at: &mut ast::Attribute) {

0 commit comments

Comments
 (0)