1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #![allow(non_snake_case)]
13 register_long_diagnostics! {
16 Constants can only be initialized by a constant value or, in a future
17 version of Rust, a call to a const function. This error indicates the use
18 of a path (like a::b, or x) denoting something other than one of these
19 allowed items. Erroneous code xample:
22 const FOO: i32 = { let x = 0; x }; // 'x' isn't a constant nor a function!
25 To avoid it, you have to replace the non-constant value:
28 const FOO: i32 = { const X : i32 = 0; X };
30 const FOO2: i32 = { 0 }; // but brackets are useless here
36 You declared a pattern as an argument in a foreign function declaration.
37 Erroneous code example:
41 fn foo((a, b): (u32, u32)); // error: patterns aren't allowed in foreign
42 // function declarations
46 Please replace the pattern argument with a regular one. Example:
55 fn foo(s: SomeStruct); // ok!
63 fn foo(a: (u32, u32)); // ok!
69 Inherent implementations (one that do not implement a trait but provide
70 methods associated with a type) are always safe because they are not
71 implementing an unsafe trait. Removing the `unsafe` keyword from the inherent
72 implementation will resolve this error.
77 // this will cause this error
79 // converting it to this will fix it
85 A negative implementation is one that excludes a type from implementing a
86 particular trait. Not being able to use a trait is always a safe operation,
87 so negative implementations are always safe and never need to be marked as
91 #![feature(optin_builtin_traits)]
95 // unsafe is unnecessary
96 unsafe impl !Clone for Foo { }
101 ```ignore (ignore auto_trait future compatibility warning)
102 #![feature(optin_builtin_traits)]
106 auto trait Enterprise {}
108 impl !Enterprise for Foo { }
111 Please note that negative impls are only allowed for auto traits.
115 This error indicates the use of a loop keyword (`break` or `continue`) inside a
116 closure but outside of any loop. Erroneous code example:
118 ```compile_fail,E0267
119 let w = || { break; }; // error: `break` inside of a closure
122 `break` and `continue` keywords can be used as normal inside closures as long as
123 they are also contained within a loop. To halt the execution of a closure you
124 should instead use a return statement. Example:
138 This error indicates the use of a loop keyword (`break` or `continue`) outside
139 of a loop. Without a loop to break out of or continue in, no sensible action can
140 be taken. Erroneous code example:
142 ```compile_fail,E0268
144 break; // error: `break` outside of loop
148 Please verify that you are using `break` and `continue` only in loops. Example:
160 Trait methods cannot be declared `const` by design. For more information, see
163 [RFC 911]: https://github.com/rust-lang/rfcs/pull/911
167 Auto traits cannot have methods or associated items.
168 For more information see the [opt-in builtin traits RFC][RFC 19].
170 [RFC 19]: https://github.com/rust-lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md
174 A visibility qualifier was used when it was unnecessary. Erroneous code
177 ```compile_fail,E0449
184 pub impl Bar {} // error: unnecessary visibility qualifier
186 pub impl Foo for Bar { // error: unnecessary visibility qualifier
187 pub fn foo() {} // error: unnecessary visibility qualifier
191 To fix this error, please remove the visibility qualifier when it is not
201 // Directly implemented methods share the visibility of the type itself,
202 // so `pub` is unnecessary here
205 // Trait methods share the visibility of the trait, so `pub` is
206 // unnecessary in either case
215 `break` or `continue` must include a label when used in the condition of a
218 Example of erroneous code:
224 To fix this, add a label specifying which loop is being broken out of:
226 'foo: while break 'foo {}
231 A `break` statement with an argument appeared in a non-`loop` loop.
233 Example of erroneous code:
235 ```compile_fail,E0571
237 # fn satisfied(n: usize) -> bool { n % 23 == 0 }
238 let result = while true {
240 break 2*i; // error: `break` with value from a `while` loop
246 The `break` statement can take an argument (which will be the value of the loop
247 expression if the `break` statement is executed) in `loop` loops, but not
248 `for`, `while`, or `while let` loops.
250 Make sure `break value;` statements only occur in `loop` loops:
254 # fn satisfied(n: usize) -> bool { n % 23 == 0 }
255 let result = loop { // ok!
265 Trait methods currently cannot take patterns as arguments.
267 Example of erroneous code:
269 ```compile_fail,E0642
271 fn foo((x, y): (i32, i32)); // error: patterns aren't allowed
276 You can instead use a single name for the argument:
280 fn foo(x_and_y: (i32, i32)); // ok!
286 A `break` statement without a label appeared inside a labeled block.
288 Example of erroneous code:
290 ```compile_fail,E0695
291 # #![feature(label_break_value)]
299 Make sure to always label the `break`:
302 # #![feature(label_break_value)]
310 Or if you want to `break` the labeled block:
313 # #![feature(label_break_value)]
324 register_diagnostics! {
325 E0226, // only a single explicit lifetime bound is permitted
326 E0472, // asm! is unsupported on this target
327 E0561, // patterns aren't allowed in function pointer types
328 E0567, // auto traits can not have generic parameters
329 E0568, // auto traits can not have super traits
330 E0666, // nested `impl Trait` is illegal
331 E0667, // `impl Trait` in projections
332 E0696, // `continue` pointing to a labeled block
333 E0706, // `async fn` in trait