Repository navigation
rust_analyzer is an unexpected cfg condition #160736
Description
Activity
- addedA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
on Aug 8, 2026 Rust analyzer should be in the list of known cfgs, given that it works out of the box.
What do you mean by "works out of the box"? As far as I know it's only set by rust analyzer, not but
rustcor Cargo, that requires using Rust analyzer.- addedA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.A-check-cfgArea: --check-cfgArea: --check-cfgA-cfgArea: `cfg` conditional compilationArea: `cfg` conditional compilationT-rust-analyzerRelevant to the rust-analyzer team, which will review and decide on the PR/issue.Relevant to the rust-analyzer team, which will review and decide on the PR/issue.and removedA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lints
on Aug 8, 2026 rustfmtdoesn't trigger this lint and is also an external tool like rust analyzer.
Either none or both should be linted.One of the reason we have used in the past for inclusion in the list of well know names and values is the number of usage of said cfgs in the wild (particularly for tools).
I'm only seeing 227 files referencing it, and they all of the case seems pretty happy to either add the cfg to list or allow the lint.
rustfmtdoesn't trigger this lint and is also an external tool like rust analyzer.rustfmtis was been trigger thousands of times in the Crater run we did, and we didn't wanted to force everyone to add the cfg to the well know list, in particular sincerustfmtis the de-facto tool (while rust-analyzer isn't).There isn't currently a way to unset a builtin cfg, so if we added it, every user would have it, including users who would never use it, like RustRover users, I don't think that's something we want.
Reacted by coolcatcoder- addedC-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.
on Aug 8, 2026 cc @rust-lang/rust-analyzer in case you want to add something
We have the
rust_analyzer::tool namespace (and we use it in rust-analyzer), I think this is equivalent (except that here it's only a warning you can silence - but not if you're a library).Also - if we do introduce it as a built-in cfg, what will people not using it lose? Do you think there is a chance of using it by mistake? After all the purpose of check-cfg is to detect wrong cfg usage.
in particular since
rustfmtis the de-facto tool (while rust-analyzer isn't)But it is the only official tool for its purpose, even if there are competitors.
The
rust_analyzertool namespace is indeed a good parallel, I didn't know the compiler had it as built-in, that seems like a sufficient precedent in it-self to addrust_analyzeras an well known cfg.Reacted by Lukas WirthIf someone to give it a go, the cfg should be added around here:
rust/compiler/rustc_session/src/config/cfg.rs
Lines 386 to 394 in 7088e4b
// These four are never set by rustc, but we set them anyway; they // should not trigger the lint because `cargo clippy`, `cargo doc`, // `cargo test`, `cargo miri run` and `cargo fmt` (respectively) // can set them. ins!(sym::clippy, no_values); ins!(sym::doc, no_values); ins!(sym::doctest, no_values); ins!(sym::miri, no_values); ins!(sym::rustfmt, no_values); - with a test in
tests/ui/check-cfg/well-known-values.rs
- addedE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.and removedC-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.
on Aug 10, 2026 @rustbot claim
- added 3 commits that reference this issue
on Aug 11, 2026 - added a commit that references this issue
on Aug 12, 2026 - added a commit that references this issue
on Aug 12, 2026
Code
#![cfg(rust_analyzer)]Current output
Desired output
Rationale and extra context
Rust analyzer should be in the list of known cfgs, given that it works out of the box.
Rust Version
Anything else?
No response