]> git.lizzy.rs Git - rust.git/blob - src/librustc_passes/error_codes.rs
Rollup merge of #61247 - spastorino:eval-place-iterate, r=wesleywiser
[rust.git] / src / librustc_passes / error_codes.rs
1 #![allow(non_snake_case)]
2
3 use syntax::{register_diagnostic, register_diagnostics, register_long_diagnostics};
4
5 register_long_diagnostics! {
6 /*
7 E0014: r##"
8 Constants can only be initialized by a constant value or, in a future
9 version of Rust, a call to a const function. This error indicates the use
10 of a path (like a::b, or x) denoting something other than one of these
11 allowed items. Erroneous code xample:
12
13 ```compile_fail
14 const FOO: i32 = { let x = 0; x }; // 'x' isn't a constant nor a function!
15 ```
16
17 To avoid it, you have to replace the non-constant value:
18
19 ```
20 const FOO: i32 = { const X : i32 = 0; X };
21 // or even:
22 const FOO2: i32 = { 0 }; // but brackets are useless here
23 ```
24 "##,
25 */
26
27 E0130: r##"
28 You declared a pattern as an argument in a foreign function declaration.
29 Erroneous code example:
30
31 ```compile_fail
32 extern {
33     fn foo((a, b): (u32, u32)); // error: patterns aren't allowed in foreign
34                                 //        function declarations
35 }
36 ```
37
38 Please replace the pattern argument with a regular one. Example:
39
40 ```
41 struct SomeStruct {
42     a: u32,
43     b: u32,
44 }
45
46 extern {
47     fn foo(s: SomeStruct); // ok!
48 }
49 ```
50
51 Or:
52
53 ```
54 extern {
55     fn foo(a: (u32, u32)); // ok!
56 }
57 ```
58 "##,
59
60 E0197: r##"
61 Inherent implementations (one that do not implement a trait but provide
62 methods associated with a type) are always safe because they are not
63 implementing an unsafe trait. Removing the `unsafe` keyword from the inherent
64 implementation will resolve this error.
65
66 ```compile_fail,E0197
67 struct Foo;
68
69 // this will cause this error
70 unsafe impl Foo { }
71 // converting it to this will fix it
72 impl Foo { }
73 ```
74 "##,
75
76 E0198: r##"
77 A negative implementation is one that excludes a type from implementing a
78 particular trait. Not being able to use a trait is always a safe operation,
79 so negative implementations are always safe and never need to be marked as
80 unsafe.
81
82 ```compile_fail
83 #![feature(optin_builtin_traits)]
84
85 struct Foo;
86
87 // unsafe is unnecessary
88 unsafe impl !Clone for Foo { }
89 ```
90
91 This will compile:
92
93 ```ignore (ignore auto_trait future compatibility warning)
94 #![feature(optin_builtin_traits)]
95
96 struct Foo;
97
98 auto trait Enterprise {}
99
100 impl !Enterprise for Foo { }
101 ```
102
103 Please note that negative impls are only allowed for auto traits.
104 "##,
105
106 E0267: r##"
107 This error indicates the use of a loop keyword (`break` or `continue`) inside a
108 closure but outside of any loop. Erroneous code example:
109
110 ```compile_fail,E0267
111 let w = || { break; }; // error: `break` inside of a closure
112 ```
113
114 `break` and `continue` keywords can be used as normal inside closures as long as
115 they are also contained within a loop. To halt the execution of a closure you
116 should instead use a return statement. Example:
117
118 ```
119 let w = || {
120     for _ in 0..10 {
121         break;
122     }
123 };
124
125 w();
126 ```
127 "##,
128
129 E0268: r##"
130 This error indicates the use of a loop keyword (`break` or `continue`) outside
131 of a loop. Without a loop to break out of or continue in, no sensible action can
132 be taken. Erroneous code example:
133
134 ```compile_fail,E0268
135 fn some_func() {
136     break; // error: `break` outside of loop
137 }
138 ```
139
140 Please verify that you are using `break` and `continue` only in loops. Example:
141
142 ```
143 fn some_func() {
144     for _ in 0..10 {
145         break; // ok!
146     }
147 }
148 ```
149 "##,
150
151 E0379: r##"
152 Trait methods cannot be declared `const` by design. For more information, see
153 [RFC 911].
154
155 [RFC 911]: https://github.com/rust-lang/rfcs/pull/911
156 "##,
157
158 E0380: r##"
159 Auto traits cannot have methods or associated items.
160 For more information see the [opt-in builtin traits RFC][RFC 19].
161
162 [RFC 19]: https://github.com/rust-lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md
163 "##,
164
165 E0449: r##"
166 A visibility qualifier was used when it was unnecessary. Erroneous code
167 examples:
168
169 ```compile_fail,E0449
170 struct Bar;
171
172 trait Foo {
173     fn foo();
174 }
175
176 pub impl Bar {} // error: unnecessary visibility qualifier
177
178 pub impl Foo for Bar { // error: unnecessary visibility qualifier
179     pub fn foo() {} // error: unnecessary visibility qualifier
180 }
181 ```
182
183 To fix this error, please remove the visibility qualifier when it is not
184 required. Example:
185
186 ```
187 struct Bar;
188
189 trait Foo {
190     fn foo();
191 }
192
193 // Directly implemented methods share the visibility of the type itself,
194 // so `pub` is unnecessary here
195 impl Bar {}
196
197 // Trait methods share the visibility of the trait, so `pub` is
198 // unnecessary in either case
199 impl Foo for Bar {
200     fn foo() {}
201 }
202 ```
203 "##,
204
205
206 E0590: r##"
207 `break` or `continue` must include a label when used in the condition of a
208 `while` loop.
209
210 Example of erroneous code:
211
212 ```compile_fail
213 while break {}
214 ```
215
216 To fix this, add a label specifying which loop is being broken out of:
217 ```
218 'foo: while break 'foo {}
219 ```
220 "##,
221
222 E0571: r##"
223 A `break` statement with an argument appeared in a non-`loop` loop.
224
225 Example of erroneous code:
226
227 ```compile_fail,E0571
228 # let mut i = 1;
229 # fn satisfied(n: usize) -> bool { n % 23 == 0 }
230 let result = while true {
231     if satisfied(i) {
232         break 2*i; // error: `break` with value from a `while` loop
233     }
234     i += 1;
235 };
236 ```
237
238 The `break` statement can take an argument (which will be the value of the loop
239 expression if the `break` statement is executed) in `loop` loops, but not
240 `for`, `while`, or `while let` loops.
241
242 Make sure `break value;` statements only occur in `loop` loops:
243
244 ```
245 # let mut i = 1;
246 # fn satisfied(n: usize) -> bool { n % 23 == 0 }
247 let result = loop { // ok!
248     if satisfied(i) {
249         break 2*i;
250     }
251     i += 1;
252 };
253 ```
254 "##,
255
256 E0642: r##"
257 Trait methods currently cannot take patterns as arguments.
258
259 Example of erroneous code:
260
261 ```compile_fail,E0642
262 trait Foo {
263     fn foo((x, y): (i32, i32)); // error: patterns aren't allowed
264                                 //        in trait methods
265 }
266 ```
267
268 You can instead use a single name for the argument:
269
270 ```
271 trait Foo {
272     fn foo(x_and_y: (i32, i32)); // ok!
273 }
274 ```
275 "##,
276
277 E0695: r##"
278 A `break` statement without a label appeared inside a labeled block.
279
280 Example of erroneous code:
281
282 ```compile_fail,E0695
283 # #![feature(label_break_value)]
284 loop {
285     'a: {
286         break;
287     }
288 }
289 ```
290
291 Make sure to always label the `break`:
292
293 ```
294 # #![feature(label_break_value)]
295 'l: loop {
296     'a: {
297         break 'l;
298     }
299 }
300 ```
301
302 Or if you want to `break` the labeled block:
303
304 ```
305 # #![feature(label_break_value)]
306 loop {
307     'a: {
308         break 'a;
309     }
310     break;
311 }
312 ```
313 "##,
314
315 E0670: r##"
316 Rust 2015 does not permit the use of `async fn`.
317
318 Example of erroneous code:
319
320 ```compile_fail,E0670
321 async fn foo() {}
322 ```
323
324 Switch to the Rust 2018 edition to use `async fn`.
325 "##
326 }
327
328 register_diagnostics! {
329     E0226, // only a single explicit lifetime bound is permitted
330     E0472, // asm! is unsupported on this target
331     E0561, // patterns aren't allowed in function pointer types
332     E0567, // auto traits can not have generic parameters
333     E0568, // auto traits can not have super traits
334     E0666, // nested `impl Trait` is illegal
335     E0667, // `impl Trait` in projections
336     E0696, // `continue` pointing to a labeled block
337     E0706, // `async fn` in trait
338 }