about summary refs log tree commit diff
path: root/src/librustc_error_codes/error_codes
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2019-11-22 13:23:33 +0100
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2019-11-22 19:14:09 +0100
commitea62c2e5b31cec7f540784cc1fad84b7c0006e3f (patch)
tree7e5815e9470477ce16ab828e9f41c0e10bbb4023 /src/librustc_error_codes/error_codes
parentf1b882b55805c342e46ee4ca3beeef1d1fa2044b (diff)
downloadrust-ea62c2e5b31cec7f540784cc1fad84b7c0006e3f.tar.gz
rust-ea62c2e5b31cec7f540784cc1fad84b7c0006e3f.zip
Improve E0015 long error explanation
Diffstat (limited to 'src/librustc_error_codes/error_codes')
-rw-r--r--src/librustc_error_codes/error_codes/E0015.md36
1 files changed, 27 insertions, 9 deletions
diff --git a/src/librustc_error_codes/error_codes/E0015.md b/src/librustc_error_codes/error_codes/E0015.md
index 2bf59983fa9..361cb425809 100644
--- a/src/librustc_error_codes/error_codes/E0015.md
+++ b/src/librustc_error_codes/error_codes/E0015.md
@@ -1,14 +1,32 @@
-The only functions that can be called in static or constant expressions are
-`const` functions, and struct/enum constructors. `const` functions are only
-available on a nightly compiler. Rust currently does not support more general
-compile-time function execution.
+A constant item was initialized with something that is not a constant expression.
+
+Erroneous code example:
+
+```compile_fail,E0015
+fn create_some() -> Option<u8> {
+    Some(1)
+}
 
+const FOO: Option<u8> = create_some(); // error!
 ```
-const FOO: Option<u8> = Some(1); // enum constructor
-struct Bar {x: u8}
-const BAR: Bar = Bar {x: 1}; // struct constructor
+
+The only functions that can be called in static or constant expressions are
+`const` functions, and struct/enum constructors.
+
+To fix this error, you can declare `create_some` as a constant function:
+
 ```
+const fn create_some() -> Option<u8> { // declared as a const function
+    Some(1)
+}
 
-See [RFC 911] for more details on the design of `const fn`s.
+const FOO: Option<u8> = create_some(); // ok!
 
-[RFC 911]: https://github.com/rust-lang/rfcs/blob/master/text/0911-const-fn.md
+// These are also working:
+struct Bar {
+    x: u8,
+}
+
+const OTHER_FOO: Option<u8> = Some(1);
+const BAR: Bar = Bar {x: 1};
+```