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