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
35 When matching against a range, the compiler verifies that the range is
36 non-empty. Range patterns include both end-points, so this is equivalent to
37 requiring the start of the range to be less than or equal to the end of the
44 // This range is ok, albeit pointless.
46 // This range is empty, and the compiler can tell.
53 You declared a pattern as an argument in a foreign function declaration.
54 Erroneous code example:
58 fn foo((a, b): (u32, u32)); // error: patterns aren't allowed in foreign
59 // function declarations
63 Please replace the pattern argument with a regular one. Example:
72 fn foo(s: SomeStruct); // ok!
80 fn foo(a: (u32, u32)); // ok!
86 Inherent implementations (one that do not implement a trait but provide
87 methods associated with a type) are always safe because they are not
88 implementing an unsafe trait. Removing the `unsafe` keyword from the inherent
89 implementation will resolve this error.
94 // this will cause this error
96 // converting it to this will fix it
102 A negative implementation is one that excludes a type from implementing a
103 particular trait. Not being able to use a trait is always a safe operation,
104 so negative implementations are always safe and never need to be marked as
108 #![feature(optin_builtin_traits)]
112 // unsafe is unnecessary
113 unsafe impl !Clone for Foo { }
118 ```ignore (ignore auto_trait future compatibility warning)
119 #![feature(optin_builtin_traits)]
123 auto trait Enterprise {}
125 impl !Enterprise for Foo { }
128 Please note that negative impls are only allowed for auto traits.
132 This error indicates the use of a loop keyword (`break` or `continue`) inside a
133 closure but outside of any loop. Erroneous code example:
135 ```compile_fail,E0267
136 let w = || { break; }; // error: `break` inside of a closure
139 `break` and `continue` keywords can be used as normal inside closures as long as
140 they are also contained within a loop. To halt the execution of a closure you
141 should instead use a return statement. Example:
155 This error indicates the use of a loop keyword (`break` or `continue`) outside
156 of a loop. Without a loop to break out of or continue in, no sensible action can
157 be taken. Erroneous code example:
159 ```compile_fail,E0268
161 break; // error: `break` outside of loop
165 Please verify that you are using `break` and `continue` only in loops. Example:
177 Trait methods cannot be declared `const` by design. For more information, see
180 [RFC 911]: https://github.com/rust-lang/rfcs/pull/911
184 Auto traits cannot have methods or associated items.
185 For more information see the [opt-in builtin traits RFC][RFC 19].
187 [RFC 19]: https://github.com/rust-lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md
191 A visibility qualifier was used when it was unnecessary. Erroneous code
194 ```compile_fail,E0449
201 pub impl Bar {} // error: unnecessary visibility qualifier
203 pub impl Foo for Bar { // error: unnecessary visibility qualifier
204 pub fn foo() {} // error: unnecessary visibility qualifier
208 To fix this error, please remove the visibility qualifier when it is not
218 // Directly implemented methods share the visibility of the type itself,
219 // so `pub` is unnecessary here
222 // Trait methods share the visibility of the trait, so `pub` is
223 // unnecessary in either case
232 When matching against an exclusive range, the compiler verifies that the range
233 is non-empty. Exclusive range patterns include the start point but not the end
234 point, so this is equivalent to requiring the start of the range to be less
235 than the end of the range.
241 // This range is ok, albeit pointless.
243 // This range is empty, and the compiler can tell.
250 `break` or `continue` must include a label when used in the condition of a
253 Example of erroneous code:
259 To fix this, add a label specifying which loop is being broken out of:
261 'foo: while break 'foo {}
266 A `break` statement with an argument appeared in a non-`loop` loop.
268 Example of erroneous code:
270 ```compile_fail,E0571
272 # fn satisfied(n: usize) -> bool { n % 23 == 0 }
273 let result = while true {
275 break 2*i; // error: `break` with value from a `while` loop
281 The `break` statement can take an argument (which will be the value of the loop
282 expression if the `break` statement is executed) in `loop` loops, but not
283 `for`, `while`, or `while let` loops.
285 Make sure `break value;` statements only occur in `loop` loops:
289 # fn satisfied(n: usize) -> bool { n % 23 == 0 }
290 let result = loop { // ok!
300 register_diagnostics! {
301 E0226, // only a single explicit lifetime bound is permitted
302 E0472, // asm! is unsupported on this target
303 E0561, // patterns aren't allowed in function pointer types
304 E0567, // auto traits can not have generic parameters
305 E0568, // auto traits can not have super traits
306 E0642, // patterns aren't allowed in methods without bodies
307 E0666, // nested `impl Trait` is illegal
308 E0667, // `impl Trait` in projections