Skip to content

Commit

Permalink
Rollup merge of rust-lang#122670 - beetrees:non-unicode-option-env-er…
Browse files Browse the repository at this point in the history
…ror, r=compiler-errors

Fix bug where `option_env!` would return `None` when env var is present but not valid Unicode

Fixes rust-lang#122669 by making `option_env!` emit an error when the value of the environment variable is not valid Unicode.
  • Loading branch information
matthiaskrgr authored Oct 15, 2024
2 parents ecb3830 + 6fc4b1a commit ffc4a6c
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions core/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1107,17 +1107,19 @@ pub(crate) mod builtin {
///
/// If the named environment variable is present at compile time, this will
/// expand into an expression of type `Option<&'static str>` whose value is
/// `Some` of the value of the environment variable. If the environment
/// variable is not present, then this will expand to `None`. See
/// [`Option<T>`][Option] for more information on this type. Use
/// [`std::env::var`] instead if you want to read the value at runtime.
/// `Some` of the value of the environment variable (a compilation error
/// will be emitted if the environment variable is not a valid Unicode
/// string). If the environment variable is not present, then this will
/// expand to `None`. See [`Option<T>`][Option] for more information on this
/// type. Use [`std::env::var`] instead if you want to read the value at
/// runtime.
///
/// [`std::env::var`]: ../std/env/fn.var.html
///
/// A compile time error is never emitted when using this macro regardless
/// of whether the environment variable is present or not.
/// To emit a compile error if the environment variable is not present,
/// use the [`env!`] macro instead.
/// A compile time error is only emitted when using this macro if the
/// environment variable exists and is not a valid Unicode string. To also
/// emit a compile error if the environment variable is not present, use the
/// [`env!`] macro instead.
///
/// # Examples
///
Expand Down

0 comments on commit ffc4a6c

Please sign in to comment.