compiletest: Do the known-directives check only once, and improve its error message#148510
Merged
bors merged 2 commits intorust-lang:masterfrom Nov 10, 2025
Merged
compiletest: Do the known-directives check only once, and improve its error message#148510bors merged 2 commits intorust-lang:masterfrom
bors merged 2 commits intorust-lang:masterfrom
Conversation
This allows every check to be a single hashtable lookup instead of a linear scan.
This also incorporates some requested improvements to the error message for unknown directives.
Collaborator
|
Some changes occurred in src/tools/compiletest cc @jieyouxu
|
Collaborator
Member
Author
|
This was originally going to wait until after #147955, but then Ralf and I both got annoyed by the error message, and improving the error message would be a lot harder without extracting the check first. |
jieyouxu
approved these changes
Nov 9, 2025
Member
There was a problem hiding this comment.
Thanks. Eventually, I would like us to move towards a late rejection, where if we fail to match the directive against any registered handle, then that constitutes an unknown directive. But in the meantime, making this "stop the bleeding" logic nicer is also a good improvement.
Member
|
We can land this first. |
Collaborator
bors
added a commit
that referenced
this pull request
Nov 9, 2025
Rollup of 4 pull requests Successful merges: - #148248 (Constify `ControlFlow` methods without unstable bounds) - #148285 (Constify `ControlFlow` methods with unstable bounds) - #148510 (compiletest: Do the known-directives check only once, and improve its error message) - #148655 (Fix invalid macro tag generation for keywords which can be followed by values) r? `@ghost` `@rustbot` modify labels: rollup
rust-timer
added a commit
that referenced
this pull request
Nov 10, 2025
Rollup merge of #148510 - Zalathar:known-directives, r=jieyouxu compiletest: Do the known-directives check only once, and improve its error message This PR is a combination of three changes: - Store the list of known directives in a set, so that checking a directive name doesn't require a linear scan - Extract the known-directives check out of `iter_directives` and do it only once, instead of multiple times per file - Improve the error message for unknown directives, [as requested on Zulip](https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/Compiletest.20directive.20parsing.20error/with/553598083) The change to error messages is fused with the extraction, since doing it independently would have been more awkward. --- ## Before ```text Testing stage1 with compiletest suite=coverage mode=coverage-map (aarch64-apple-darwin) errors encountered during EarlyProps parsing: /Users/stuart/Dev/rust/rust/tests/coverage/trivial.rs 2025-11-05T01:55:46.440012Z ERROR compiletest::directives: /Users/stuart/Dev/rust/rust/tests/coverage/trivial.rs:2: detected unknown compiletest test directive `add-core-stubs` thread '<unnamed>' (36268582) panicked at src/tools/compiletest/src/directives.rs:72:13: errors encountered during EarlyProps parsing note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` ## After ```text Testing stage1 with compiletest suite=coverage mode=coverage-map (aarch64-apple-darwin) thread '<unnamed>' (36270772) panicked at src/tools/compiletest/src/lib.rs:876:9: directives check failed: ERROR: unknown compiletest directive `add-core-stubs` at /Users/stuart/Dev/rust/rust/tests/coverage/trivial.rs:2 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ```
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR is a combination of three changes:
iter_directivesand do it only once, instead of multiple times per fileThe change to error messages is fused with the extraction, since doing it independently would have been more awkward.
Before
After