-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
AstValidator
tweaks
#139235
+189
−188
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
compiler-errors
approved these changes
Apr 2, 2025
r? compiler-errors @bors r+ |
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`
This was referenced Apr 2, 2025
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
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``
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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