about summary refs log tree commit diff
path: root/src/librustc_error_codes/error_codes
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-11-22 22:03:11 +0000
committerbors <bors@rust-lang.org>2019-11-22 22:03:11 +0000
commita449535bbc7912c4adc1bbf2ab2738d0442f212c (patch)
tree40cae34afe14332b5c35ee5d819261fbaffcaee7 /src/librustc_error_codes/error_codes
parent5fa0af2327944bd806b2fa382d4e983149ae7e4a (diff)
parent56512b9d427012321384b91dcde5dc8daa83cf89 (diff)
downloadrust-a449535bbc7912c4adc1bbf2ab2738d0442f212c.tar.gz
rust-a449535bbc7912c4adc1bbf2ab2738d0442f212c.zip
Auto merge of #66640 - Centril:rollup-862009l, r=Centril
Rollup of 8 pull requests

Successful merges:

 - #66183 (*Syntactically* permit visibilities on trait items & enum variants)
 - #66566 (Document pitfall with `impl PartialEq<B> for A`)
 - #66575 (Remove pretty printing of specific nodes in AST)
 - #66587 (Handle statics in MIR as const pointers)
 - #66619 (follow the convention in this file to use third-person singular verbs)
 - #66633 (Error code's long explanation cleanup)
 - #66637 (fix reoccuring typo: dereferencable -> dereferenceable)
 - #66639 (resolve: more declarative `fresh_binding`)

Failed merges:

r? @ghost
Diffstat (limited to 'src/librustc_error_codes/error_codes')
-rw-r--r--src/librustc_error_codes/error_codes/E0015.md36
-rw-r--r--src/librustc_error_codes/error_codes/E0023.md9
-rw-r--r--src/librustc_error_codes/error_codes/E0033.md2
-rw-r--r--src/librustc_error_codes/error_codes/E0038.md4
-rw-r--r--src/librustc_error_codes/error_codes/E0057.md10
-rw-r--r--src/librustc_error_codes/error_codes/E0061.md10
6 files changed, 54 insertions, 17 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};
+```
diff --git a/src/librustc_error_codes/error_codes/E0023.md b/src/librustc_error_codes/error_codes/E0023.md
index 23a9d22a60d..c1d85705da3 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 c49cedf2d58..735a2d1f3fe 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 21b5eb47480..25e380b02e6 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<Trait>) {
 
 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 e11c07f835a..bb5e4b48d2d 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 3386dff2c85..143251c13b0 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.