Skip to content

Commit 8e403e5

Browse files
committed
Auto merge of #9053 - sharnoff:master, r=alexcrichton
[doc] add note about empty environment variables for missing manifest keys This is a small addition to the cargo book. In [the section](https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates) about the environment variables cargo sets to provide information about a crate, there's no mention about the value of those environment variables is if the key isn't present in the manifest. As can be seen [here](https://github.com/rust-lang/cargo/blob/94e21ada550f91f5d32f2f51635792a79aeb8d63/src/cargo/core/compiler/compilation.rs#L287)¹, the values default to the empty string (instead of, say, not being present), so this change just adds a sentence in the book to clarify that. If the terminology could be improved or there's a better place for this to be included, I'm happy to change it :) --- ¹ To be clear, I did also play around with this and found that the environment variables were empty. The code reference was more to double-check that the behavior I saw was a consistent pattern.
2 parents 94e21ad + 48cd236 commit 8e403e5

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/doc/src/reference/environment-variables.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ let version = env!("CARGO_PKG_VERSION");
188188

189189
`version` will now contain the value of `CARGO_PKG_VERSION`.
190190

191+
Note that if one of these values is not provided in the manifest, the
192+
corresponding environment variable is set to the empty string, `""`.
193+
191194
* `CARGO` — Path to the `cargo` binary performing the build.
192195
* `CARGO_MANIFEST_DIR` — The directory containing the manifest of your package.
193196
* `CARGO_PKG_VERSION` — The full version of your package.

0 commit comments

Comments
 (0)