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