Skip to content

compiletest: Add testing for lint machinery at runtime#157721

Open
clubby789 wants to merge 2 commits into
rust-lang:mainfrom
clubby789:test-lint-machinery
Open

compiletest: Add testing for lint machinery at runtime#157721
clubby789 wants to merge 2 commits into
rust-lang:mainfrom
clubby789:test-lint-machinery

Conversation

@clubby789

@clubby789 clubby789 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

While implementing #157707, I noticed that we don't have 'runtime' tests for the diagnostic machinery (i.e. we test the derive macros themselves, but not their output when emitted). This introduces a new way to test this machinery.

  • Add //@ aux-lint: file.rs, which builds a lint library in auxiliary/file.rs
  • Lint libraries link with rustc_private, and export a extern "C" fn register_lints(...)
  • A new compiletest-lint-driver wraps rustc and installs the provided lints when building the test

Included is a simple demo lint for example

AI Disclosure: I used an LLM to plan out the broad structure of the machinery and identify issues; all code in this PR is written by hand

@rustbot

rustbot commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

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

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

Some changes occurred in src/tools/compiletest

cc @jieyouxu

@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) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 10, 2026
@rustbot

rustbot commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @jieyouxu, @oli-obk, @wesleywiser, bootstrap
  • @jieyouxu, @oli-obk, @wesleywiser, bootstrap expanded to 8 candidates
  • Random selection from Mark-Simulacrum, jieyouxu, oli-obk, wesleywiser

@rustbot

rustbot commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

rustc-dev-guide is developed in its own repository. If possible, consider making this change to rust-lang/rustc-dev-guide instead.

cc @BoxyUwU, @tshepang

@rustbot rustbot added the A-rustc-dev-guide Area: rustc-dev-guide label Jun 10, 2026
Comment on lines +2106 to +2111
let lint_driver: PathBuf = builder
.ensure(tool::CompiletestLintDriver {
compiler: test_compiler,
target: test_compiler.host,
})
.tool_path;

@clubby789 clubby789 Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does add some tool+std builds unconditionally to any ui-fulldeps invoke; this should hopefully be relatively low impact in practice

View changes since the review

@clubby789

Copy link
Copy Markdown
Contributor Author

Just because I'm a little unsure on the correctness of some of the logic:
@bors try jobs=x86_64-gnu-stable,dist-x86_64-msvc

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 10, 2026
compiletest: Add testing for lint machinery at runtime


try-job: x86_64-gnu-stable
try-job: dist-x86_64-msvc
@rust-bors

rust-bors Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: e1663b0 (e1663b0b8baea0aa95b6292be893d0340b542cf1, parent: 485ec3fbcc12fa14ef6596dabb125ad710499c9e)

@Mark-Simulacrum

Copy link
Copy Markdown
Member

we test the derive macros themselves, but not their output when emitted

I'm a bit confused (probably just missing something...)... but aren't those macros tested by every diagnostics-related UI test in the existing suite? It's an indirect test but it should still catch bugs in practice, right?

If we wanted to test the raw output, I'd expect that to be done with something more like proc-macro2 + insta to snapshot test what is produced by the macro?

I think in general it would make sense to make a compiler MCP for this since it'll at minimum make it a bit more painful to edit the lint infrastructure.

@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 21, 2026
@clubby789

Copy link
Copy Markdown
Contributor Author

'Output' as in the runtime diagnostics emission. The machinery in general is tested, but when introducing new features to the system (i.e. lint MSRV) it would be nice to test the edge cases of behaviour.

An MCP probably does make sense here though.

@clubby789

Copy link
Copy Markdown
Contributor Author

MCP: rust-lang/compiler-team#1004

@clubby789 clubby789 added S-waiting-on-MCP Status: PR has a compiler MCP and is waiting for the compiler MCP to complete. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 21, 2026
@jieyouxu jieyouxu assigned jieyouxu and unassigned jieyouxu Jun 22, 2026
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-rustc-dev-guide Area: rustc-dev-guide A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-MCP Status: PR has a compiler MCP and is waiting for the compiler MCP to complete. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) 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.

5 participants