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! {
8 In types, the `+` type operator has low precedence, so it is often necessary
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)
24 More details can be found in [RFC 438].
26 [RFC 438]: https://github.com/rust-lang/rfcs/pull/438
30 The `not` cfg-predicate was malformed.
32 Erroneous code example:
35 #[cfg(not())] // error: expected 1 cfg-pattern
41 The `not` predicate expects one cfg-pattern. Example:
44 #[cfg(not(target_os = "linux"))] // ok!
50 For more information about the cfg attribute, read:
51 https://doc.rust-lang.org/reference.html#conditional-compilation
55 An unknown predicate was used inside the `cfg` attribute.
57 Erroneous code example:
60 #[cfg(unknown())] // error: invalid predicate `unknown`
66 The `cfg` attribute supports only three kinds of predicates:
75 #[cfg(not(target_os = "linux"))] // ok!
81 For more information about the cfg attribute, read:
82 https://doc.rust-lang.org/reference.html#conditional-compilation
86 Attribute contains same meta item more than once.
88 Erroneous code example:
93 note="First deprecation note.",
94 note="Second deprecation note." // error: multiple same meta item
96 fn deprecated_function() {}
99 Meta items are the key-value pairs inside of an attribute. Each key may only be
100 used once in each attribute.
102 To fix the problem, remove all but one of the meta items with the same key.
109 note="First deprecation note."
111 fn deprecated_function() {}
116 An unknown meta item was used.
118 Erroneous code example:
120 ```compile_fail,E0541
123 // error: unknown meta item
124 reason="Example invalid meta item. Should be 'note'")
126 fn deprecated_function() {}
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.
132 To fix the problem, either remove the unknown meta item, or rename it if you
133 provided the wrong name.
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:
141 note="This is a valid meta item for the deprecated attribute."
143 fn deprecated_function() {}
148 More than one `deprecated` attribute has been put on an item.
150 Erroneous code example:
152 ```compile_fail,E0550
153 #[deprecated(note = "because why not?")]
154 #[deprecated(note = "right?")] // error!
158 The `deprecated` attribute can only be present **once** on an item.
161 #[deprecated(note = "because why not, right?")]
162 fn the_banished() {} // ok!
167 An invalid meta-item was used inside an attribute.
169 Erroneous code example:
171 ```compile_fail,E0551
172 #[deprecated(note)] // error!
173 fn i_am_deprecated() {}
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:
180 #[deprecated(note = "because")] // ok!
181 fn i_am_deprecated() {}
186 A unrecognized representation attribute was used.
188 Erroneous code example:
190 ```compile_fail,E0552
191 #[repr(D)] // error: unrecognized representation hint
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.
200 Make sure you're using one of the supported options:
209 For more information about specifying representations, see the ["Alternative
210 Representations" section] of the Rustonomicon.
212 ["Alternative Representations" section]: https://doc.rust-lang.org/nomicon/other-reprs.html
216 Feature attributes are only allowed on the nightly release channel. Stable or
217 beta compilers will not comply.
219 Example of erroneous code (on a stable compiler):
221 ```ignore (depends on release channel)
222 #![feature(non_ascii_idents)] // error: `#![feature]` may not be used on the
223 // stable release channel
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).
231 The `feature` attribute was badly formed.
233 Erroneous code example:
235 ```compile_fail,E0556
236 #![feature(foo_bar_baz, foo(bar), foo = "baz", foo)] // error!
237 #![feature] // error!
238 #![feature = "foo"] // error!
241 The `feature` attribute only accept a "feature flag" and can only be used on
244 ```ignore (only works in nightly)
250 A feature attribute named a feature that has been removed.
252 Erroneous code example:
254 ```compile_fail,E0557
255 #![feature(managed_boxes)] // error: feature has been removed
258 Delete the offending feature attribute.
262 A literal was used in a built-in attribute that doesn't support literals.
264 Erroneous code example:
266 ```ignore (compile_fail not working here; see Issue #43707)
267 #[inline("always")] // error: unsupported literal
268 pub fn something() {}
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
277 pub fn something() {}
282 A file wasn't found for an out-of-line module.
284 Erroneous code example:
286 ```ignore (compile_fail not working here; see Issue #43707)
287 mod file_that_doesnt_exist; // error: file not found for module
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
299 A doc comment that is not attached to anything has been encountered.
301 Erroneous code example:
303 ```compile_fail,E0584
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:
326 A documentation comment that doesn't document anything was found.
328 Erroneous code example:
330 ```compile_fail,E0585
332 // The following doc comment will fail:
333 /// This is a useless doc comment!
337 Documentation comments need to be followed by items, including functions,
338 types, modules, etc. Examples:
341 /// I'm documenting the following struct:
344 /// I'm documenting the following function:
350 An inclusive range was used with no end.
352 Erroneous code example:
354 ```compile_fail,E0586
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
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 `..`):
366 let tmp = vec![0, 1, 2, 3, 4, 4, 3, 3, 2, 1];
367 let x = &tmp[1..]; // ok!
371 Or put an end to your inclusive range:
375 let tmp = vec![0, 1, 2, 3, 4, 4, 3, 3, 2, 1];
376 let x = &tmp[1..=3]; // ok!
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.
385 ```compile_fail,E0589
386 #[repr(align(15))] // error: invalid `repr(align)` attribute: not a power of two
394 An unstable feature was used.
396 Erroneous code example:
399 #[repr(u128)] // error: use of unstable library feature 'repr128'
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).
409 If you're using a nightly version of rustc, just add the corresponding feature
410 to be able to use it:
423 The `unwind` attribute was malformed.
425 Erroneous code example:
427 ```ignore (compile_fail not working here; see Issue #43707)
428 #[unwind()] // error: expected one argument
429 pub extern fn something() {}
434 The `#[unwind]` attribute should be used as follows:
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.
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.
444 NB. The default behavior here is "allowed", but this is unspecified
445 and likely to change in the future.
450 This error indicates that a incorrect visibility restriction was specified.
452 Example of erroneous code:
454 ```compile_fail,E0704
456 pub(foo) struct Bar {
462 To make struct `Bar` only visible in module `foo` the `in` keyword should be
466 pub(in crate::foo) struct Bar {
473 For more information see the Rust Reference on [Visibility].
475 [Visibility]: https://doc.rust-lang.org/reference/visibility-and-privacy.html
479 A `#![feature]` attribute was declared for a feature that is stable in
480 the current edition, but not in all editions.
482 Erroneous code example:
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
494 A feature attribute named a feature that was disallowed in the compiler
497 Erroneous code example:
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
504 Delete the offending feature attribute, or add it to the list of allowed
505 features in the `-Z allow_features` flag.
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
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
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