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 This error indicates that a static or constant references itself.
87 All statics and constants need to resolve to a value in an acyclic manner.
89 For example, neither of the following can be sensibly compiled:
102 This error indicates the use of a loop keyword (`break` or `continue`) inside a
103 closure but outside of any loop. Erroneous code example:
105 ```compile_fail,E0267
106 let w = || { break; }; // error: `break` inside of a closure
109 `break` and `continue` keywords can be used as normal inside closures as long as
110 they are also contained within a loop. To halt the execution of a closure you
111 should instead use a return statement. Example:
125 This error indicates the use of a loop keyword (`break` or `continue`) outside
126 of a loop. Without a loop to break out of or continue in, no sensible action can
127 be taken. Erroneous code example:
129 ```compile_fail,E0268
131 break; // error: `break` outside of loop
135 Please verify that you are using `break` and `continue` only in loops. Example:
147 Trait methods cannot be declared `const` by design. For more information, see
150 [RFC 911]: https://github.com/rust-lang/rfcs/pull/911
154 A visibility qualifier was used when it was unnecessary. Erroneous code
157 ```compile_fail,E0449
164 pub impl Bar {} // error: unnecessary visibility qualifier
166 pub impl Foo for Bar { // error: unnecessary visibility qualifier
167 pub fn foo() {} // error: unnecessary visibility qualifier
171 To fix this error, please remove the visibility qualifier when it is not
181 // Directly implemented methods share the visibility of the type itself,
182 // so `pub` is unnecessary here
185 // Trait methods share the visibility of the trait, so `pub` is
186 // unnecessary in either case
195 When matching against an exclusive range, the compiler verifies that the range
196 is non-empty. Exclusive range patterns include the start point but not the end
197 point, so this is equivalent to requiring the start of the range to be less
198 than the end of the range.
204 // This range is ok, albeit pointless.
206 // This range is empty, and the compiler can tell.
213 `break` or `continue` must include a label when used in the condition of a
216 Example of erroneous code:
222 To fix this, add a label specifying which loop is being broken out of:
224 'foo: while break 'foo {}
229 A `break` statement with an argument appeared in a non-`loop` loop.
231 Example of erroneous code:
233 ```compile_fail,E0571
235 # fn satisfied(n: usize) -> bool { n % 23 == 0 }
236 let result = while true {
238 break 2*i; // error: `break` with value from a `while` loop
244 The `break` statement can take an argument (which will be the value of the loop
245 expression if the `break` statement is executed) in `loop` loops, but not
246 `for`, `while`, or `while let` loops.
248 Make sure `break value;` statements only occur in `loop` loops:
252 # fn satisfied(n: usize) -> bool { n % 23 == 0 }
253 let result = loop { // ok!
263 register_diagnostics
! {
264 E0226
, // only a single explicit lifetime bound is permitted
265 E0472
, // asm! is unsupported on this target
266 E0561
, // patterns aren't allowed in function pointer types
267 E0642
, // patterns aren't allowed in methods without bodies