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 A unrecognized representation attribute was used.
150 Erroneous code example:
152 ```compile_fail,E0552
153 #[repr(D)] // error: unrecognized representation hint
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.
162 Make sure you're using one of the supported options:
171 For more information about specifying representations, see the ["Alternative
172 Representations" section] of the Rustonomicon.
174 ["Alternative Representations" section]: https://doc.rust-lang.org/nomicon/other-reprs.html
178 Feature attributes are only allowed on the nightly release channel. Stable or
179 beta compilers will not comply.
181 Example of erroneous code (on a stable compiler):
183 ```ignore (depends on release channel)
184 #![feature(non_ascii_idents)] // error: `#![feature]` may not be used on the
185 // stable release channel
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).
193 A feature attribute named a feature that has been removed.
195 Erroneous code example:
197 ```compile_fail,E0557
198 #![feature(managed_boxes)] // error: feature has been removed
201 Delete the offending feature attribute.
205 A literal was used in a built-in attribute that doesn't support literals.
207 Erroneous code example:
209 ```ignore (compile_fail not working here; see Issue #43707)
210 #[inline("always")] // error: unsupported literal
211 pub fn something() {}
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
220 pub fn something() {}
225 A file wasn't found for an out-of-line module.
227 Erroneous code example:
229 ```ignore (compile_fail not working here; see Issue #43707)
230 mod file_that_doesnt_exist; // error: file not found for module
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
242 A documentation comment that doesn't document anything was found.
244 Erroneous code example:
246 ```compile_fail,E0585
248 // The following doc comment will fail:
249 /// This is a useless doc comment!
253 Documentation comments need to be followed by items, including functions,
254 types, modules, etc. Examples:
257 /// I'm documenting the following struct:
260 /// I'm documenting the following function:
266 An inclusive range was used with no end.
268 Erroneous code example:
270 ```compile_fail,E0586
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
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 `..`):
282 let tmp = vec![0, 1, 2, 3, 4, 4, 3, 3, 2, 1];
283 let x = &tmp[1..]; // ok!
287 Or put an end to your inclusive range:
291 let tmp = vec![0, 1, 2, 3, 4, 4, 3, 3, 2, 1];
292 let x = &tmp[1..=3]; // ok!
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.
301 ```compile_fail,E0589
302 #[repr(align(15))] // error: invalid `repr(align)` attribute: not a power of two
310 An unstable feature was used.
312 Erroneous code example:
315 #[repr(u128)] // error: use of unstable library feature 'repr128'
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).
325 If you're using a nightly version of rustc, just add the corresponding feature
326 to be able to use it:
339 The `unwind` attribute was malformed.
341 Erroneous code example:
343 ```ignore (compile_fail not working here; see Issue #43707)
344 #[unwind()] // error: expected one argument
345 pub extern fn something() {}
350 The `#[unwind]` attribute should be used as follows:
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.
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.
360 NB. The default behavior here is "allowed", but this is unspecified
361 and likely to change in the future.
366 This error indicates that a incorrect visibility restriction was specified.
368 Example of erroneous code:
370 ```compile_fail,E0704
372 pub(foo) struct Bar {
378 To make struct `Bar` only visible in module `foo` the `in` keyword should be
382 pub(in crate::foo) struct Bar {
389 For more information see the Rust Reference on [Visibility].
391 [Visibility]: https://doc.rust-lang.org/reference/visibility-and-privacy.html
395 A `#![feature]` attribute was declared for a feature that is stable in
396 the current edition, but not in all editions.
398 Erroneous code example:
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
410 A feature attribute named a feature that was disallowed in the compiler
413 Erroneous code example:
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
420 Delete the offending feature attribute, or add it to the list of allowed
421 features in the `-Z allow_features` flag.
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
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
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