]> git.lizzy.rs Git - rust.git/blob - src/librustc_passes/diagnostics.rs
Rollup merge of #48560 - bdrewery:freebsd-struct-abi, r=estebank
[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 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 E0197: r##"
86 Inherent implementations (one that do not implement a trait but provide
87 methods associated with a type) are always safe because they are not
88 implementing an unsafe trait. Removing the `unsafe` keyword from the inherent
89 implementation will resolve this error.
90
91 ```compile_fail,E0197
92 struct Foo;
93
94 // this will cause this error
95 unsafe impl Foo { }
96 // converting it to this will fix it
97 impl Foo { }
98 ```
99 "##,
100
101 E0198: r##"
102 A negative implementation is one that excludes a type from implementing a
103 particular trait. Not being able to use a trait is always a safe operation,
104 so negative implementations are always safe and never need to be marked as
105 unsafe.
106
107 ```compile_fail
108 #![feature(optin_builtin_traits)]
109
110 struct Foo;
111
112 // unsafe is unnecessary
113 unsafe impl !Clone for Foo { }
114 ```
115
116 This will compile:
117
118 ```ignore (ignore auto_trait future compatibility warning)
119 #![feature(optin_builtin_traits)]
120
121 struct Foo;
122
123 auto trait Enterprise {}
124
125 impl !Enterprise for Foo { }
126 ```
127
128 Please note that negative impls are only allowed for auto traits.
129 "##,
130
131 E0267: r##"
132 This error indicates the use of a loop keyword (`break` or `continue`) inside a
133 closure but outside of any loop. Erroneous code example:
134
135 ```compile_fail,E0267
136 let w = || { break; }; // error: `break` inside of a closure
137 ```
138
139 `break` and `continue` keywords can be used as normal inside closures as long as
140 they are also contained within a loop. To halt the execution of a closure you
141 should instead use a return statement. Example:
142
143 ```
144 let w = || {
145     for _ in 0..10 {
146         break;
147     }
148 };
149
150 w();
151 ```
152 "##,
153
154 E0268: r##"
155 This error indicates the use of a loop keyword (`break` or `continue`) outside
156 of a loop. Without a loop to break out of or continue in, no sensible action can
157 be taken. Erroneous code example:
158
159 ```compile_fail,E0268
160 fn some_func() {
161     break; // error: `break` outside of loop
162 }
163 ```
164
165 Please verify that you are using `break` and `continue` only in loops. Example:
166
167 ```
168 fn some_func() {
169     for _ in 0..10 {
170         break; // ok!
171     }
172 }
173 ```
174 "##,
175
176 E0379: r##"
177 Trait methods cannot be declared `const` by design. For more information, see
178 [RFC 911].
179
180 [RFC 911]: https://github.com/rust-lang/rfcs/pull/911
181 "##,
182
183 E0380: r##"
184 Auto traits cannot have methods or associated items.
185 For more information see the [opt-in builtin traits RFC][RFC 19].
186
187 [RFC 19]: https://github.com/rust-lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md
188 "##,
189
190 E0449: r##"
191 A visibility qualifier was used when it was unnecessary. Erroneous code
192 examples:
193
194 ```compile_fail,E0449
195 struct Bar;
196
197 trait Foo {
198     fn foo();
199 }
200
201 pub impl Bar {} // error: unnecessary visibility qualifier
202
203 pub impl Foo for Bar { // error: unnecessary visibility qualifier
204     pub fn foo() {} // error: unnecessary visibility qualifier
205 }
206 ```
207
208 To fix this error, please remove the visibility qualifier when it is not
209 required. Example:
210
211 ```
212 struct Bar;
213
214 trait Foo {
215     fn foo();
216 }
217
218 // Directly implemented methods share the visibility of the type itself,
219 // so `pub` is unnecessary here
220 impl Bar {}
221
222 // Trait methods share the visibility of the trait, so `pub` is
223 // unnecessary in either case
224 impl Foo for Bar {
225     fn foo() {}
226 }
227 ```
228 "##,
229
230
231 E0579: r##"
232 When matching against an exclusive range, the compiler verifies that the range
233 is non-empty. Exclusive range patterns include the start point but not the end
234 point, so this is equivalent to requiring the start of the range to be less
235 than the end of the range.
236
237 For example:
238
239 ```compile_fail
240 match 5u32 {
241     // This range is ok, albeit pointless.
242     1 .. 2 => {}
243     // This range is empty, and the compiler can tell.
244     5 .. 5 => {}
245 }
246 ```
247 "##,
248
249 E0590: r##"
250 `break` or `continue` must include a label when used in the condition of a
251 `while` loop.
252
253 Example of erroneous code:
254
255 ```compile_fail
256 while break {}
257 ```
258
259 To fix this, add a label specifying which loop is being broken out of:
260 ```
261 'foo: while break 'foo {}
262 ```
263 "##,
264
265 E0571: r##"
266 A `break` statement with an argument appeared in a non-`loop` loop.
267
268 Example of erroneous code:
269
270 ```compile_fail,E0571
271 # let mut i = 1;
272 # fn satisfied(n: usize) -> bool { n % 23 == 0 }
273 let result = while true {
274     if satisfied(i) {
275         break 2*i; // error: `break` with value from a `while` loop
276     }
277     i += 1;
278 };
279 ```
280
281 The `break` statement can take an argument (which will be the value of the loop
282 expression if the `break` statement is executed) in `loop` loops, but not
283 `for`, `while`, or `while let` loops.
284
285 Make sure `break value;` statements only occur in `loop` loops:
286
287 ```
288 # let mut i = 1;
289 # fn satisfied(n: usize) -> bool { n % 23 == 0 }
290 let result = loop { // ok!
291     if satisfied(i) {
292         break 2*i;
293     }
294     i += 1;
295 };
296 ```
297 "##
298 }
299
300 register_diagnostics! {
301     E0226, // only a single explicit lifetime bound is permitted
302     E0472, // asm! is unsupported on this target
303     E0561, // patterns aren't allowed in function pointer types
304     E0567, // auto traits can not have generic parameters
305     E0568, // auto traits can not have super traits
306     E0642, // patterns aren't allowed in methods without bodies
307     E0666, // nested `impl Trait` is illegal
308     E0667, // `impl Trait` in projections
309 }