rust-lang / rust-lang/rust-clippy
Flag `env!` macro usage in build scripts
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
I am not sure if lints can or should make assumptions about the file they are defined in, but it would be good to flag usage of the env! (and option_env!) macro in build scripts. In all likelihood this is wrong. It certainly is wrong for CARGO_* variables [0].
Advantage
It is easy to miss this wrong usage, as it may not break immediately.
Drawbacks
None that I can think of.
Example
env!("CARGO_PKG_VERSION")
Could be written as:
std::env::var("CARGO_PKG_VERSION").expect("CARGO_PKG_VERSION variable not set")
Comparison with existing lints
Not aware of existing lints doing something similar.
Additional Context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue targets Rust build scripts and use of the env! and option_env! macros; start by finding how Clippy identifies build-script code and how comparable lints are organized. Use the linked Cargo environment-variable documentation and the examples as behavioral guidance. Done means the misuse is flagged without incorrectly flagging valid cases, with coverage for both macros.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- build-system, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100