rust-lang / rust-lang/rust-clippy

Flag `env!` macro usage in build scripts

Open
#15,872 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.