Open weiznich opened 4 months ago
This is indeed a foot-gun that users might encountered, and I agree that a lint seems appropriate.
However adding this kind of very targetted lint (Cargo specific knowledge) seems out of place for rustc
, and given that are use-case for #[cfg(target_* = "...")]
in build script, albeit very small, I think this proposed lint should probably live in Clippy.
Code
Current output
Desired output
Rationale and extra context
I would expect a warning that explains that
cfg!(target_*)
will be evaluated in the context of the host system that compiles the build script and not in the context of the target system. It seems to be a common mistake for crate authors writing build scripts to usecfg!
and notstd::env
in combination with the environment variables set by cargo. The warning should suggest that the later variant is the correct solution there.Other cases
No response
Rust Version
Anything else?
No response