1 syntax::register_diagnostics! {
4 Constants can only be initialized by a constant value or, in a future
5 version of Rust, a call to a const function. This error indicates the use
6 of a path (like a::b, or x) denoting something other than one of these
7 allowed items. Erroneous code xample:
10 const FOO: i32 = { let x = 0; x }; // 'x' isn't a constant nor a function!
13 To avoid it, you have to replace the non-constant value:
16 const FOO: i32 = { const X : i32 = 0; X };
18 const FOO2: i32 = { 0 }; // but brackets are useless here
24 You declared a pattern as an argument in a foreign function declaration.
25 Erroneous code example:
29 fn foo((a, b): (u32, u32)); // error: patterns aren't allowed in foreign
30 // function declarations
34 Please replace the pattern argument with a regular one. Example:
43 fn foo(s: SomeStruct); // ok!
51 fn foo(a: (u32, u32)); // ok!
57 Inherent implementations (one that do not implement a trait but provide
58 methods associated with a type) are always safe because they are not
59 implementing an unsafe trait. Removing the `unsafe` keyword from the inherent
60 implementation will resolve this error.
65 // this will cause this error
67 // converting it to this will fix it
73 A negative implementation is one that excludes a type from implementing a
74 particular trait. Not being able to use a trait is always a safe operation,
75 so negative implementations are always safe and never need to be marked as
79 #![feature(optin_builtin_traits)]
83 // unsafe is unnecessary
84 unsafe impl !Clone for Foo { }
89 ```ignore (ignore auto_trait future compatibility warning)
90 #![feature(optin_builtin_traits)]
94 auto trait Enterprise {}
96 impl !Enterprise for Foo { }
99 Please note that negative impls are only allowed for auto traits.
103 This error indicates the use of a loop keyword (`break` or `continue`) inside a
104 closure but outside of any loop. Erroneous code example:
106 ```compile_fail,E0267
107 let w = || { break; }; // error: `break` inside of a closure
110 `break` and `continue` keywords can be used as normal inside closures as long as
111 they are also contained within a loop. To halt the execution of a closure you
112 should instead use a return statement. Example:
126 This error indicates the use of a loop keyword (`break` or `continue`) outside
127 of a loop. Without a loop to break out of or continue in, no sensible action can
128 be taken. Erroneous code example:
130 ```compile_fail,E0268
132 break; // error: `break` outside of a loop
136 Please verify that you are using `break` and `continue` only in loops. Example:
148 Trait methods cannot be declared `const` by design. For more information, see
151 [RFC 911]: https://github.com/rust-lang/rfcs/pull/911
155 Auto traits cannot have methods or associated items.
156 For more information see the [opt-in builtin traits RFC][RFC 19].
158 [RFC 19]: https://github.com/rust-lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md
162 A visibility qualifier was used when it was unnecessary. Erroneous code
165 ```compile_fail,E0449
172 pub impl Bar {} // error: unnecessary visibility qualifier
174 pub impl Foo for Bar { // error: unnecessary visibility qualifier
175 pub fn foo() {} // error: unnecessary visibility qualifier
179 To fix this error, please remove the visibility qualifier when it is not
189 // Directly implemented methods share the visibility of the type itself,
190 // so `pub` is unnecessary here
193 // Trait methods share the visibility of the trait, so `pub` is
194 // unnecessary in either case
203 `break` or `continue` must include a label when used in the condition of a
206 Example of erroneous code:
212 To fix this, add a label specifying which loop is being broken out of:
214 'foo: while break 'foo {}
219 A `break` statement with an argument appeared in a non-`loop` loop.
221 Example of erroneous code:
223 ```compile_fail,E0571
225 # fn satisfied(n: usize) -> bool { n % 23 == 0 }
226 let result = while true {
228 break 2*i; // error: `break` with value from a `while` loop
234 The `break` statement can take an argument (which will be the value of the loop
235 expression if the `break` statement is executed) in `loop` loops, but not
236 `for`, `while`, or `while let` loops.
238 Make sure `break value;` statements only occur in `loop` loops:
242 # fn satisfied(n: usize) -> bool { n % 23 == 0 }
243 let result = loop { // ok!
253 Trait methods currently cannot take patterns as arguments.
255 Example of erroneous code:
257 ```compile_fail,E0642
259 fn foo((x, y): (i32, i32)); // error: patterns aren't allowed
264 You can instead use a single name for the argument:
268 fn foo(x_and_y: (i32, i32)); // ok!
274 A `break` statement without a label appeared inside a labeled block.
276 Example of erroneous code:
278 ```compile_fail,E0695
279 # #![feature(label_break_value)]
287 Make sure to always label the `break`:
290 # #![feature(label_break_value)]
298 Or if you want to `break` the labeled block:
301 # #![feature(label_break_value)]
312 Rust 2015 does not permit the use of `async fn`.
314 Example of erroneous code:
316 ```compile_fail,E0670
320 Switch to the Rust 2018 edition to use `async fn`.
323 // This shouldn't really ever trigger since the repeated value error comes first
325 A binary can only have one entry point, and by default that entry point is the
326 function `main()`. If there are multiple such functions, please rename one.
330 More than one function was declared with the `#[main]` attribute.
332 Erroneous code example:
334 ```compile_fail,E0137
341 fn f() {} // error: multiple functions with a `#[main]` attribute
344 This error indicates that the compiler found multiple functions with the
345 `#[main]` attribute. This is an error because there must be a unique entry
346 point into a Rust program. Example:
357 More than one function was declared with the `#[start]` attribute.
359 Erroneous code example:
361 ```compile_fail,E0138
365 fn foo(argc: isize, argv: *const *const u8) -> isize {}
368 fn f(argc: isize, argv: *const *const u8) -> isize {}
369 // error: multiple 'start' functions
372 This error indicates that the compiler found multiple functions with the
373 `#[start]` attribute. This is an error because there must be a unique entry
374 point into a Rust program. Example:
380 fn foo(argc: isize, argv: *const *const u8) -> isize { 0 } // ok!
385 No `main` function was found in a binary crate. To fix this error, add a
386 `main` function. For example:
390 // Your program will start here.
391 println!("Hello world!");
395 If you don't know the basics of Rust, you can go look to the Rust Book to get
396 started: https://doc.rust-lang.org/book/
400 E0226, // only a single explicit lifetime bound is permitted
401 E0472, // asm! is unsupported on this target
402 E0561, // patterns aren't allowed in function pointer types
403 E0567, // auto traits can not have generic parameters
404 E0568, // auto traits can not have super traits
405 E0666, // nested `impl Trait` is illegal
406 E0667, // `impl Trait` in projections
407 E0696, // `continue` pointing to a labeled block
408 E0706, // `async fn` in trait