Add new misleading_cfg_in_build_script lint#153721
Conversation
|
Some changes occurred in check-cfg diagnostics cc @Urgau |
262d2e2 to
3e99ab7
Compare
|
Added a ui test to ensure this lint is only emitted on cargo |
This comment has been minimized.
This comment has been minimized.
3e99ab7 to
ea1c733
Compare
This comment has been minimized.
This comment has been minimized.
| fn is_build_script(cx: &EarlyContext<'_>) -> bool { | ||
| rustc_session::utils::was_invoked_from_cargo() | ||
| && cx.sess().opts.crate_name.as_deref() == Some("build_script_build") | ||
| } |
There was a problem hiding this comment.
This seems quite hacky and brittle for a lint.
Is there a better to detect if we are compiling a Cargo build script? If there isn't, we could maybe consider having the lint allowed by-default, but have Cargo implicitly set it to warn for build-scripts.
cc @rust-lang/cargo
There was a problem hiding this comment.
Agreed, not great. :-/
I was kinda hoping that we had a "build script" crate kind but we don't (which is logical but still, not fun).
There was a problem hiding this comment.
Just put it in t-cargo meeting agenda :)
next meeting time: Tue, Mar 17, 2026, 10:00 UTC-4
ea1c733 to
28c7221
Compare
This comment has been minimized.
This comment has been minimized.
|
CI is finally happy. ^^' |
|
The cargo team discussed this today (notes). Some comments from that discussion:
|
|
I would expect a T-cargo FCP, with maybe T-compiler, but not T-lang. The lint proposed here has nothing to do with the language, it's purely a compiler and Cargo affair. To elaborate a bit more, this lint could be in cargo it-self if we had a custom linting system, and it wouldn't need T-lang approval for that, so I don't think it needs one. We also (T-compiler) didn't ask T-lang to FCP the
I wouldn't look to closely at the impl. I haven't yet done a review of it, I wanted to wait for T-cargo input first. |
There was a problem hiding this comment.
I share the concerns from Eric, about having another cfg parser.
Fortunately, this lint is simple enough that it can use the same infra as the unexpected_cfgs lint and perform the verification directly when parsing the cfgs them-selves in rustc_attr_parsing.
This will require some code re-shuffling between different crates (rustc_attr_parsing, rustc_lint_defs, rustc_lint, ...). You can follow what has been done for the UNEXPECTED_CFGS lint.
2d14a6b to
06e2527
Compare
This comment has been minimized.
This comment has been minimized.
I don't think that's how lints have been handled in the past. They all need to be approved by the lang team. I'm not aware of any exclusions. |
|
I'm surprised: I added lints in the past without needing t-lang approval (although it might have been a few years for the last one... ^^'). |
I haven't done yet a deep-dive review, but that looks pretty good. Happy to see the logic moved directly in the parsing, it seems to simplify a bunch of things. Even perf seems to be happy. I will try to do a review before RustWeek, otherwise it will after. |
0ecdc4f to
a114a87
Compare
This comment has been minimized.
This comment has been minimized.
|
Implementation seems fine to me. @GuillaumeGomez what do say we do a crater run with the lint as deny-by-default to see the impact of the lint? For the purpose of the Crater run (since we don't have Cargo support yet), I think we can check |
…t have a compiler output generated by the lint-docs script
a114a87 to
b547e5d
Compare
|
Some changes occurred in check-cfg diagnostics cc @Urgau |
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@Urgau: Rebased and added one extra commit to change the lint level and trigger it on cargo |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
@bors try |
This comment has been minimized.
This comment has been minimized.
…, r=<try> Add new `misleading_cfg_in_build_script` lint
|
@craterbot check |
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
View all comments
Fixes #125441.
Fixes rust-lang/rust-clippy#9419.
Take-over of rust-lang/rust-clippy#12862.
It was originally implemented in clippy but the clippy thought it made for sense for such a lint to be directly implemented in rustc. I applied all suggestions made on the original PR and also improved the code overall (added docs too).
So on a
build.rsfromcargocrate, we will check for anytarget_*,unixandwindowscfg and warn about them.Since you made the original review on clippy.
r? @Urgau