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... ^^'). |
…, r=<try> Add new `misleading_cfg_in_build_script` lint
This comment has been minimized.
This comment has been minimized.
|
Error occured while categorizing benchmark run:
|
|
Failed again? O.o Let's try a full thing just in case. ^^' @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…, r=<try> Add new `misleading_cfg_in_build_script` lint
|
rust-lang/triagebot#2401 should fix the rustc-perf error. |
This comment has been minimized.
This comment has been minimized.
|
Error occured while categorizing benchmark run:
|
|
I'll wait for it to fixed. Please restart it once fixed on your side @Kobzol. ;) |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…, r=<try> Add new `misleading_cfg_in_build_script` lint
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (f7e8e16): comparison URL. Overall result: ❌✅ regressions and improvements - please read:Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. Next, please: If you can, justify the regressions found in this try perf run in writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 2.6%, secondary -1.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -1.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 517.584s -> 509.112s (-1.64%) |
|
@Urgau How does it look to you? |
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
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