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