Files
rust/compiler
Jonathan Brouwer 86063080a5 Rollup merge of #152302 - ShE3py:cargo-envs, r=davidtwco
fix: don't suggest replacing `env!("CARGO_BIN_NAME")` with itself

Some environment variables (e.g. `CARGO_BIN_NAME`) are only available for some targets ([Cargo Targets](https://doc.rust-lang.org/cargo/reference/cargo-targets.html), [§ Environment variables Cargo sets for crates](https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates)), and the current diagnostic when copy-pasting code from a binary to a library is kinda confusing:

```rs
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
2026-03-10 22:44:05 +01:00
..
2026-03-07 10:42:02 -08:00
2026-03-07 10:42:02 -08:00
2026-03-07 10:42:02 -08:00
2026-03-07 10:42:02 -08:00
2026-03-08 22:54:12 +11:00
2026-03-07 10:42:02 -08:00
2026-01-19 16:08:54 +00:00