about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2018-05-24 01:02:22 +0200
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2018-05-24 20:08:10 +0200
commitfe9a19580cd12adc2d0483bb549140fc6566a57e (patch)
treec3876805f299c5a95b70a0df1399e3c2f0d3384d /src/libstd
parent21b536704574061cebe431582116b6f91ae5b983 (diff)
downloadrust-fe9a19580cd12adc2d0483bb549140fc6566a57e.tar.gz
rust-fe9a19580cd12adc2d0483bb549140fc6566a57e.zip
Add documentation about env! second argument
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/macros.rs17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs
index d1274a40900..8da70f5717e 100644
--- a/src/libstd/macros.rs
+++ b/src/libstd/macros.rs
@@ -364,7 +364,6 @@ pub mod builtin {
     ///
     /// let s = fmt::format(format_args!("hello {}", "world"));
     /// assert_eq!(s, format!("hello {}", "world"));
-    ///
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     #[macro_export]
@@ -379,7 +378,7 @@ pub mod builtin {
     /// compile time, yielding an expression of type `&'static str`.
     ///
     /// If the environment variable is not defined, then a compilation error
-    /// will be emitted.  To not emit a compile error, use the [`option_env!`]
+    /// will be emitted. To not emit a compile error, use the [`option_env!`]
     /// macro instead.
     ///
     /// [`option_env!`]: ../std/macro.option_env.html
@@ -390,6 +389,20 @@ pub mod builtin {
     /// let path: &'static str = env!("PATH");
     /// println!("the $PATH variable at the time of compiling was: {}", path);
     /// ```
+    ///
+    /// You can customize the error message by passing a string as the second
+    /// parameter:
+    ///
+    /// ```compile_fail
+    /// let doc: &'static str = env!("documentation", "what's that?!");
+    /// ```
+    ///
+    /// If the `documentation` environment variable is not defined, you'll get
+    /// the following error:
+    ///
+    /// ```text
+    /// error: what's that?!
+    /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     #[macro_export]
     macro_rules! env {