Skip to content

Commit

Permalink
Auto merge of #125741 - petrochenkov:atvisord, r=<try>
Browse files Browse the repository at this point in the history
ast: Standardize visiting order for attributes and node IDs

This should only affect `macro_rules` scopes and order of diagnostics.

This is blocked on #125734 and will also need a crater run.
  • Loading branch information
bors committed May 30, 2024
2 parents 91c0823 + baccb16 commit 0525276
Show file tree
Hide file tree
Showing 14 changed files with 205 additions and 173 deletions.
42 changes: 21 additions & 21 deletions compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,10 @@ pub fn noop_flat_map_pat_field<T: MutVisitor>(
) -> SmallVec<[PatField; 1]> {
let PatField { attrs, id, ident, is_placeholder: _, is_shorthand: _, pat, span } = &mut fp;
vis.visit_id(id);
visit_attrs(attrs, vis);
vis.visit_ident(ident);
vis.visit_pat(pat);
vis.visit_span(span);
visit_attrs(attrs, vis);
smallvec![fp]
}

Expand All @@ -443,8 +443,8 @@ fn noop_visit_use_tree<T: MutVisitor>(use_tree: &mut UseTree, vis: &mut T) {
UseTreeKind::Simple(rename) => visit_opt(rename, |rename| vis.visit_ident(rename)),
UseTreeKind::Nested { items, .. } => {
for (tree, id) in items {
vis.visit_use_tree(tree);
vis.visit_id(id);
vis.visit_use_tree(tree);
}
}
UseTreeKind::Glob => {}
Expand All @@ -454,8 +454,8 @@ fn noop_visit_use_tree<T: MutVisitor>(use_tree: &mut UseTree, vis: &mut T) {

pub fn noop_flat_map_arm<T: MutVisitor>(mut arm: Arm, vis: &mut T) -> SmallVec<[Arm; 1]> {
let Arm { attrs, pat, guard, body, span, id, is_placeholder: _ } = &mut arm;
visit_attrs(attrs, vis);
vis.visit_id(id);
visit_attrs(attrs, vis);
vis.visit_pat(pat);
visit_opt(guard, |guard| vis.visit_expr(guard));
visit_opt(body, |body| vis.visit_expr(body));
Expand Down Expand Up @@ -553,10 +553,10 @@ pub fn noop_flat_map_variant<T: MutVisitor>(
visitor: &mut T,
) -> SmallVec<[Variant; 1]> {
let Variant { ident, vis, attrs, id, data, disr_expr, span, is_placeholder: _ } = &mut variant;
visitor.visit_id(id);
visit_attrs(attrs, visitor);
visitor.visit_ident(ident);
visitor.visit_vis(vis);
visit_attrs(attrs, visitor);
visitor.visit_id(id);
visitor.visit_variant_data(data);
visit_opt(disr_expr, |disr_expr| visitor.visit_anon_const(disr_expr));
visitor.visit_span(span);
Expand All @@ -570,8 +570,8 @@ fn noop_visit_ident<T: MutVisitor>(Ident { name: _, span }: &mut Ident, vis: &mu
fn noop_visit_path<T: MutVisitor>(Path { segments, span, tokens }: &mut Path, vis: &mut T) {
vis.visit_span(span);
for PathSegment { ident, id, args } in segments {
vis.visit_ident(ident);
vis.visit_id(id);
vis.visit_ident(ident);
visit_opt(args, |args| vis.visit_generic_args(args));
}
visit_lazy_tts(tokens, vis);
Expand Down Expand Up @@ -625,6 +625,7 @@ fn noop_visit_parenthesized_parameter_data<T: MutVisitor>(
fn noop_visit_local<T: MutVisitor>(local: &mut P<Local>, vis: &mut T) {
let Local { id, pat, ty, kind, span, colon_sp, attrs, tokens } = local.deref_mut();
vis.visit_id(id);
visit_attrs(attrs, vis);
vis.visit_pat(pat);
visit_opt(ty, |ty| vis.visit_ty(ty));
match kind {
Expand All @@ -639,7 +640,6 @@ fn noop_visit_local<T: MutVisitor>(local: &mut P<Local>, vis: &mut T) {
}
vis.visit_span(span);
visit_opt(colon_sp, |sp| vis.visit_span(sp));
visit_attrs(attrs, vis);
visit_lazy_tts(tokens, vis);
}

Expand Down Expand Up @@ -896,9 +896,9 @@ fn noop_visit_coroutine_kind<T: MutVisitor>(coroutine_kind: &mut CoroutineKind,
CoroutineKind::Async { span, closure_id, return_impl_trait_id }
| CoroutineKind::Gen { span, closure_id, return_impl_trait_id }
| CoroutineKind::AsyncGen { span, closure_id, return_impl_trait_id } => {
vis.visit_span(span);
vis.visit_id(closure_id);
vis.visit_id(return_impl_trait_id);
vis.visit_span(span);
}
}
}
Expand Down Expand Up @@ -929,8 +929,8 @@ fn noop_visit_precise_capturing_arg<T: MutVisitor>(arg: &mut PreciseCapturingArg
vis.visit_lifetime(lt);
}
PreciseCapturingArg::Arg(path, id) => {
vis.visit_path(path);
vis.visit_id(id);
vis.visit_path(path);
}
}
}
Expand All @@ -941,11 +941,11 @@ pub fn noop_flat_map_generic_param<T: MutVisitor>(
) -> SmallVec<[GenericParam; 1]> {
let GenericParam { id, ident, attrs, bounds, kind, colon_span, is_placeholder: _ } = &mut param;
vis.visit_id(id);
visit_attrs(attrs, vis);
vis.visit_ident(ident);
if let Some(colon_span) = colon_span {
vis.visit_span(colon_span);
}
visit_attrs(attrs, vis);
visit_vec(bounds, |bound| noop_visit_param_bound(bound, vis));
match kind {
GenericParamKind::Lifetime => {}
Expand Down Expand Up @@ -1012,16 +1012,16 @@ fn noop_visit_variant_data<T: MutVisitor>(vdata: &mut VariantData, vis: &mut T)
fields.flat_map_in_place(|field| vis.flat_map_field_def(field));
}
VariantData::Tuple(fields, id) => {
fields.flat_map_in_place(|field| vis.flat_map_field_def(field));
vis.visit_id(id);
fields.flat_map_in_place(|field| vis.flat_map_field_def(field));
}
VariantData::Unit(id) => vis.visit_id(id),
}
}

fn noop_visit_trait_ref<T: MutVisitor>(TraitRef { path, ref_id }: &mut TraitRef, vis: &mut T) {
vis.visit_path(path);
vis.visit_id(ref_id);
vis.visit_path(path);
}

fn noop_visit_poly_trait_ref<T: MutVisitor>(p: &mut PolyTraitRef, vis: &mut T) {
Expand All @@ -1036,12 +1036,12 @@ pub fn noop_flat_map_field_def<T: MutVisitor>(
visitor: &mut T,
) -> SmallVec<[FieldDef; 1]> {
let FieldDef { span, ident, vis, id, ty, attrs, is_placeholder: _ } = &mut fd;
visitor.visit_id(id);
visit_attrs(attrs, visitor);
visitor.visit_span(span);
visit_opt(ident, |ident| visitor.visit_ident(ident));
visitor.visit_vis(vis);
visitor.visit_id(id);
visitor.visit_ty(ty);
visit_attrs(attrs, visitor);
smallvec![fd]
}

Expand All @@ -1050,11 +1050,11 @@ pub fn noop_flat_map_expr_field<T: MutVisitor>(
vis: &mut T,
) -> SmallVec<[ExprField; 1]> {
let ExprField { ident, expr, span, is_shorthand: _, attrs, id, is_placeholder: _ } = &mut f;
vis.visit_id(id);
visit_attrs(attrs, vis);
vis.visit_ident(ident);
vis.visit_expr(expr);
vis.visit_id(id);
vis.visit_span(span);
visit_attrs(attrs, vis);
smallvec![f]
}

Expand Down Expand Up @@ -1408,6 +1408,8 @@ pub fn noop_visit_expr<T: MutVisitor>(
Expr { kind, id, span, attrs, tokens }: &mut Expr,
vis: &mut T,
) {
vis.visit_id(id);
visit_attrs(attrs, vis);
match kind {
ExprKind::Array(exprs) => visit_thin_exprs(exprs, vis),
ExprKind::ConstBlock(anon_const) => {
Expand All @@ -1428,8 +1430,8 @@ pub fn noop_visit_expr<T: MutVisitor>(
args: call_args,
span,
}) => {
vis.visit_ident(ident);
vis.visit_id(id);
vis.visit_ident(ident);
visit_opt(seg_args, |args| vis.visit_generic_args(args));
vis.visit_method_receiver_expr(receiver);
visit_thin_exprs(call_args, vis);
Expand Down Expand Up @@ -1580,9 +1582,7 @@ pub fn noop_visit_expr<T: MutVisitor>(
ExprKind::TryBlock(body) => vis.visit_block(body),
ExprKind::Lit(_) | ExprKind::IncludedBytes(..) | ExprKind::Err(_) | ExprKind::Dummy => {}
}
vis.visit_id(id);
vis.visit_span(span);
visit_attrs(attrs, vis);
visit_lazy_tts(tokens, vis);
}

Expand Down Expand Up @@ -1624,8 +1624,8 @@ fn noop_flat_map_stmt_kind<T: MutVisitor>(kind: StmtKind, vis: &mut T) -> SmallV
StmtKind::Empty => smallvec![StmtKind::Empty],
StmtKind::MacCall(mut mac) => {
let MacCallStmt { mac: mac_, style: _, attrs, tokens } = mac.deref_mut();
vis.visit_mac_call(mac_);
visit_attrs(attrs, vis);
vis.visit_mac_call(mac_);
visit_lazy_tts(tokens, vis);
smallvec![StmtKind::MacCall(mac)]
}
Expand All @@ -1636,8 +1636,8 @@ fn noop_visit_vis<T: MutVisitor>(visibility: &mut Visibility, vis: &mut T) {
match &mut visibility.kind {
VisibilityKind::Public | VisibilityKind::Inherited => {}
VisibilityKind::Restricted { path, id, shorthand: _ } => {
vis.visit_path(path);
vis.visit_id(id);
vis.visit_path(path);
}
}
vis.visit_span(&mut visibility.span);
Expand Down
18 changes: 9 additions & 9 deletions compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ pub trait Visitor<'ast>: Sized {
}

pub fn walk_crate<'a, V: Visitor<'a>>(visitor: &mut V, krate: &'a Crate) -> V::Result {
walk_list!(visitor, visit_item, &krate.items);
walk_list!(visitor, visit_attribute, &krate.attrs);
walk_list!(visitor, visit_item, &krate.items);
V::Result::output()
}

Expand Down Expand Up @@ -440,25 +440,25 @@ pub fn walk_variant<'a, V: Visitor<'a>>(visitor: &mut V, variant: &'a Variant) -
where
V: Visitor<'a>,
{
walk_list!(visitor, visit_attribute, &variant.attrs);
try_visit!(visitor.visit_ident(variant.ident));
try_visit!(visitor.visit_vis(&variant.vis));
try_visit!(visitor.visit_variant_data(&variant.data));
visit_opt!(visitor, visit_variant_discr, &variant.disr_expr);
walk_list!(visitor, visit_attribute, &variant.attrs);
V::Result::output()
}

pub fn walk_expr_field<'a, V: Visitor<'a>>(visitor: &mut V, f: &'a ExprField) -> V::Result {
walk_list!(visitor, visit_attribute, &f.attrs);
try_visit!(visitor.visit_expr(&f.expr));
try_visit!(visitor.visit_ident(f.ident));
walk_list!(visitor, visit_attribute, &f.attrs);
V::Result::output()
}

pub fn walk_pat_field<'a, V: Visitor<'a>>(visitor: &mut V, fp: &'a PatField) -> V::Result {
walk_list!(visitor, visit_attribute, &fp.attrs);
try_visit!(visitor.visit_ident(fp.ident));
try_visit!(visitor.visit_pat(&fp.pat));
walk_list!(visitor, visit_attribute, &fp.attrs);
V::Result::output()
}

Expand Down Expand Up @@ -701,8 +701,8 @@ pub fn walk_generic_param<'a, V: Visitor<'a>>(
visitor: &mut V,
param: &'a GenericParam,
) -> V::Result {
try_visit!(visitor.visit_ident(param.ident));
walk_list!(visitor, visit_attribute, &param.attrs);
try_visit!(visitor.visit_ident(param.ident));
walk_list!(visitor, visit_param_bound, &param.bounds, BoundKind::Bound);
match &param.kind {
GenericParamKind::Lifetime => (),
Expand Down Expand Up @@ -852,10 +852,10 @@ pub fn walk_assoc_item<'a, V: Visitor<'a>>(
ctxt: AssocCtxt,
) -> V::Result {
let &Item { id: _, span: _, ident, ref vis, ref attrs, ref kind, tokens: _ } = item;
walk_list!(visitor, visit_attribute, attrs);
try_visit!(visitor.visit_vis(vis));
try_visit!(visitor.visit_ident(ident));
try_visit!(kind.walk(item, ctxt, visitor));
walk_list!(visitor, visit_attribute, attrs);
V::Result::output()
}

Expand All @@ -868,10 +868,10 @@ pub fn walk_struct_def<'a, V: Visitor<'a>>(
}

pub fn walk_field_def<'a, V: Visitor<'a>>(visitor: &mut V, field: &'a FieldDef) -> V::Result {
walk_list!(visitor, visit_attribute, &field.attrs);
try_visit!(visitor.visit_vis(&field.vis));
visit_opt!(visitor, visit_ident, field.ident);
try_visit!(visitor.visit_ty(&field.ty));
walk_list!(visitor, visit_attribute, &field.attrs);
V::Result::output()
}

Expand All @@ -888,8 +888,8 @@ pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) -> V:
StmtKind::Empty => {}
StmtKind::MacCall(mac) => {
let MacCallStmt { mac, attrs, style: _, tokens: _ } = &**mac;
try_visit!(visitor.visit_mac_call(mac));
walk_list!(visitor, visit_attribute, attrs);
try_visit!(visitor.visit_mac_call(mac));
}
}
V::Result::output()
Expand Down Expand Up @@ -1111,10 +1111,10 @@ pub fn walk_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a Param) -> V::R
}

pub fn walk_arm<'a, V: Visitor<'a>>(visitor: &mut V, arm: &'a Arm) -> V::Result {
walk_list!(visitor, visit_attribute, &arm.attrs);
try_visit!(visitor.visit_pat(&arm.pat));
visit_opt!(visitor, visit_expr, &arm.guard);
visit_opt!(visitor, visit_expr, &arm.body);
walk_list!(visitor, visit_attribute, &arm.attrs);
V::Result::output()
}

Expand Down
18 changes: 9 additions & 9 deletions src/tools/clippy/tests/ui/cfg_attr_cargo_clippy.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
error: `feature = "cargo-clippy"` was replaced by `clippy`
--> tests/ui/cfg_attr_cargo_clippy.rs:5:12
--> tests/ui/cfg_attr_cargo_clippy.rs:3:13
|
LL | #[cfg_attr(feature = "cargo-clippy", derive(Debug))]
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `clippy`
LL | #![cfg_attr(feature = "cargo-clippy", doc = "a")]
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `clippy`
|
= note: `-D clippy::deprecated-clippy-cfg-attr` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::deprecated_clippy_cfg_attr)]`

error: `feature = "cargo-clippy"` was replaced by `clippy`
--> tests/ui/cfg_attr_cargo_clippy.rs:5:12
|
LL | #[cfg_attr(feature = "cargo-clippy", derive(Debug))]
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `clippy`

error: `feature = "cargo-clippy"` was replaced by `clippy`
--> tests/ui/cfg_attr_cargo_clippy.rs:6:16
|
Expand Down Expand Up @@ -37,11 +43,5 @@ error: `feature = "cargo-clippy"` was replaced by `clippy`
LL | #[cfg(all(feature = "cargo-clippy"))]
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `clippy`

error: `feature = "cargo-clippy"` was replaced by `clippy`
--> tests/ui/cfg_attr_cargo_clippy.rs:3:13
|
LL | #![cfg_attr(feature = "cargo-clippy", doc = "a")]
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `clippy`

error: aborting due to 7 previous errors

Loading

0 comments on commit 0525276

Please sign in to comment.