]> git.lizzy.rs Git - rust.git/blob - src/librustc_passes/diagnostics.rs
d031694d85308a1d1cbc97f9aaec3f21a2540acf
[rust.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
35 E0130: r##"
36 You declared a pattern as an argument in a foreign function declaration.
37 Erroneous code example:
38
39 ```compile_fail
40 extern {
41     fn foo((a, b): (u32, u32)); // error: patterns aren't allowed in foreign
42                                 //        function declarations
43 }
44 ```
45
46 Please replace the pattern argument with a regular one. Example:
47
48 ```
49 struct SomeStruct {
50     a: u32,
51     b: u32,
52 }
53
54 extern {
55     fn foo(s: SomeStruct); // ok!
56 }
57 ```
58
59 Or:
60
61 ```
62 extern {
63     fn foo(a: (u32, u32)); // ok!
64 }
65 ```
66 "##,
67
68 E0197: r##"
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.
73
74 ```compile_fail,E0197
75 struct Foo;
76
77 // this will cause this error
78 unsafe impl Foo { }
79 // converting it to this will fix it
80 impl Foo { }
81 ```
82 "##,
83
84 E0198: r##"
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
88 unsafe.
89
90 ```compile_fail
91 #![feature(optin_builtin_traits)]
92
93 struct Foo;
94
95 // unsafe is unnecessary
96 unsafe impl !Clone for Foo { }
97 ```
98
99 This will compile:
100
101 ```ignore (ignore auto_trait future compatibility warning)
102 #![feature(optin_builtin_traits)]
103
104 struct Foo;
105
106 auto trait Enterprise {}
107
108 impl !Enterprise for Foo { }
109 ```
110
111 Please note that negative impls are only allowed for auto traits.
112 "##,
113
114 E0267: r##"
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:
117
118 ```compile_fail,E0267
119 let w = || { break; }; // error: `break` inside of a closure
120 ```
121
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:
125
126 ```
127 let w = || {
128     for _ in 0..10 {
129         break;
130     }
131 };
132
133 w();
134 ```
135 "##,
136
137 E0268: r##"
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:
141
142 ```compile_fail,E0268
143 fn some_func() {
144     break; // error: `break` outside of loop
145 }
146 ```
147
148 Please verify that you are using `break` and `continue` only in loops. Example:
149
150 ```
151 fn some_func() {
152     for _ in 0..10 {
153         break; // ok!
154     }
155 }
156 ```
157 "##,
158
159 E0379: r##"
160 Trait methods cannot be declared `const` by design. For more information, see
161 [RFC 911].
162
163 [RFC 911]: https://github.com/rust-lang/rfcs/pull/911
164 "##,
165
166 E0380: r##"
167 Auto traits cannot have methods or associated items.
168 For more information see the [opt-in builtin traits RFC][RFC 19].
169
170 [RFC 19]: https://github.com/rust-lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md
171 "##,
172
173 E0449: r##"
174 A visibility qualifier was used when it was unnecessary. Erroneous code
175 examples:
176
177 ```compile_fail,E0449
178 struct Bar;
179
180 trait Foo {
181     fn foo();
182 }
183
184 pub impl Bar {} // error: unnecessary visibility qualifier
185
186 pub impl Foo for Bar { // error: unnecessary visibility qualifier
187     pub fn foo() {} // error: unnecessary visibility qualifier
188 }
189 ```
190
191 To fix this error, please remove the visibility qualifier when it is not
192 required. Example:
193
194 ```
195 struct Bar;
196
197 trait Foo {
198     fn foo();
199 }
200
201 // Directly implemented methods share the visibility of the type itself,
202 // so `pub` is unnecessary here
203 impl Bar {}
204
205 // Trait methods share the visibility of the trait, so `pub` is
206 // unnecessary in either case
207 impl Foo for Bar {
208     fn foo() {}
209 }
210 ```
211 "##,
212
213
214 E0590: r##"
215 `break` or `continue` must include a label when used in the condition of a
216 `while` loop.
217
218 Example of erroneous code:
219
220 ```compile_fail
221 while break {}
222 ```
223
224 To fix this, add a label specifying which loop is being broken out of:
225 ```
226 'foo: while break 'foo {}
227 ```
228 "##,
229
230 E0571: r##"
231 A `break` statement with an argument appeared in a non-`loop` loop.
232
233 Example of erroneous code:
234
235 ```compile_fail,E0571
236 # let mut i = 1;
237 # fn satisfied(n: usize) -> bool { n % 23 == 0 }
238 let result = while true {
239     if satisfied(i) {
240         break 2*i; // error: `break` with value from a `while` loop
241     }
242     i += 1;
243 };
244 ```
245
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.
249
250 Make sure `break value;` statements only occur in `loop` loops:
251
252 ```
253 # let mut i = 1;
254 # fn satisfied(n: usize) -> bool { n % 23 == 0 }
255 let result = loop { // ok!
256     if satisfied(i) {
257         break 2*i;
258     }
259     i += 1;
260 };
261 ```
262 "##,
263
264 E0695: r##"
265 A `break` statement without a label appeared inside a labeled block.
266
267 Example of erroneous code:
268
269 ```compile_fail,E0695
270 # #![feature(label_break_value)]
271 loop {
272     'a: {
273         break;
274     }
275 }
276 ```
277
278 Make sure to always label the `break`:
279
280 ```
281 # #![feature(label_break_value)]
282 'l: loop {
283     'a: {
284         break 'l;
285     }
286 }
287 ```
288
289 Or if you want to `break` the labeled block:
290
291 ```
292 # #![feature(label_break_value)]
293 loop {
294     'a: {
295         break 'a;
296     }
297     break;
298 }
299 ```
300 "##
301 }
302
303 register_diagnostics! {
304     E0226, // only a single explicit lifetime bound is permitted
305     E0472, // asm! is unsupported on this target
306     E0561, // patterns aren't allowed in function pointer types
307     E0567, // auto traits can not have generic parameters
308     E0568, // auto traits can not have super traits
309     E0642, // patterns aren't allowed in methods without bodies
310     E0666, // nested `impl Trait` is illegal
311     E0667, // `impl Trait` in projections
312     E0696, // `continue` pointing to a labeled block
313 }