Skip to content

fix: don't suggest replacing env!("CARGO_BIN_NAME") with itself#152302

Open
ShE3py wants to merge 1 commit intorust-lang:mainfrom
ShE3py:cargo-envs
Open

fix: don't suggest replacing env!("CARGO_BIN_NAME") with itself#152302
ShE3py wants to merge 1 commit intorust-lang:mainfrom
ShE3py:cargo-envs

Conversation

@ShE3py
Copy link
Contributor

@ShE3py ShE3py commented Feb 7, 2026

Some environment variables (e.g. CARGO_BIN_NAME) are only available for some crate types, and the current diagnostic when copy-pasting code from a binary to a library is kinda confusing:

const _: &str = env!("CARGO_BIN_NAME");

Before:

error: environment variable `CARGO_BIN_NAME` not defined at compile time
 --> lib.rs:1:17
  |
1 | const _: &str = env!("CARGO_BIN_NAME");
  |                 ^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: there is a similar Cargo environment variable: `CARGO_BIN_NAME`

After:

error: environment variable `CARGO_BIN_NAME` not defined at compile time
 --> lib.rs:1:17
  |
1 | const _: &str = env!("CARGO_BIN_NAME");
  |                 ^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: `CARGO_BIN_NAME` may not be available for the current Cargo target
  = help: Cargo sets build script variables at run time. Use `std::env::var("CARGO_BIN_NAME")` instead

@rustbot label +T-compiler +A-diagnostics +D-confusing

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 7, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 7, 2026

r? @davidtwco

rustbot has assigned @davidtwco.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 21 candidates
  • Random selection from 12 candidates

@rustbot rustbot added A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. labels Feb 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants