]> git.lizzy.rs Git - rust.git/blob - src/libsyntax/diagnostic_list.rs
Auto merge of #48818 - michaelwoerister:issue-47309, r=eddyb
[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 E0552: r##"
97 A unrecognized representation attribute was used.
98
99 Erroneous code example:
100
101 ```compile_fail,E0552
102 #[repr(D)] // error: unrecognized representation hint
103 struct MyStruct {
104     my_field: usize
105 }
106 ```
107
108 You can use a `repr` attribute to tell the compiler how you want a struct or
109 enum to be laid out in memory.
110
111 Make sure you're using one of the supported options:
112
113 ```
114 #[repr(C)] // ok!
115 struct MyStruct {
116     my_field: usize
117 }
118 ```
119
120 For more information about specifying representations, see the ["Alternative
121 Representations" section] of the Rustonomicon.
122
123 ["Alternative Representations" section]: https://doc.rust-lang.org/nomicon/other-reprs.html
124 "##,
125
126 E0554: r##"
127 Feature attributes are only allowed on the nightly release channel. Stable or
128 beta compilers will not comply.
129
130 Example of erroneous code (on a stable compiler):
131
132 ```ignore (depends on release channel)
133 #![feature(non_ascii_idents)] // error: #![feature] may not be used on the
134                               //        stable release channel
135 ```
136
137 If you need the feature, make sure to use a nightly release of the compiler
138 (but be warned that the feature may be removed or altered in the future).
139 "##,
140
141 E0557: r##"
142 A feature attribute named a feature that has been removed.
143
144 Erroneous code example:
145
146 ```compile_fail,E0557
147 #![feature(managed_boxes)] // error: feature has been removed
148 ```
149
150 Delete the offending feature attribute.
151 "##,
152
153 E0565: r##"
154 A literal was used in an attribute that doesn't support literals.
155
156 Erroneous code example:
157
158 ```ignore (compile_fail not working here; see Issue #43707)
159 #![feature(attr_literals)]
160
161 #[inline("always")] // error: unsupported literal
162 pub fn something() {}
163 ```
164
165 Literals in attributes are new and largely unsupported. Work to support literals
166 where appropriate is ongoing. Try using an unquoted name instead:
167
168 ```
169 #[inline(always)]
170 pub fn something() {}
171 ```
172 "##,
173
174 E0583: r##"
175 A file wasn't found for an out-of-line module.
176
177 Erroneous code example:
178
179 ```ignore (compile_fail not working here; see Issue #43707)
180 mod file_that_doesnt_exist; // error: file not found for module
181
182 fn main() {}
183 ```
184
185 Please be sure that a file corresponding to the module exists. If you
186 want to use a module named `file_that_doesnt_exist`, you need to have a file
187 named `file_that_doesnt_exist.rs` or `file_that_doesnt_exist/mod.rs` in the
188 same directory.
189 "##,
190
191 E0585: r##"
192 A documentation comment that doesn't document anything was found.
193
194 Erroneous code example:
195
196 ```compile_fail,E0585
197 fn main() {
198     // The following doc comment will fail:
199     /// This is a useless doc comment!
200 }
201 ```
202
203 Documentation comments need to be followed by items, including functions,
204 types, modules, etc. Examples:
205
206 ```
207 /// I'm documenting the following struct:
208 struct Foo;
209
210 /// I'm documenting the following function:
211 fn foo() {}
212 ```
213 "##,
214
215 E0586: r##"
216 An inclusive range was used with no end.
217
218 Erroneous code example:
219
220 ```compile_fail,E0586
221 fn main() {
222     let tmp = vec![0, 1, 2, 3, 4, 4, 3, 3, 2, 1];
223     let x = &tmp[1..=]; // error: inclusive range was used with no end
224 }
225 ```
226
227 An inclusive range needs an end in order to *include* it. If you just need a
228 start and no end, use a non-inclusive range (with `..`):
229
230 ```
231 fn main() {
232     let tmp = vec![0, 1, 2, 3, 4, 4, 3, 3, 2, 1];
233     let x = &tmp[1..]; // ok!
234 }
235 ```
236
237 Or put an end to your inclusive range:
238
239 ```
240 fn main() {
241     let tmp = vec![0, 1, 2, 3, 4, 4, 3, 3, 2, 1];
242     let x = &tmp[1..=3]; // ok!
243 }
244 ```
245 "##,
246
247 E0658: r##"
248 An unstable feature was used.
249
250 Erroneous code example:
251
252 ```compile_fail,E658
253 let x = ::std::u128::MAX; // error: use of unstable library feature 'i128'
254 ```
255
256 If you're using a stable or a beta version of rustc, you won't be able to use
257 any unstable features. In order to do so, please switch to a nightly version of
258 rustc (by using rustup).
259
260 If you're using a nightly version of rustc, just add the corresponding feature
261 to be able to use it:
262
263 ```
264 #![feature(i128)]
265
266 fn main() {
267     let x = ::std::u128::MAX; // ok!
268 }
269 ```
270 "##,
271
272 E0633: r##"
273 The `unwind` attribute was malformed.
274
275 Erroneous code example:
276
277 ```ignore (compile_fail not working here; see Issue #43707)
278 #[unwind()] // error: expected one argument
279 pub extern fn something() {}
280
281 fn main() {}
282 ```
283
284 The `#[unwind]` attribute should be used as follows:
285
286 - `#[unwind(aborts)]` -- specifies that if a non-Rust ABI function
287   should abort the process if it attempts to unwind. This is the safer
288   and preferred option.
289
290 - `#[unwind(allowed)]` -- specifies that a non-Rust ABI function
291   should be allowed to unwind. This can easily result in Undefined
292   Behavior (UB), so be careful.
293
294 NB. The default behavior here is "allowed", but this is unspecified
295 and likely to change in the future.
296
297 "##,
298
299 }
300
301 register_diagnostics! {
302     E0538, // multiple [same] items
303     E0539, // incorrect meta item
304     E0540, // multiple rustc_deprecated attributes
305     E0541, // unknown meta item
306     E0542, // missing 'since'
307     E0543, // missing 'reason'
308     E0544, // multiple stability levels
309     E0545, // incorrect 'issue'
310     E0546, // missing 'feature'
311     E0547, // missing 'issue'
312     E0548, // incorrect stability attribute type
313     E0549, // rustc_deprecated attribute must be paired with either stable or unstable attribute
314     E0550, // multiple deprecated attributes
315     E0551, // incorrect meta item
316     E0553, // multiple rustc_const_unstable attributes
317     E0555, // malformed feature attribute, expected #![feature(...)]
318     E0556, // malformed feature, expected just one word
319     E0584, // file for module `..` found at both .. and ..
320     E0589, // invalid `repr(align)` attribute
321     E0629, // missing 'feature' (rustc_const_unstable)
322     E0630, // rustc_const_unstable attribute must be paired with stable/unstable attribute
323 }