Skip to content

Conversation

@Zalathar
Copy link
Member

@Zalathar Zalathar commented Nov 5, 2025

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

The change to error messages is fused with the extraction, since doing it independently would have been more awkward.


Before

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

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 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.
@rustbot
Copy link
Collaborator

rustbot commented Nov 5, 2025

Some changes occurred in src/tools/compiletest

cc @jieyouxu

compiletest directives have been modified. Please add or update docs for the
new or modified directive in src/doc/rustc-dev-guide/.

@rustbot rustbot added A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Nov 5, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 5, 2025

r? @Kobzol

rustbot has assigned @Kobzol.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@Zalathar
Copy link
Member Author

Zalathar commented Nov 5, 2025

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 jieyouxu self-assigned this Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants