Skip to content

AstValidator tweaks #139235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 2, 2025
Merged

AstValidator tweaks #139235

merged 4 commits into from
Apr 2, 2025

Conversation

nnethercote
Copy link
Contributor

When I read through AstValidator there were several things that tripped me up, and made the code harder to understand than I would have liked. This PR addresses them. Best reviewed one commit at a time.

r? @davidtwco

Currently some code paths return early, while others fall through to the
`visit::walk_item` call, which is easy to overlook (I did, at first),
even with the explanatory comments.

This commit removes the early returns and moves the `visit::walk_item`
calls up where necessary. This makes the function easier to read and
slightly shorter.
Currently it uses `walk_item` on some item kinds. For other item kinds
it visits the fields individually. For the latter group, this commit
adds `visit_attrs_vis` and `visit_attrs_vis_ident` which bundle up
visits to the fields that don't need special handling. This makes it
clearer that they haven't been forgotten about.

Also, it's better to do the attribute visits at the start because
attributes precede the items in the source code. Because of this, a
couple of tests have their output improved: errors appear in an order
that matches the source code order.
A bunch of span-related names in `AstValidator` don't end in `span`,
which goes against the usual naming conventions and makes the code
surprisingly hard to read. E.g. a name like `body` doesn't sound like
it's a span.

This commit adds `_span` suffixes.
`AstValidator` has several `with_*` methods, each one setting a field
that adjust how checking takes place for items within certain other
items. E.g. `with_in_trait_impl` is used to adjust the checking done on
items inside an `impl` item. Weirdly, the scopes used for most of the
`with_*` calls are very broad, and include things that aren't "inside"
the item, such as visibility, unsafety, and constness.

This commit minimizes the scope of these `with_*` calls so they only
apply to the things inside the item.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 2, 2025
@compiler-errors
Copy link
Member

r? compiler-errors @bors r+

@bors
Copy link
Collaborator

bors commented Apr 2, 2025

📌 Commit 2e7de1a has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 2, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 2, 2025
…=compiler-errors

`AstValidator` tweaks

When I read through `AstValidator` there were several things that tripped me up, and made the code harder to understand than I would have liked. This PR addresses them. Best reviewed one commit at a time.

r? `@davidtwco`
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 2, 2025
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#138992 (literal pattern lowering: use the pattern's type instead of the literal's in `const_to_pat`)
 - rust-lang#139211 (interpret: add a version of run_for_validation for &self)
 - rust-lang#139235 (`AstValidator` tweaks)
 - rust-lang#139237 (Add a dep kind for use of the anon node with zero dependencies)
 - rust-lang#139260 (Add dianqk to codegen reviewers)
 - rust-lang#139264 (Fix two incorrect turbofish suggestions)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit ad8db11 into rust-lang:master Apr 2, 2025
6 checks passed
@rustbot rustbot added this to the 1.88.0 milestone Apr 2, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 2, 2025
Rollup merge of rust-lang#139235 - nnethercote:AstValidator-tweaks, r=compiler-errors

`AstValidator` tweaks

When I read through `AstValidator` there were several things that tripped me up, and made the code harder to understand than I would have liked. This PR addresses them. Best reviewed one commit at a time.

r? ``@davidtwco``
@nnethercote nnethercote deleted the AstValidator-tweaks branch April 2, 2025 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants