Add new misleading_cfg_in_build_script lint#153721
Open
GuillaumeGomez wants to merge 4 commits intorust-lang:mainfrom
Open
Add new misleading_cfg_in_build_script lint#153721GuillaumeGomez wants to merge 4 commits intorust-lang:mainfrom
misleading_cfg_in_build_script lint#153721GuillaumeGomez wants to merge 4 commits intorust-lang:mainfrom
Conversation
Collaborator
|
Some changes occurred in check-cfg diagnostics cc @Urgau |
262d2e2 to
3e99ab7
Compare
Member
Author
|
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.
Urgau
reviewed
Mar 11, 2026
Comment on lines
+202
to
+205
| 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") | ||
| } |
Member
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
Member
Author
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).
ea1c733 to
28c7221
Compare
This comment has been minimized.
This comment has been minimized.
…t have a compiler output generated by the lint-docs script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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