]> git.proxmox.com Git - rustc.git/blob - src/librustc_passes/diagnostics.rs
New upstream version 1.23.0+dfsg1
[rustc.git] / src / librustc_passes / diagnostics.rs
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.
4 //
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.
10
11 #![allow(non_snake_case)]
12
13 register_long_diagnostics! {
14 /*
15 E0014: r##"
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:
20
21 ```compile_fail
22 const FOO: i32 = { let x = 0; x }; // 'x' isn't a constant nor a function!
23 ```
24
25 To avoid it, you have to replace the non-constant value:
26
27 ```
28 const FOO: i32 = { const X : i32 = 0; X };
29 // or even:
30 const FOO2: i32 = { 0 }; // but brackets are useless here
31 ```
32 "##,
33 */
34 E0030: r##"
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
38 range.
39
40 For example:
41
42 ```compile_fail
43 match 5u32 {
44 // This range is ok, albeit pointless.
45 1 ... 1 => {}
46 // This range is empty, and the compiler can tell.
47 1000 ... 5 => {}
48 }
49 ```
50 "##,
51
52 E0130: r##"
53 You declared a pattern as an argument in a foreign function declaration.
54 Erroneous code example:
55
56 ```compile_fail
57 extern {
58 fn foo((a, b): (u32, u32)); // error: patterns aren't allowed in foreign
59 // function declarations
60 }
61 ```
62
63 Please replace the pattern argument with a regular one. Example:
64
65 ```
66 struct SomeStruct {
67 a: u32,
68 b: u32,
69 }
70
71 extern {
72 fn foo(s: SomeStruct); // ok!
73 }
74 ```
75
76 Or:
77
78 ```
79 extern {
80 fn foo(a: (u32, u32)); // ok!
81 }
82 ```
83 "##,
84
85 E0265: r##"
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.
88
89 For example, neither of the following can be sensibly compiled:
90
91 ```compile_fail,E0265
92 const X: u32 = X;
93 ```
94
95 ```compile_fail,E0265
96 const X: u32 = Y;
97 const Y: u32 = X;
98 ```
99 "##,
100
101 E0267: r##"
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:
104
105 ```compile_fail,E0267
106 let w = || { break; }; // error: `break` inside of a closure
107 ```
108
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:
112
113 ```
114 let w = || {
115 for _ in 0..10 {
116 break;
117 }
118 };
119
120 w();
121 ```
122 "##,
123
124 E0268: r##"
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:
128
129 ```compile_fail,E0268
130 fn some_func() {
131 break; // error: `break` outside of loop
132 }
133 ```
134
135 Please verify that you are using `break` and `continue` only in loops. Example:
136
137 ```
138 fn some_func() {
139 for _ in 0..10 {
140 break; // ok!
141 }
142 }
143 ```
144 "##,
145
146 E0379: r##"
147 Trait methods cannot be declared `const` by design. For more information, see
148 [RFC 911].
149
150 [RFC 911]: https://github.com/rust-lang/rfcs/pull/911
151 "##,
152
153 E0449: r##"
154 A visibility qualifier was used when it was unnecessary. Erroneous code
155 examples:
156
157 ```compile_fail,E0449
158 struct Bar;
159
160 trait Foo {
161 fn foo();
162 }
163
164 pub impl Bar {} // error: unnecessary visibility qualifier
165
166 pub impl Foo for Bar { // error: unnecessary visibility qualifier
167 pub fn foo() {} // error: unnecessary visibility qualifier
168 }
169 ```
170
171 To fix this error, please remove the visibility qualifier when it is not
172 required. Example:
173
174 ```
175 struct Bar;
176
177 trait Foo {
178 fn foo();
179 }
180
181 // Directly implemented methods share the visibility of the type itself,
182 // so `pub` is unnecessary here
183 impl Bar {}
184
185 // Trait methods share the visibility of the trait, so `pub` is
186 // unnecessary in either case
187 impl Foo for Bar {
188 fn foo() {}
189 }
190 ```
191 "##,
192
193
194 E0579: r##"
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.
199
200 For example:
201
202 ```compile_fail
203 match 5u32 {
204 // This range is ok, albeit pointless.
205 1 .. 2 => {}
206 // This range is empty, and the compiler can tell.
207 5 .. 5 => {}
208 }
209 ```
210 "##,
211
212 E0590: r##"
213 `break` or `continue` must include a label when used in the condition of a
214 `while` loop.
215
216 Example of erroneous code:
217
218 ```compile_fail
219 while break {}
220 ```
221
222 To fix this, add a label specifying which loop is being broken out of:
223 ```
224 'foo: while break 'foo {}
225 ```
226 "##,
227
228 E0571: r##"
229 A `break` statement with an argument appeared in a non-`loop` loop.
230
231 Example of erroneous code:
232
233 ```compile_fail,E0571
234 # let mut i = 1;
235 # fn satisfied(n: usize) -> bool { n % 23 == 0 }
236 let result = while true {
237 if satisfied(i) {
238 break 2*i; // error: `break` with value from a `while` loop
239 }
240 i += 1;
241 };
242 ```
243
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.
247
248 Make sure `break value;` statements only occur in `loop` loops:
249
250 ```
251 # let mut i = 1;
252 # fn satisfied(n: usize) -> bool { n % 23 == 0 }
253 let result = loop { // ok!
254 if satisfied(i) {
255 break 2*i;
256 }
257 i += 1;
258 };
259 ```
260 "##
261 }
262
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
268 }