fix: don't suggest replacing env!("CARGO_BIN_NAME") with itself#152302
fix: don't suggest replacing env!("CARGO_BIN_NAME") with itself#152302ShE3py wants to merge 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.
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