Skip to content

Commit fe9a195

Browse files
Add documentation about env! second argument
1 parent 21b5367 commit fe9a195

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/libstd/macros.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ pub mod builtin {
364364
///
365365
/// let s = fmt::format(format_args!("hello {}", "world"));
366366
/// assert_eq!(s, format!("hello {}", "world"));
367-
///
368367
/// ```
369368
#[stable(feature = "rust1", since = "1.0.0")]
370369
#[macro_export]
@@ -379,7 +378,7 @@ pub mod builtin {
379378
/// compile time, yielding an expression of type `&'static str`.
380379
///
381380
/// If the environment variable is not defined, then a compilation error
382-
/// will be emitted. To not emit a compile error, use the [`option_env!`]
381+
/// will be emitted. To not emit a compile error, use the [`option_env!`]
383382
/// macro instead.
384383
///
385384
/// [`option_env!`]: ../std/macro.option_env.html
@@ -390,6 +389,20 @@ pub mod builtin {
390389
/// let path: &'static str = env!("PATH");
391390
/// println!("the $PATH variable at the time of compiling was: {}", path);
392391
/// ```
392+
///
393+
/// You can customize the error message by passing a string as the second
394+
/// parameter:
395+
///
396+
/// ```compile_fail
397+
/// let doc: &'static str = env!("documentation", "what's that?!");
398+
/// ```
399+
///
400+
/// If the `documentation` environment variable is not defined, you'll get
401+
/// the following error:
402+
///
403+
/// ```text
404+
/// error: what's that?!
405+
/// ```
393406
#[stable(feature = "rust1", since = "1.0.0")]
394407
#[macro_export]
395408
macro_rules! env {

0 commit comments

Comments
 (0)