]> git.lizzy.rs Git - rust.git/blob - src/libsyntax/error_codes.rs
Rollup merge of #64229 - kawa-yoiko:unreachable-call-lint, r=estebank
[rust.git] / src / libsyntax / error_codes.rs
1 // Error messages for EXXXX errors.
2 // Each message should start and end with a new line, and be wrapped to 80
3 // characters.  In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use
4 // `:set tw=0` to disable.
5 register_diagnostics! {
6
7 E0178: r##"
8 In types, the `+` type operator has low precedence, so it is often necessary
9 to use parentheses.
10
11 For example:
12
13 ```compile_fail,E0178
14 trait Foo {}
15
16 struct Bar<'a> {
17     w: &'a Foo + Copy,   // error, use &'a (Foo + Copy)
18     x: &'a Foo + 'a,     // error, use &'a (Foo + 'a)
19     y: &'a mut Foo + 'a, // error, use &'a mut (Foo + 'a)
20     z: fn() -> Foo + 'a, // error, use fn() -> (Foo + 'a)
21 }
22 ```
23
24 More details can be found in [RFC 438].
25
26 [RFC 438]: https://github.com/rust-lang/rfcs/pull/438
27 "##,
28
29 E0536: r##"
30 The `not` cfg-predicate was malformed.
31
32 Erroneous code example:
33
34 ```compile_fail,E0536
35 #[cfg(not())] // error: expected 1 cfg-pattern
36 pub fn something() {}
37
38 pub fn main() {}
39 ```
40
41 The `not` predicate expects one cfg-pattern. Example:
42
43 ```
44 #[cfg(not(target_os = "linux"))] // ok!
45 pub fn something() {}
46
47 pub fn main() {}
48 ```
49
50 For more information about the cfg attribute, read:
51 https://doc.rust-lang.org/reference.html#conditional-compilation
52 "##,
53
54 E0537: r##"
55 An unknown predicate was used inside the `cfg` attribute.
56
57 Erroneous code example:
58
59 ```compile_fail,E0537
60 #[cfg(unknown())] // error: invalid predicate `unknown`
61 pub fn something() {}
62
63 pub fn main() {}
64 ```
65
66 The `cfg` attribute supports only three kinds of predicates:
67
68  * any
69  * all
70  * not
71
72 Example:
73
74 ```
75 #[cfg(not(target_os = "linux"))] // ok!
76 pub fn something() {}
77
78 pub fn main() {}
79 ```
80
81 For more information about the cfg attribute, read:
82 https://doc.rust-lang.org/reference.html#conditional-compilation
83 "##,
84
85 E0538: r##"
86 Attribute contains same meta item more than once.
87
88 Erroneous code example:
89
90 ```compile_fail,E0538
91 #[deprecated(
92     since="1.0.0",
93     note="First deprecation note.",
94     note="Second deprecation note." // error: multiple same meta item
95 )]
96 fn deprecated_function() {}
97 ```
98
99 Meta items are the key-value pairs inside of an attribute. Each key may only be
100 used once in each attribute.
101
102 To fix the problem, remove all but one of the meta items with the same key.
103
104 Example:
105
106 ```
107 #[deprecated(
108     since="1.0.0",
109     note="First deprecation note."
110 )]
111 fn deprecated_function() {}
112 ```
113 "##,
114
115 E0541: r##"
116 An unknown meta item was used.
117
118 Erroneous code example:
119
120 ```compile_fail,E0541
121 #[deprecated(
122     since="1.0.0",
123     // error: unknown meta item
124     reason="Example invalid meta item. Should be 'note'")
125 ]
126 fn deprecated_function() {}
127 ```
128
129 Meta items are the key-value pairs inside of an attribute. The keys provided
130 must be one of the valid keys for the specified attribute.
131
132 To fix the problem, either remove the unknown meta item, or rename it if you
133 provided the wrong name.
134
135 In the erroneous code example above, the wrong name was provided, so changing
136 to a correct one it will fix the error. Example:
137
138 ```
139 #[deprecated(
140     since="1.0.0",
141     note="This is a valid meta item for the deprecated attribute."
142 )]
143 fn deprecated_function() {}
144 ```
145 "##,
146
147 E0552: r##"
148 A unrecognized representation attribute was used.
149
150 Erroneous code example:
151
152 ```compile_fail,E0552
153 #[repr(D)] // error: unrecognized representation hint
154 struct MyStruct {
155     my_field: usize
156 }
157 ```
158
159 You can use a `repr` attribute to tell the compiler how you want a struct or
160 enum to be laid out in memory.
161
162 Make sure you're using one of the supported options:
163
164 ```
165 #[repr(C)] // ok!
166 struct MyStruct {
167     my_field: usize
168 }
169 ```
170
171 For more information about specifying representations, see the ["Alternative
172 Representations" section] of the Rustonomicon.
173
174 ["Alternative Representations" section]: https://doc.rust-lang.org/nomicon/other-reprs.html
175 "##,
176
177 E0554: r##"
178 Feature attributes are only allowed on the nightly release channel. Stable or
179 beta compilers will not comply.
180
181 Example of erroneous code (on a stable compiler):
182
183 ```ignore (depends on release channel)
184 #![feature(non_ascii_idents)] // error: `#![feature]` may not be used on the
185                               //        stable release channel
186 ```
187
188 If you need the feature, make sure to use a nightly release of the compiler
189 (but be warned that the feature may be removed or altered in the future).
190 "##,
191
192 E0557: r##"
193 A feature attribute named a feature that has been removed.
194
195 Erroneous code example:
196
197 ```compile_fail,E0557
198 #![feature(managed_boxes)] // error: feature has been removed
199 ```
200
201 Delete the offending feature attribute.
202 "##,
203
204 E0565: r##"
205 A literal was used in a built-in attribute that doesn't support literals.
206
207 Erroneous code example:
208
209 ```ignore (compile_fail not working here; see Issue #43707)
210 #[inline("always")] // error: unsupported literal
211 pub fn something() {}
212 ```
213
214 Literals in attributes are new and largely unsupported in built-in attributes.
215 Work to support literals where appropriate is ongoing. Try using an unquoted
216 name instead:
217
218 ```
219 #[inline(always)]
220 pub fn something() {}
221 ```
222 "##,
223
224 E0583: r##"
225 A file wasn't found for an out-of-line module.
226
227 Erroneous code example:
228
229 ```ignore (compile_fail not working here; see Issue #43707)
230 mod file_that_doesnt_exist; // error: file not found for module
231
232 fn main() {}
233 ```
234
235 Please be sure that a file corresponding to the module exists. If you
236 want to use a module named `file_that_doesnt_exist`, you need to have a file
237 named `file_that_doesnt_exist.rs` or `file_that_doesnt_exist/mod.rs` in the
238 same directory.
239 "##,
240
241 E0585: r##"
242 A documentation comment that doesn't document anything was found.
243
244 Erroneous code example:
245
246 ```compile_fail,E0585
247 fn main() {
248     // The following doc comment will fail:
249     /// This is a useless doc comment!
250 }
251 ```
252
253 Documentation comments need to be followed by items, including functions,
254 types, modules, etc. Examples:
255
256 ```
257 /// I'm documenting the following struct:
258 struct Foo;
259
260 /// I'm documenting the following function:
261 fn foo() {}
262 ```
263 "##,
264
265 E0586: r##"
266 An inclusive range was used with no end.
267
268 Erroneous code example:
269
270 ```compile_fail,E0586
271 fn main() {
272     let tmp = vec![0, 1, 2, 3, 4, 4, 3, 3, 2, 1];
273     let x = &tmp[1..=]; // error: inclusive range was used with no end
274 }
275 ```
276
277 An inclusive range needs an end in order to *include* it. If you just need a
278 start and no end, use a non-inclusive range (with `..`):
279
280 ```
281 fn main() {
282     let tmp = vec![0, 1, 2, 3, 4, 4, 3, 3, 2, 1];
283     let x = &tmp[1..]; // ok!
284 }
285 ```
286
287 Or put an end to your inclusive range:
288
289 ```
290 fn main() {
291     let tmp = vec![0, 1, 2, 3, 4, 4, 3, 3, 2, 1];
292     let x = &tmp[1..=3]; // ok!
293 }
294 ```
295 "##,
296
297 E0589: r##"
298 The value of `N` that was specified for `repr(align(N))` was not a power
299 of two, or was greater than 2^29.
300
301 ```compile_fail,E0589
302 #[repr(align(15))] // error: invalid `repr(align)` attribute: not a power of two
303 enum Foo {
304     Bar(u64),
305 }
306 ```
307 "##,
308
309 E0658: r##"
310 An unstable feature was used.
311
312 Erroneous code example:
313
314 ```compile_fail,E658
315 #[repr(u128)] // error: use of unstable library feature 'repr128'
316 enum Foo {
317     Bar(u64),
318 }
319 ```
320
321 If you're using a stable or a beta version of rustc, you won't be able to use
322 any unstable features. In order to do so, please switch to a nightly version of
323 rustc (by using rustup).
324
325 If you're using a nightly version of rustc, just add the corresponding feature
326 to be able to use it:
327
328 ```
329 #![feature(repr128)]
330
331 #[repr(u128)] // ok!
332 enum Foo {
333     Bar(u64),
334 }
335 ```
336 "##,
337
338 E0633: r##"
339 The `unwind` attribute was malformed.
340
341 Erroneous code example:
342
343 ```ignore (compile_fail not working here; see Issue #43707)
344 #[unwind()] // error: expected one argument
345 pub extern fn something() {}
346
347 fn main() {}
348 ```
349
350 The `#[unwind]` attribute should be used as follows:
351
352 - `#[unwind(aborts)]` -- specifies that if a non-Rust ABI function
353   should abort the process if it attempts to unwind. This is the safer
354   and preferred option.
355
356 - `#[unwind(allowed)]` -- specifies that a non-Rust ABI function
357   should be allowed to unwind. This can easily result in Undefined
358   Behavior (UB), so be careful.
359
360 NB. The default behavior here is "allowed", but this is unspecified
361 and likely to change in the future.
362
363 "##,
364
365 E0704: r##"
366 This error indicates that a incorrect visibility restriction was specified.
367
368 Example of erroneous code:
369
370 ```compile_fail,E0704
371 mod foo {
372     pub(foo) struct Bar {
373         x: i32
374     }
375 }
376 ```
377
378 To make struct `Bar` only visible in module `foo` the `in` keyword should be
379 used:
380 ```
381 mod foo {
382     pub(in crate::foo) struct Bar {
383         x: i32
384     }
385 }
386 # fn main() {}
387 ```
388
389 For more information see the Rust Reference on [Visibility].
390
391 [Visibility]: https://doc.rust-lang.org/reference/visibility-and-privacy.html
392 "##,
393
394 E0705: r##"
395 A `#![feature]` attribute was declared for a feature that is stable in
396 the current edition, but not in all editions.
397
398 Erroneous code example:
399
400 ```ignore (limited to a warning during 2018 edition development)
401 #![feature(rust_2018_preview)]
402 #![feature(test_2018_feature)] // error: the feature
403                                // `test_2018_feature` is
404                                // included in the Rust 2018 edition
405 ```
406
407 "##,
408
409 E0725: r##"
410 A feature attribute named a feature that was disallowed in the compiler
411 command line flags.
412
413 Erroneous code example:
414
415 ```ignore (can't specify compiler flags from doctests)
416 #![feature(never_type)] // error: the feature `never_type` is not in
417                         // the list of allowed features
418 ```
419
420 Delete the offending feature attribute, or add it to the list of allowed
421 features in the `-Z allow_features` flag.
422 "##,
423
424 ;
425
426     E0539, // incorrect meta item
427     E0540, // multiple rustc_deprecated attributes
428     E0542, // missing 'since'
429     E0543, // missing 'reason'
430     E0544, // multiple stability levels
431     E0545, // incorrect 'issue'
432     E0546, // missing 'feature'
433     E0547, // missing 'issue'
434 //  E0548, // replaced with a generic attribute input check
435     // rustc_deprecated attribute must be paired with either stable or unstable
436     // attribute
437     E0549,
438     E0550, // multiple deprecated attributes
439     E0551, // incorrect meta item
440     E0553, // multiple rustc_const_unstable attributes
441 //  E0555, // replaced with a generic attribute input check
442     E0556, // malformed feature, expected just one word
443     E0584, // file for module `..` found at both .. and ..
444     E0629, // missing 'feature' (rustc_const_unstable)
445     // rustc_const_unstable attribute must be paired with stable/unstable
446     // attribute
447     E0630,
448     E0693, // incorrect `repr(align)` attribute format
449 //  E0694, // an unknown tool name found in scoped attributes
450     E0703, // invalid ABI
451     E0717, // rustc_promotable without stability attribute
452 }