]> git.lizzy.rs Git - rust.git/blob - src/libsyntax/error_codes.rs
Add hooks for Miri panic unwinding
[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 E0536: r##"
8 The `not` cfg-predicate was malformed.
9
10 Erroneous code example:
11
12 ```compile_fail,E0536
13 #[cfg(not())] // error: expected 1 cfg-pattern
14 pub fn something() {}
15
16 pub fn main() {}
17 ```
18
19 The `not` predicate expects one cfg-pattern. Example:
20
21 ```
22 #[cfg(not(target_os = "linux"))] // ok!
23 pub fn something() {}
24
25 pub fn main() {}
26 ```
27
28 For more information about the cfg attribute, read:
29 https://doc.rust-lang.org/reference.html#conditional-compilation
30 "##,
31
32 E0537: r##"
33 An unknown predicate was used inside the `cfg` attribute.
34
35 Erroneous code example:
36
37 ```compile_fail,E0537
38 #[cfg(unknown())] // error: invalid predicate `unknown`
39 pub fn something() {}
40
41 pub fn main() {}
42 ```
43
44 The `cfg` attribute supports only three kinds of predicates:
45
46  * any
47  * all
48  * not
49
50 Example:
51
52 ```
53 #[cfg(not(target_os = "linux"))] // ok!
54 pub fn something() {}
55
56 pub fn main() {}
57 ```
58
59 For more information about the cfg attribute, read:
60 https://doc.rust-lang.org/reference.html#conditional-compilation
61 "##,
62
63 E0538: r##"
64 Attribute contains same meta item more than once.
65
66 Erroneous code example:
67
68 ```compile_fail,E0538
69 #[deprecated(
70     since="1.0.0",
71     note="First deprecation note.",
72     note="Second deprecation note." // error: multiple same meta item
73 )]
74 fn deprecated_function() {}
75 ```
76
77 Meta items are the key-value pairs inside of an attribute. Each key may only be
78 used once in each attribute.
79
80 To fix the problem, remove all but one of the meta items with the same key.
81
82 Example:
83
84 ```
85 #[deprecated(
86     since="1.0.0",
87     note="First deprecation note."
88 )]
89 fn deprecated_function() {}
90 ```
91 "##,
92
93 E0541: r##"
94 An unknown meta item was used.
95
96 Erroneous code example:
97
98 ```compile_fail,E0541
99 #[deprecated(
100     since="1.0.0",
101     // error: unknown meta item
102     reason="Example invalid meta item. Should be 'note'")
103 ]
104 fn deprecated_function() {}
105 ```
106
107 Meta items are the key-value pairs inside of an attribute. The keys provided
108 must be one of the valid keys for the specified attribute.
109
110 To fix the problem, either remove the unknown meta item, or rename it if you
111 provided the wrong name.
112
113 In the erroneous code example above, the wrong name was provided, so changing
114 to a correct one it will fix the error. Example:
115
116 ```
117 #[deprecated(
118     since="1.0.0",
119     note="This is a valid meta item for the deprecated attribute."
120 )]
121 fn deprecated_function() {}
122 ```
123 "##,
124
125 E0550: r##"
126 More than one `deprecated` attribute has been put on an item.
127
128 Erroneous code example:
129
130 ```compile_fail,E0550
131 #[deprecated(note = "because why not?")]
132 #[deprecated(note = "right?")] // error!
133 fn the_banished() {}
134 ```
135
136 The `deprecated` attribute can only be present **once** on an item.
137
138 ```
139 #[deprecated(note = "because why not, right?")]
140 fn the_banished() {} // ok!
141 ```
142 "##,
143
144 E0551: r##"
145 An invalid meta-item was used inside an attribute.
146
147 Erroneous code example:
148
149 ```compile_fail,E0551
150 #[deprecated(note)] // error!
151 fn i_am_deprecated() {}
152 ```
153
154 Meta items are the key-value pairs inside of an attribute. To fix this issue,
155 you need to give a value to the `note` key. Example:
156
157 ```
158 #[deprecated(note = "because")] // ok!
159 fn i_am_deprecated() {}
160 ```
161 "##,
162
163 E0552: r##"
164 A unrecognized representation attribute was used.
165
166 Erroneous code example:
167
168 ```compile_fail,E0552
169 #[repr(D)] // error: unrecognized representation hint
170 struct MyStruct {
171     my_field: usize
172 }
173 ```
174
175 You can use a `repr` attribute to tell the compiler how you want a struct or
176 enum to be laid out in memory.
177
178 Make sure you're using one of the supported options:
179
180 ```
181 #[repr(C)] // ok!
182 struct MyStruct {
183     my_field: usize
184 }
185 ```
186
187 For more information about specifying representations, see the ["Alternative
188 Representations" section] of the Rustonomicon.
189
190 ["Alternative Representations" section]: https://doc.rust-lang.org/nomicon/other-reprs.html
191 "##,
192
193 E0554: r##"
194 Feature attributes are only allowed on the nightly release channel. Stable or
195 beta compilers will not comply.
196
197 Example of erroneous code (on a stable compiler):
198
199 ```ignore (depends on release channel)
200 #![feature(non_ascii_idents)] // error: `#![feature]` may not be used on the
201                               //        stable release channel
202 ```
203
204 If you need the feature, make sure to use a nightly release of the compiler
205 (but be warned that the feature may be removed or altered in the future).
206 "##,
207
208 E0556: r##"
209 The `feature` attribute was badly formed.
210
211 Erroneous code example:
212
213 ```compile_fail,E0556
214 #![feature(foo_bar_baz, foo(bar), foo = "baz", foo)] // error!
215 #![feature] // error!
216 #![feature = "foo"] // error!
217 ```
218
219 The `feature` attribute only accept a "feature flag" and can only be used on
220 nightly. Example:
221
222 ```ignore (only works in nightly)
223 #![feature(flag)]
224 ```
225 "##,
226
227 E0557: r##"
228 A feature attribute named a feature that has been removed.
229
230 Erroneous code example:
231
232 ```compile_fail,E0557
233 #![feature(managed_boxes)] // error: feature has been removed
234 ```
235
236 Delete the offending feature attribute.
237 "##,
238
239 E0565: r##"
240 A literal was used in a built-in attribute that doesn't support literals.
241
242 Erroneous code example:
243
244 ```ignore (compile_fail not working here; see Issue #43707)
245 #[inline("always")] // error: unsupported literal
246 pub fn something() {}
247 ```
248
249 Literals in attributes are new and largely unsupported in built-in attributes.
250 Work to support literals where appropriate is ongoing. Try using an unquoted
251 name instead:
252
253 ```
254 #[inline(always)]
255 pub fn something() {}
256 ```
257 "##,
258
259 E0589: r##"
260 The value of `N` that was specified for `repr(align(N))` was not a power
261 of two, or was greater than 2^29.
262
263 ```compile_fail,E0589
264 #[repr(align(15))] // error: invalid `repr(align)` attribute: not a power of two
265 enum Foo {
266     Bar(u64),
267 }
268 ```
269 "##,
270
271 E0658: r##"
272 An unstable feature was used.
273
274 Erroneous code example:
275
276 ```compile_fail,E658
277 #[repr(u128)] // error: use of unstable library feature 'repr128'
278 enum Foo {
279     Bar(u64),
280 }
281 ```
282
283 If you're using a stable or a beta version of rustc, you won't be able to use
284 any unstable features. In order to do so, please switch to a nightly version of
285 rustc (by using rustup).
286
287 If you're using a nightly version of rustc, just add the corresponding feature
288 to be able to use it:
289
290 ```
291 #![feature(repr128)]
292
293 #[repr(u128)] // ok!
294 enum Foo {
295     Bar(u64),
296 }
297 ```
298 "##,
299
300 E0633: r##"
301 The `unwind` attribute was malformed.
302
303 Erroneous code example:
304
305 ```ignore (compile_fail not working here; see Issue #43707)
306 #[unwind()] // error: expected one argument
307 pub extern fn something() {}
308
309 fn main() {}
310 ```
311
312 The `#[unwind]` attribute should be used as follows:
313
314 - `#[unwind(aborts)]` -- specifies that if a non-Rust ABI function
315   should abort the process if it attempts to unwind. This is the safer
316   and preferred option.
317
318 - `#[unwind(allowed)]` -- specifies that a non-Rust ABI function
319   should be allowed to unwind. This can easily result in Undefined
320   Behavior (UB), so be careful.
321
322 NB. The default behavior here is "allowed", but this is unspecified
323 and likely to change in the future.
324
325 "##,
326
327 E0705: r##"
328 A `#![feature]` attribute was declared for a feature that is stable in
329 the current edition, but not in all editions.
330
331 Erroneous code example:
332
333 ```ignore (limited to a warning during 2018 edition development)
334 #![feature(rust_2018_preview)]
335 #![feature(test_2018_feature)] // error: the feature
336                                // `test_2018_feature` is
337                                // included in the Rust 2018 edition
338 ```
339 "##,
340
341 E0725: r##"
342 A feature attribute named a feature that was disallowed in the compiler
343 command line flags.
344
345 Erroneous code example:
346
347 ```ignore (can't specify compiler flags from doctests)
348 #![feature(never_type)] // error: the feature `never_type` is not in
349                         // the list of allowed features
350 ```
351
352 Delete the offending feature attribute, or add it to the list of allowed
353 features in the `-Z allow_features` flag.
354 "##,
355
356 ;
357
358     E0539, // incorrect meta item
359     E0540, // multiple rustc_deprecated attributes
360     E0542, // missing 'since'
361     E0543, // missing 'reason'
362     E0544, // multiple stability levels
363     E0545, // incorrect 'issue'
364     E0546, // missing 'feature'
365     E0547, // missing 'issue'
366 //  E0548, // replaced with a generic attribute input check
367     // rustc_deprecated attribute must be paired with either stable or unstable
368     // attribute
369     E0549,
370     E0553, // multiple rustc_const_unstable attributes
371 //  E0555, // replaced with a generic attribute input check
372     E0629, // missing 'feature' (rustc_const_unstable)
373     // rustc_const_unstable attribute must be paired with stable/unstable
374     // attribute
375     E0630,
376     E0693, // incorrect `repr(align)` attribute format
377 //  E0694, // an unknown tool name found in scoped attributes
378     E0717, // rustc_promotable without stability attribute
379 }