]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_passes/error_codes.rs
Auto merge of #64873 - popzxc:prettify-test-time, r=wesleywiser
[rust.git] / src / librustc_passes / error_codes.rs
index 1c61eb35497d7ab26adbdc83533d794d2b93cadf..a2626617afec33f880c11b431a50a54d5d40e730 100644 (file)
@@ -1,12 +1,15 @@
 syntax::register_diagnostics! {
-/*
 E0014: r##"
+#### Note: this error code is no longer emitted by the compiler.
+
 Constants can only be initialized by a constant value or, in a future
 version of Rust, a call to a const function. This error indicates the use
 of a path (like a::b, or x) denoting something other than one of these
-allowed items. Erroneous code xample:
+allowed items.
 
-```compile_fail
+Erroneous code example:
+
+```
 const FOO: i32 = { let x = 0; x }; // 'x' isn't a constant nor a function!
 ```
 
 const FOO2: i32 = { 0 }; // but brackets are useless here
 ```
 "##,
-*/
 
 E0130: r##"
 You declared a pattern as an argument in a foreign function declaration.
+
 Erroneous code example:
 
 ```compile_fail
@@ -53,6 +56,81 @@ struct SomeStruct {
 ```
 "##,
 
+// This shouldn't really ever trigger since the repeated value error comes first
+E0136: r##"
+A binary can only have one entry point, and by default that entry point is the
+function `main()`. If there are multiple such functions, please rename one.
+
+Erroneous code example:
+
+```compile_fail,E0136
+fn main() {
+    // ...
+}
+
+// ...
+
+fn main() { // error!
+    // ...
+}
+```
+"##,
+
+E0137: r##"
+More than one function was declared with the `#[main]` attribute.
+
+Erroneous code example:
+
+```compile_fail,E0137
+#![feature(main)]
+
+#[main]
+fn foo() {}
+
+#[main]
+fn f() {} // error: multiple functions with a `#[main]` attribute
+```
+
+This error indicates that the compiler found multiple functions with the
+`#[main]` attribute. This is an error because there must be a unique entry
+point into a Rust program. Example:
+
+```
+#![feature(main)]
+
+#[main]
+fn f() {} // ok!
+```
+"##,
+
+E0138: r##"
+More than one function was declared with the `#[start]` attribute.
+
+Erroneous code example:
+
+```compile_fail,E0138
+#![feature(start)]
+
+#[start]
+fn foo(argc: isize, argv: *const *const u8) -> isize {}
+
+#[start]
+fn f(argc: isize, argv: *const *const u8) -> isize {}
+// error: multiple 'start' functions
+```
+
+This error indicates that the compiler found multiple functions with the
+`#[start]` attribute. This is an error because there must be a unique entry
+point into a Rust program. Example:
+
+```
+#![feature(start)]
+
+#[start]
+fn foo(argc: isize, argv: *const *const u8) -> isize { 0 } // ok!
+```
+"##,
+
 E0197: r##"
 Inherent implementations (one that do not implement a trait but provide
 methods associated with a type) are always safe because they are not
@@ -198,202 +276,166 @@ fn foo() {}
 ```
 "##,
 
+E0512: r##"
+Transmute with two differently sized types was attempted. Erroneous code
+example:
 
-E0590: r##"
-`break` or `continue` must include a label when used in the condition of a
-`while` loop.
-
-Example of erroneous code:
+```compile_fail,E0512
+fn takes_u8(_: u8) {}
 
-```compile_fail
-while break {}
+fn main() {
+    unsafe { takes_u8(::std::mem::transmute(0u16)); }
+    // error: cannot transmute between types of different sizes,
+    //        or dependently-sized types
+}
 ```
 
-To fix this, add a label specifying which loop is being broken out of:
+Please use types with same size or use the expected type directly. Example:
+
 ```
-'foo: while break 'foo {}
+fn takes_u8(_: u8) {}
+
+fn main() {
+    unsafe { takes_u8(::std::mem::transmute(0i8)); } // ok!
+    // or:
+    unsafe { takes_u8(0u8); } // ok!
+}
 ```
 "##,
 
-E0571: r##"
-A `break` statement with an argument appeared in a non-`loop` loop.
+E0561: r##"
+A non-ident or non-wildcard pattern has been used as a parameter of a function
+pointer type.
 
-Example of erroneous code:
+Erroneous code example:
 
-```compile_fail,E0571
-# let mut i = 1;
-# fn satisfied(n: usize) -> bool { n % 23 == 0 }
-let result = while true {
-    if satisfied(i) {
-        break 2*i; // error: `break` with value from a `while` loop
-    }
-    i += 1;
-};
+```compile_fail,E0561
+type A1 = fn(mut param: u8); // error!
+type A2 = fn(&param: u32); // error!
 ```
 
-The `break` statement can take an argument (which will be the value of the loop
-expression if the `break` statement is executed) in `loop` loops, but not
-`for`, `while`, or `while let` loops.
+When using an alias over a function type, you cannot e.g. denote a parameter as
+being mutable.
 
-Make sure `break value;` statements only occur in `loop` loops:
+To fix the issue, remove patterns (`_` is allowed though). Example:
 
 ```
-# let mut i = 1;
-# fn satisfied(n: usize) -> bool { n % 23 == 0 }
-let result = loop { // ok!
-    if satisfied(i) {
-        break 2*i;
-    }
-    i += 1;
-};
+type A1 = fn(param: u8); // ok!
+type A2 = fn(_: u32); // ok!
 ```
-"##,
 
-E0642: r##"
-Trait methods currently cannot take patterns as arguments.
-
-Example of erroneous code:
-
-```compile_fail,E0642
-trait Foo {
-    fn foo((x, y): (i32, i32)); // error: patterns aren't allowed
-                                //        in trait methods
-}
-```
-
-You can instead use a single name for the argument:
+You can also omit the parameter name:
 
 ```
-trait Foo {
-    fn foo(x_and_y: (i32, i32)); // ok!
-}
+type A3 = fn(i16); // ok!
 ```
 "##,
 
-E0695: r##"
-A `break` statement without a label appeared inside a labeled block.
-
-Example of erroneous code:
+E0567: r##"
+Generics have been used on an auto trait.
 
-```compile_fail,E0695
-# #![feature(label_break_value)]
-loop {
-    'a: {
-        break;
-    }
-}
-```
-
-Make sure to always label the `break`:
+Erroneous code example:
 
-```
-# #![feature(label_break_value)]
-'l: loop {
-    'a: {
-        break 'l;
-    }
-}
-```
+```compile_fail,E0567
+#![feature(optin_builtin_traits)]
 
-Or if you want to `break` the labeled block:
+auto trait Generic<T> {} // error!
 
+fn main() {}
 ```
-# #![feature(label_break_value)]
-loop {
-    'a: {
-        break 'a;
-    }
-    break;
-}
-```
-"##,
 
-E0670: r##"
-Rust 2015 does not permit the use of `async fn`.
+Since an auto trait is implemented on all existing types, the
+compiler would not be able to infer the types of the trait's generic
+parameters.
 
-Example of erroneous code:
+To fix this issue, just remove the generics:
 
-```compile_fail,E0670
-async fn foo() {}
 ```
+#![feature(optin_builtin_traits)]
 
-Switch to the Rust 2018 edition to use `async fn`.
-"##,
+auto trait Generic {} // ok!
 
-// This shouldn't really ever trigger since the repeated value error comes first
-E0136: r##"
-A binary can only have one entry point, and by default that entry point is the
-function `main()`. If there are multiple such functions, please rename one.
+fn main() {}
+```
 "##,
 
-E0137: r##"
-More than one function was declared with the `#[main]` attribute.
+E0568: r##"
+A super trait has been added to an auto trait.
 
 Erroneous code example:
 
-```compile_fail,E0137
-#![feature(main)]
+```compile_fail,E0568
+#![feature(optin_builtin_traits)]
 
-#[main]
-fn foo() {}
+auto trait Bound : Copy {} // error!
 
-#[main]
-fn f() {} // error: multiple functions with a `#[main]` attribute
+fn main() {}
 ```
 
-This error indicates that the compiler found multiple functions with the
-`#[main]` attribute. This is an error because there must be a unique entry
-point into a Rust program. Example:
+Since an auto trait is implemented on all existing types, adding a super trait
+would filter out a lot of those types. In the current example, almost none of
+all the existing types could implement `Bound` because very few of them have the
+`Copy` trait.
 
-```
-#![feature(main)]
+To fix this issue, just remove the super trait:
 
-#[main]
-fn f() {} // ok!
 ```
-"##,
+#![feature(optin_builtin_traits)]
 
-E0138: r##"
-More than one function was declared with the `#[start]` attribute.
+auto trait Bound {} // ok!
 
-Erroneous code example:
+fn main() {}
+```
+"##,
 
-```compile_fail,E0138
-#![feature(start)]
+E0571: r##"
+A `break` statement with an argument appeared in a non-`loop` loop.
 
-#[start]
-fn foo(argc: isize, argv: *const *const u8) -> isize {}
+Example of erroneous code:
 
-#[start]
-fn f(argc: isize, argv: *const *const u8) -> isize {}
-// error: multiple 'start' functions
+```compile_fail,E0571
+# let mut i = 1;
+# fn satisfied(n: usize) -> bool { n % 23 == 0 }
+let result = while true {
+    if satisfied(i) {
+        break 2*i; // error: `break` with value from a `while` loop
+    }
+    i += 1;
+};
 ```
 
-This error indicates that the compiler found multiple functions with the
-`#[start]` attribute. This is an error because there must be a unique entry
-point into a Rust program. Example:
+The `break` statement can take an argument (which will be the value of the loop
+expression if the `break` statement is executed) in `loop` loops, but not
+`for`, `while`, or `while let` loops.
 
-```
-#![feature(start)]
+Make sure `break value;` statements only occur in `loop` loops:
 
-#[start]
-fn foo(argc: isize, argv: *const *const u8) -> isize { 0 } // ok!
+```
+# let mut i = 1;
+# fn satisfied(n: usize) -> bool { n % 23 == 0 }
+let result = loop { // ok!
+    if satisfied(i) {
+        break 2*i;
+    }
+    i += 1;
+};
 ```
 "##,
 
-E0601: r##"
-No `main` function was found in a binary crate. To fix this error, add a
-`main` function. For example:
+E0590: r##"
+`break` or `continue` must include a label when used in the condition of a
+`while` loop.
 
-```
-fn main() {
-    // Your program will start here.
-    println!("Hello world!");
-}
+Example of erroneous code:
+
+```compile_fail
+while break {}
 ```
 
-If you don't know the basics of Rust, you can go look to the Rust Book to get
-started: https://doc.rust-lang.org/book/
+To fix this, add a label specifying which loop is being broken out of:
+```
+'foo: while break 'foo {}
+```
 "##,
 
 E0591: r##"
@@ -474,39 +516,95 @@ extern "C" fn foo(userdata: Box<i32>) {
 [rfc401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
 "##,
 
-E0512: r##"
-Transmute with two differently sized types was attempted. Erroneous code
-example:
-
-```compile_fail,E0512
-fn takes_u8(_: u8) {}
+E0601: r##"
+No `main` function was found in a binary crate. To fix this error, add a
+`main` function. For example:
 
+```
 fn main() {
-    unsafe { takes_u8(::std::mem::transmute(0u16)); }
-    // error: cannot transmute between types of different sizes,
-    //        or dependently-sized types
+    // Your program will start here.
+    println!("Hello world!");
 }
 ```
 
-Please use types with same size or use the expected type directly. Example:
+If you don't know the basics of Rust, you can go look to the Rust Book to get
+started: https://doc.rust-lang.org/book/
+"##,
+
+E0642: r##"
+Trait methods currently cannot take patterns as arguments.
+
+Example of erroneous code:
 
+```compile_fail,E0642
+trait Foo {
+    fn foo((x, y): (i32, i32)); // error: patterns aren't allowed
+                                //        in trait methods
+}
 ```
-fn takes_u8(_: u8) {}
 
-fn main() {
-    unsafe { takes_u8(::std::mem::transmute(0i8)); } // ok!
-    // or:
-    unsafe { takes_u8(0u8); } // ok!
+You can instead use a single name for the argument:
+
+```
+trait Foo {
+    fn foo(x_and_y: (i32, i32)); // ok!
 }
 ```
 "##,
 
+E0695: r##"
+A `break` statement without a label appeared inside a labeled block.
+
+Example of erroneous code:
+
+```compile_fail,E0695
+# #![feature(label_break_value)]
+loop {
+    'a: {
+        break;
+    }
+}
+```
+
+Make sure to always label the `break`:
+
+```
+# #![feature(label_break_value)]
+'l: loop {
+    'a: {
+        break 'l;
+    }
+}
+```
+
+Or if you want to `break` the labeled block:
+
+```
+# #![feature(label_break_value)]
+loop {
+    'a: {
+        break 'a;
+    }
+    break;
+}
+```
+"##,
+
+E0670: r##"
+Rust 2015 does not permit the use of `async fn`.
+
+Example of erroneous code:
+
+```compile_fail,E0670
+async fn foo() {}
+```
+
+Switch to the Rust 2018 edition to use `async fn`.
+"##,
+
 ;
     E0226, // only a single explicit lifetime bound is permitted
     E0472, // asm! is unsupported on this target
-    E0561, // patterns aren't allowed in function pointer types
-    E0567, // auto traits can not have generic parameters
-    E0568, // auto traits can not have super traits
     E0666, // nested `impl Trait` is illegal
     E0667, // `impl Trait` in projections
     E0696, // `continue` pointing to a labeled block