diff --git a/src/librustc_error_codes/error_codes/E0015.md b/src/librustc_error_codes/error_codes/E0015.md index 2bf59983fa93a..361cb425809d7 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 { + Some(1) +} +const FOO: Option = create_some(); // error! ``` -const FOO: Option = 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 { // declared as a const function + Some(1) +} -See [RFC 911] for more details on the design of `const fn`s. +const FOO: Option = 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 = Some(1); +const BAR: Bar = Bar {x: 1}; +``` diff --git a/src/librustc_error_codes/error_codes/E0023.md b/src/librustc_error_codes/error_codes/E0023.md index 23a9d22a60d82..c1d85705da3a9 100644 --- a/src/librustc_error_codes/error_codes/E0023.md +++ b/src/librustc_error_codes/error_codes/E0023.md @@ -2,11 +2,18 @@ A pattern attempted to extract an incorrect number of fields from a variant. Erroneous code example: -``` +```compile_fail,E0023 enum Fruit { Apple(String, String), Pear(u32), } + +let x = Fruit::Apple(String::new(), String::new()); + +match x { + Fruit::Apple(a) => {}, // error! + _ => {} +} ``` A pattern used to match against an enum variant must provide a sub-pattern for diff --git a/src/librustc_error_codes/error_codes/E0033.md b/src/librustc_error_codes/error_codes/E0033.md index c49cedf2d5869..735a2d1f3fe85 100644 --- a/src/librustc_error_codes/error_codes/E0033.md +++ b/src/librustc_error_codes/error_codes/E0033.md @@ -24,4 +24,4 @@ dereferencing the pointer. You can read more about trait objects in the [Trait Objects] section of the Reference. -[Trait Objects]: https://doc.rust-lang.org/reference/types.html#trait-objects \ No newline at end of file +[Trait Objects]: https://doc.rust-lang.org/reference/types.html#trait-objects diff --git a/src/librustc_error_codes/error_codes/E0038.md b/src/librustc_error_codes/error_codes/E0038.md index 21b5eb47480e6..25e380b02e647 100644 --- a/src/librustc_error_codes/error_codes/E0038.md +++ b/src/librustc_error_codes/error_codes/E0038.md @@ -62,7 +62,7 @@ cause this problem.) In such a case, the compiler cannot predict the return type of `foo()` in a situation like the following: -```compile_fail +```compile_fail,E0038 trait Trait { fn foo(&self) -> Self; } @@ -183,7 +183,7 @@ fn call_foo(thing: Box) { We don't just need to create a table of all implementations of all methods of `Trait`, we need to create such a table, for each different type fed to -`foo()`. In this case this turns out to be (10 types implementing `Trait`)*(3 +`foo()`. In this case this turns out to be (10 types implementing `Trait`)\*(3 types being fed to `foo()`) = 30 implementations! With real world traits these numbers can grow drastically. diff --git a/src/librustc_error_codes/error_codes/E0057.md b/src/librustc_error_codes/error_codes/E0057.md index e11c07f835ad7..bb5e4b48d2deb 100644 --- a/src/librustc_error_codes/error_codes/E0057.md +++ b/src/librustc_error_codes/error_codes/E0057.md @@ -1,8 +1,6 @@ -When invoking closures or other implementations of the function traits `Fn`, -`FnMut` or `FnOnce` using call notation, the number of parameters passed to the -function must match its definition. +An invalid number of arguments was given when calling a closure. -An example using a closure: +Erroneous code example: ```compile_fail,E0057 let f = |x| x * 3; @@ -11,6 +9,10 @@ let b = f(4); // this works! let c = f(2, 3); // invalid, too many parameters ``` +When invoking closures or other implementations of the function traits `Fn`, +`FnMut` or `FnOnce` using call notation, the number of parameters passed to the +function must match its definition. + A generic function must be treated similarly: ``` diff --git a/src/librustc_error_codes/error_codes/E0061.md b/src/librustc_error_codes/error_codes/E0061.md index 3386dff2c8513..143251c13b069 100644 --- a/src/librustc_error_codes/error_codes/E0061.md +++ b/src/librustc_error_codes/error_codes/E0061.md @@ -1,3 +1,13 @@ +An invalid number of arguments was passed when calling a function. + +Erroneous code example: + +```compile_fail,E0061 +fn f(u: i32) {} + +f(); // error! +``` + The number of arguments passed to a function must match the number of arguments specified in the function signature.