fix: don't suggest replacing env!("CARGO_BIN_NAME") with itself#152302
fix: don't suggest replacing env!("CARGO_BIN_NAME") with itself#152302rust-bors[bot] merged 1 commit intorust-lang:mainfrom
env!("CARGO_BIN_NAME") with itself#152302Conversation
|
r? @davidtwco rustbot has assigned @davidtwco. Use Why was this reviewer chosen?The reviewer was selected based on:
|
| #[derive(Diagnostic)] | ||
| pub(crate) enum EnvNotDefined<'a> { | ||
| #[diag("environment variable `{$var}` not defined at compile time")] | ||
| #[help("`{$var}` may not be available for the current Cargo target")] |
There was a problem hiding this comment.
"current Cargo target" reads strangely to me, I'm not entirely sure what I'd interpret this as referring to. Does this only come up with different crate types?
There was a problem hiding this comment.
It's what the Cargo Book call them, but they don't really map 1:1 to crate types (cf. TargetKind::rustc_crate_types).
E.g. CARGO_BIN_NAME is only available for binaries and example binaries, CARGO_MANIFEST_LINKS only for build scripts, and both are compiled with --crate-type=bin.
I'll try to improve the message with TargetKind::description, but not sure if it is exposed to Rustc.
I've also updated the PR description.
There was a problem hiding this comment.
It's fine for just now then, we can always adjust the wording later if we need to
|
@bors r+ rollup |
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
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
…uwer Rollup of 8 pull requests Successful merges: - #149130 (Implement coercions between `&pin (mut|const) T` and `&(mut) T` when `T: Unpin`) - #152457 (Pass -pg to linker when using -Zinstrument-mcount) - #153143 (Allow `./x test` to run tests without doc tests and without benchmarks) - #153653 (scalable vector: type renames and simple checks) - #152302 (fix: don't suggest replacing `env!("CARGO_BIN_NAME")` with itself) - #153641 (Move `Spanned`.) - #153643 (Avoid projection-only suggestions for inherent assoc types) - #153657 (triagebot: remove myself from some mention groups)
…uwer Rollup of 8 pull requests Successful merges: - #149130 (Implement coercions between `&pin (mut|const) T` and `&(mut) T` when `T: Unpin`) - #152457 (Pass -pg to linker when using -Zinstrument-mcount) - #153143 (Allow `./x test` to run tests without doc tests and without benchmarks) - #153653 (scalable vector: type renames and simple checks) - #152302 (fix: don't suggest replacing `env!("CARGO_BIN_NAME")` with itself) - #153641 (Move `Spanned`.) - #153643 (Avoid projection-only suggestions for inherent assoc types) - #153657 (triagebot: remove myself from some mention groups)
…uwer Rollup of 8 pull requests Successful merges: - #149130 (Implement coercions between `&pin (mut|const) T` and `&(mut) T` when `T: Unpin`) - #152457 (Pass -pg to linker when using -Zinstrument-mcount) - #153143 (Allow `./x test` to run tests without doc tests and without benchmarks) - #153653 (scalable vector: type renames and simple checks) - #152302 (fix: don't suggest replacing `env!("CARGO_BIN_NAME")` with itself) - #153641 (Move `Spanned`.) - #153643 (Avoid projection-only suggestions for inherent assoc types) - #153657 (triagebot: remove myself from some mention groups)
…uwer Rollup of 8 pull requests Successful merges: - #149130 (Implement coercions between `&pin (mut|const) T` and `&(mut) T` when `T: Unpin`) - #152457 (Pass -pg to linker when using -Zinstrument-mcount) - #153143 (Allow `./x test` to run tests without doc tests and without benchmarks) - #153653 (scalable vector: type renames and simple checks) - #152302 (fix: don't suggest replacing `env!("CARGO_BIN_NAME")` with itself) - #153641 (Move `Spanned`.) - #153643 (Avoid projection-only suggestions for inherent assoc types) - #153657 (triagebot: remove myself from some mention groups)
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
…uwer Rollup of 13 pull requests Successful merges: - #149130 (Implement coercions between `&pin (mut|const) T` and `&(mut) T` when `T: Unpin`) - #152457 (Pass -pg to linker when using -Zinstrument-mcount) - #153143 (Allow `./x test` to run tests without doc tests and without benchmarks) - #153471 (Refactor `ActiveJobGuard`) - #153595 (`QueryLatch` cleanups) - #153653 (scalable vector: type renames and simple checks) - #152302 (fix: don't suggest replacing `env!("CARGO_BIN_NAME")` with itself) - #153479 (Add rationale for intentional potential_query_instability allows) - #153600 (add test for proc-macros with custom panic payloads) - #153641 (Move `Spanned`.) - #153643 (Avoid projection-only suggestions for inherent assoc types) - #153657 (triagebot: remove myself from some mention groups) - #153659 (Mark an unreachable match arm as such)
…uwer Rollup of 13 pull requests Successful merges: - #149130 (Implement coercions between `&pin (mut|const) T` and `&(mut) T` when `T: Unpin`) - #152457 (Pass -pg to linker when using -Zinstrument-mcount) - #153143 (Allow `./x test` to run tests without doc tests and without benchmarks) - #153471 (Refactor `ActiveJobGuard`) - #153595 (`QueryLatch` cleanups) - #153653 (scalable vector: type renames and simple checks) - #152302 (fix: don't suggest replacing `env!("CARGO_BIN_NAME")` with itself) - #153479 (Add rationale for intentional potential_query_instability allows) - #153600 (add test for proc-macros with custom panic payloads) - #153641 (Move `Spanned`.) - #153643 (Avoid projection-only suggestions for inherent assoc types) - #153657 (triagebot: remove myself from some mention groups) - #153659 (Mark an unreachable match arm as such)
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
…uwer Rollup of 14 pull requests Successful merges: - #149130 (Implement coercions between `&pin (mut|const) T` and `&(mut) T` when `T: Unpin`) - #152457 (Pass -pg to linker when using -Zinstrument-mcount) - #153143 (Allow `./x test` to run tests without doc tests and without benchmarks) - #153471 (Refactor `ActiveJobGuard`) - #153595 (`QueryLatch` cleanups) - #153653 (scalable vector: type renames and simple checks) - #152302 (fix: don't suggest replacing `env!("CARGO_BIN_NAME")` with itself) - #153283 (feat(rustdoc-json): Add optional support for rkyv (de)serialization) - #153479 (Add rationale for intentional potential_query_instability allows) - #153533 (Fix LegacyKeyValueFormat report from docker build: miscellaneous) - #153600 (add test for proc-macros with custom panic payloads) - #153643 (Avoid projection-only suggestions for inherent assoc types) - #153657 (triagebot: remove myself from some mention groups) - #153659 (Mark an unreachable match arm as such)
…uwer Rollup of 13 pull requests Successful merges: - #149130 (Implement coercions between `&pin (mut|const) T` and `&(mut) T` when `T: Unpin`) - #153143 (Allow `./x test` to run tests without doc tests and without benchmarks) - #153471 (Refactor `ActiveJobGuard`) - #153595 (`QueryLatch` cleanups) - #153653 (scalable vector: type renames and simple checks) - #152302 (fix: don't suggest replacing `env!("CARGO_BIN_NAME")` with itself) - #153283 (feat(rustdoc-json): Add optional support for rkyv (de)serialization) - #153479 (Add rationale for intentional potential_query_instability allows) - #153533 (Fix LegacyKeyValueFormat report from docker build: miscellaneous) - #153600 (add test for proc-macros with custom panic payloads) - #153643 (Avoid projection-only suggestions for inherent assoc types) - #153657 (triagebot: remove myself from some mention groups) - #153659 (Mark an unreachable match arm as such)
…uwer Rollup of 13 pull requests Successful merges: - #149130 (Implement coercions between `&pin (mut|const) T` and `&(mut) T` when `T: Unpin`) - #153143 (Allow `./x test` to run tests without doc tests and without benchmarks) - #153471 (Refactor `ActiveJobGuard`) - #153595 (`QueryLatch` cleanups) - #153653 (scalable vector: type renames and simple checks) - #152302 (fix: don't suggest replacing `env!("CARGO_BIN_NAME")` with itself) - #153283 (feat(rustdoc-json): Add optional support for rkyv (de)serialization) - #153479 (Add rationale for intentional potential_query_instability allows) - #153533 (Fix LegacyKeyValueFormat report from docker build: miscellaneous) - #153600 (add test for proc-macros with custom panic payloads) - #153643 (Avoid projection-only suggestions for inherent assoc types) - #153657 (triagebot: remove myself from some mention groups) - #153659 (Mark an unreachable match arm as such)
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
…nathanBrouwer Rollup of 13 pull requests Successful merges: - rust-lang#149130 (Implement coercions between `&pin (mut|const) T` and `&(mut) T` when `T: Unpin`) - rust-lang#153143 (Allow `./x test` to run tests without doc tests and without benchmarks) - rust-lang#153471 (Refactor `ActiveJobGuard`) - rust-lang#153595 (`QueryLatch` cleanups) - rust-lang#153653 (scalable vector: type renames and simple checks) - rust-lang#152302 (fix: don't suggest replacing `env!("CARGO_BIN_NAME")` with itself) - rust-lang#153283 (feat(rustdoc-json): Add optional support for rkyv (de)serialization) - rust-lang#153479 (Add rationale for intentional potential_query_instability allows) - rust-lang#153533 (Fix LegacyKeyValueFormat report from docker build: miscellaneous) - rust-lang#153600 (add test for proc-macros with custom panic payloads) - rust-lang#153643 (Avoid projection-only suggestions for inherent assoc types) - rust-lang#153657 (triagebot: remove myself from some mention groups) - rust-lang#153659 (Mark an unreachable match arm as such)
Some environment variables (e.g.
CARGO_BIN_NAME) are only available for some targets (Cargo Targets, § Environment variables Cargo sets for crates), and the current diagnostic when copy-pasting code from a binary to a library is kinda confusing:Before:
After:
@rustbot label +T-compiler +A-diagnostics +D-confusing