]> git.lizzy.rs Git - rust.git/blob - src/libsyntax/error_codes.rs
Auto merge of #65094 - oxalica:linux-statx, r=alexcrichton
[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 E0550: r##"
148 More than one `deprecated` attribute has been put on an item.
149
150 Erroneous code example:
151
152 ```compile_fail,E0550
153 #[deprecated(note = "because why not?")]
154 #[deprecated(note = "right?")] // error!
155 fn the_banished() {}
156 ```
157
158 The `deprecated` attribute can only be present **once** on an item.
159
160 ```
161 #[deprecated(note = "because why not, right?")]
162 fn the_banished() {} // ok!
163 ```
164 "##,
165
166 E0551: r##"
167 An invalid meta-item was used inside an attribute.
168
169 Erroneous code example:
170
171 ```compile_fail,E0551
172 #[deprecated(note)] // error!
173 fn i_am_deprecated() {}
174 ```
175
176 Meta items are the key-value pairs inside of an attribute. To fix this issue,
177 you need to give a value to the `note` key. Example:
178
179 ```
180 #[deprecated(note = "because")] // ok!
181 fn i_am_deprecated() {}
182 ```
183 "##,
184
185 E0552: r##"
186 A unrecognized representation attribute was used.
187
188 Erroneous code example:
189
190 ```compile_fail,E0552
191 #[repr(D)] // error: unrecognized representation hint
192 struct MyStruct {
193     my_field: usize
194 }
195 ```
196
197 You can use a `repr` attribute to tell the compiler how you want a struct or
198 enum to be laid out in memory.
199
200 Make sure you're using one of the supported options:
201
202 ```
203 #[repr(C)] // ok!
204 struct MyStruct {
205     my_field: usize
206 }
207 ```
208
209 For more information about specifying representations, see the ["Alternative
210 Representations" section] of the Rustonomicon.
211
212 ["Alternative Representations" section]: https://doc.rust-lang.org/nomicon/other-reprs.html
213 "##,
214
215 E0554: r##"
216 Feature attributes are only allowed on the nightly release channel. Stable or
217 beta compilers will not comply.
218
219 Example of erroneous code (on a stable compiler):
220
221 ```ignore (depends on release channel)
222 #![feature(non_ascii_idents)] // error: `#![feature]` may not be used on the
223                               //        stable release channel
224 ```
225
226 If you need the feature, make sure to use a nightly release of the compiler
227 (but be warned that the feature may be removed or altered in the future).
228 "##,
229
230 E0556: r##"
231 The `feature` attribute was badly formed.
232
233 Erroneous code example:
234
235 ```compile_fail,E0556
236 #![feature(foo_bar_baz, foo(bar), foo = "baz", foo)] // error!
237 #![feature] // error!
238 #![feature = "foo"] // error!
239 ```
240
241 The `feature` attribute only accept a "feature flag" and can only be used on
242 nightly. Example:
243
244 ```ignore (only works in nightly)
245 #![feature(flag)]
246 ```
247 "##,
248
249 E0557: r##"
250 A feature attribute named a feature that has been removed.
251
252 Erroneous code example:
253
254 ```compile_fail,E0557
255 #![feature(managed_boxes)] // error: feature has been removed
256 ```
257
258 Delete the offending feature attribute.
259 "##,
260
261 E0565: r##"
262 A literal was used in a built-in attribute that doesn't support literals.
263
264 Erroneous code example:
265
266 ```ignore (compile_fail not working here; see Issue #43707)
267 #[inline("always")] // error: unsupported literal
268 pub fn something() {}
269 ```
270
271 Literals in attributes are new and largely unsupported in built-in attributes.
272 Work to support literals where appropriate is ongoing. Try using an unquoted
273 name instead:
274
275 ```
276 #[inline(always)]
277 pub fn something() {}
278 ```
279 "##,
280
281 E0583: r##"
282 A file wasn't found for an out-of-line module.
283
284 Erroneous code example:
285
286 ```ignore (compile_fail not working here; see Issue #43707)
287 mod file_that_doesnt_exist; // error: file not found for module
288
289 fn main() {}
290 ```
291
292 Please be sure that a file corresponding to the module exists. If you
293 want to use a module named `file_that_doesnt_exist`, you need to have a file
294 named `file_that_doesnt_exist.rs` or `file_that_doesnt_exist/mod.rs` in the
295 same directory.
296 "##,
297
298 E0584: r##"
299 A doc comment that is not attached to anything has been encountered.
300
301 Erroneous code example:
302
303 ```compile_fail,E0584
304 trait Island {
305     fn lost();
306
307     /// I'm lost!
308 }
309 ```
310
311 A little reminder: a doc comment has to be placed before the item it's supposed
312 to document. So if you want to document the `Island` trait, you need to put a
313 doc comment before it, not inside it. Same goes for the `lost` method: the doc
314 comment needs to be before it:
315
316 ```
317 /// I'm THE island!
318 trait Island {
319     /// I'm lost!
320     fn lost();
321 }
322 ```
323 "##,
324
325 E0585: r##"
326 A documentation comment that doesn't document anything was found.
327
328 Erroneous code example:
329
330 ```compile_fail,E0585
331 fn main() {
332     // The following doc comment will fail:
333     /// This is a useless doc comment!
334 }
335 ```
336
337 Documentation comments need to be followed by items, including functions,
338 types, modules, etc. Examples:
339
340 ```
341 /// I'm documenting the following struct:
342 struct Foo;
343
344 /// I'm documenting the following function:
345 fn foo() {}
346 ```
347 "##,
348
349 E0586: r##"
350 An inclusive range was used with no end.
351
352 Erroneous code example:
353
354 ```compile_fail,E0586
355 fn main() {
356     let tmp = vec![0, 1, 2, 3, 4, 4, 3, 3, 2, 1];
357     let x = &tmp[1..=]; // error: inclusive range was used with no end
358 }
359 ```
360
361 An inclusive range needs an end in order to *include* it. If you just need a
362 start and no end, use a non-inclusive range (with `..`):
363
364 ```
365 fn main() {
366     let tmp = vec![0, 1, 2, 3, 4, 4, 3, 3, 2, 1];
367     let x = &tmp[1..]; // ok!
368 }
369 ```
370
371 Or put an end to your inclusive range:
372
373 ```
374 fn main() {
375     let tmp = vec![0, 1, 2, 3, 4, 4, 3, 3, 2, 1];
376     let x = &tmp[1..=3]; // ok!
377 }
378 ```
379 "##,
380
381 E0589: r##"
382 The value of `N` that was specified for `repr(align(N))` was not a power
383 of two, or was greater than 2^29.
384
385 ```compile_fail,E0589
386 #[repr(align(15))] // error: invalid `repr(align)` attribute: not a power of two
387 enum Foo {
388     Bar(u64),
389 }
390 ```
391 "##,
392
393 E0658: r##"
394 An unstable feature was used.
395
396 Erroneous code example:
397
398 ```compile_fail,E658
399 #[repr(u128)] // error: use of unstable library feature 'repr128'
400 enum Foo {
401     Bar(u64),
402 }
403 ```
404
405 If you're using a stable or a beta version of rustc, you won't be able to use
406 any unstable features. In order to do so, please switch to a nightly version of
407 rustc (by using rustup).
408
409 If you're using a nightly version of rustc, just add the corresponding feature
410 to be able to use it:
411
412 ```
413 #![feature(repr128)]
414
415 #[repr(u128)] // ok!
416 enum Foo {
417     Bar(u64),
418 }
419 ```
420 "##,
421
422 E0633: r##"
423 The `unwind` attribute was malformed.
424
425 Erroneous code example:
426
427 ```ignore (compile_fail not working here; see Issue #43707)
428 #[unwind()] // error: expected one argument
429 pub extern fn something() {}
430
431 fn main() {}
432 ```
433
434 The `#[unwind]` attribute should be used as follows:
435
436 - `#[unwind(aborts)]` -- specifies that if a non-Rust ABI function
437   should abort the process if it attempts to unwind. This is the safer
438   and preferred option.
439
440 - `#[unwind(allowed)]` -- specifies that a non-Rust ABI function
441   should be allowed to unwind. This can easily result in Undefined
442   Behavior (UB), so be careful.
443
444 NB. The default behavior here is "allowed", but this is unspecified
445 and likely to change in the future.
446
447 "##,
448
449 E0704: r##"
450 This error indicates that a incorrect visibility restriction was specified.
451
452 Example of erroneous code:
453
454 ```compile_fail,E0704
455 mod foo {
456     pub(foo) struct Bar {
457         x: i32
458     }
459 }
460 ```
461
462 To make struct `Bar` only visible in module `foo` the `in` keyword should be
463 used:
464 ```
465 mod foo {
466     pub(in crate::foo) struct Bar {
467         x: i32
468     }
469 }
470 # fn main() {}
471 ```
472
473 For more information see the Rust Reference on [Visibility].
474
475 [Visibility]: https://doc.rust-lang.org/reference/visibility-and-privacy.html
476 "##,
477
478 E0705: r##"
479 A `#![feature]` attribute was declared for a feature that is stable in
480 the current edition, but not in all editions.
481
482 Erroneous code example:
483
484 ```ignore (limited to a warning during 2018 edition development)
485 #![feature(rust_2018_preview)]
486 #![feature(test_2018_feature)] // error: the feature
487                                // `test_2018_feature` is
488                                // included in the Rust 2018 edition
489 ```
490
491 "##,
492
493 E0725: r##"
494 A feature attribute named a feature that was disallowed in the compiler
495 command line flags.
496
497 Erroneous code example:
498
499 ```ignore (can't specify compiler flags from doctests)
500 #![feature(never_type)] // error: the feature `never_type` is not in
501                         // the list of allowed features
502 ```
503
504 Delete the offending feature attribute, or add it to the list of allowed
505 features in the `-Z allow_features` flag.
506 "##,
507
508 ;
509
510     E0539, // incorrect meta item
511     E0540, // multiple rustc_deprecated attributes
512     E0542, // missing 'since'
513     E0543, // missing 'reason'
514     E0544, // multiple stability levels
515     E0545, // incorrect 'issue'
516     E0546, // missing 'feature'
517     E0547, // missing 'issue'
518 //  E0548, // replaced with a generic attribute input check
519     // rustc_deprecated attribute must be paired with either stable or unstable
520     // attribute
521     E0549,
522     E0553, // multiple rustc_const_unstable attributes
523 //  E0555, // replaced with a generic attribute input check
524     E0629, // missing 'feature' (rustc_const_unstable)
525     // rustc_const_unstable attribute must be paired with stable/unstable
526     // attribute
527     E0630,
528     E0693, // incorrect `repr(align)` attribute format
529 //  E0694, // an unknown tool name found in scoped attributes
530     E0703, // invalid ABI
531     E0717, // rustc_promotable without stability attribute
532 }