]>
Commit | Line | Data |
---|---|---|
9cc50fc6 SL |
1 | // Copyright 2015 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 | register_long_diagnostics! { | |
5bcae85e | 14 | /* |
7453a54e SL |
15 | E0014: r##" |
16 | Constants can only be initialized by a constant value or, in a future | |
17 | version of Rust, a call to a const function. This error indicates the use | |
18 | of a path (like a::b, or x) denoting something other than one of these | |
19 | allowed items. Erroneous code xample: | |
20 | ||
21 | ```compile_fail | |
22 | const FOO: i32 = { let x = 0; x }; // 'x' isn't a constant nor a function! | |
23 | ``` | |
24 | ||
25 | To avoid it, you have to replace the non-constant value: | |
26 | ||
27 | ``` | |
28 | const FOO: i32 = { const X : i32 = 0; X }; | |
29 | // or even: | |
30 | const FOO2: i32 = { 0 }; // but brackets are useless here | |
31 | ``` | |
32 | "##, | |
5bcae85e | 33 | */ |
7453a54e SL |
34 | E0030: r##" |
35 | When matching against a range, the compiler verifies that the range is | |
36 | non-empty. Range patterns include both end-points, so this is equivalent to | |
37 | requiring the start of the range to be less than or equal to the end of the | |
38 | range. | |
39 | ||
40 | For example: | |
41 | ||
42 | ```compile_fail | |
43 | match 5u32 { | |
44 | // This range is ok, albeit pointless. | |
45 | 1 ... 1 => {} | |
46 | // This range is empty, and the compiler can tell. | |
47 | 1000 ... 5 => {} | |
48 | } | |
49 | ``` | |
50 | "##, | |
51 | ||
5bcae85e SL |
52 | E0130: r##" |
53 | You declared a pattern as an argument in a foreign function declaration. | |
54 | Erroneous code example: | |
55 | ||
56 | ```compile_fail | |
57 | extern { | |
58 | fn foo((a, b): (u32, u32)); // error: patterns aren't allowed in foreign | |
59 | // function declarations | |
60 | } | |
61 | ``` | |
62 | ||
63 | Please replace the pattern argument with a regular one. Example: | |
64 | ||
65 | ``` | |
66 | struct SomeStruct { | |
67 | a: u32, | |
68 | b: u32, | |
69 | } | |
70 | ||
71 | extern { | |
72 | fn foo(s: SomeStruct); // ok! | |
73 | } | |
74 | ``` | |
75 | ||
76 | Or: | |
77 | ||
78 | ``` | |
79 | extern { | |
80 | fn foo(a: (u32, u32)); // ok! | |
81 | } | |
82 | ``` | |
83 | "##, | |
84 | ||
7453a54e | 85 | E0161: r##" |
3157f602 XL |
86 | A value was moved. However, its size was not known at compile time, and only |
87 | values of a known size can be moved. | |
88 | ||
89 | Erroneous code example: | |
90 | ||
91 | ```compile_fail | |
92 | #![feature(box_syntax)] | |
93 | ||
94 | fn main() { | |
95 | let array: &[isize] = &[1, 2, 3]; | |
96 | let _x: Box<[isize]> = box *array; | |
97 | // error: cannot move a value of type [isize]: the size of [isize] cannot | |
98 | // be statically determined | |
99 | } | |
100 | ``` | |
101 | ||
7453a54e SL |
102 | In Rust, you can only move a value when its size is known at compile time. |
103 | ||
104 | To work around this restriction, consider "hiding" the value behind a reference: | |
105 | either `&x` or `&mut x`. Since a reference has a fixed size, this lets you move | |
3157f602 XL |
106 | it around as usual. Example: |
107 | ||
108 | ``` | |
109 | #![feature(box_syntax)] | |
110 | ||
111 | fn main() { | |
112 | let array: &[isize] = &[1, 2, 3]; | |
113 | let _x: Box<&[isize]> = box array; // ok! | |
114 | } | |
115 | ``` | |
7453a54e SL |
116 | "##, |
117 | ||
118 | E0265: r##" | |
119 | This error indicates that a static or constant references itself. | |
120 | All statics and constants need to resolve to a value in an acyclic manner. | |
121 | ||
122 | For example, neither of the following can be sensibly compiled: | |
123 | ||
5bcae85e | 124 | ```compile_fail,E0265 |
7453a54e SL |
125 | const X: u32 = X; |
126 | ``` | |
127 | ||
5bcae85e | 128 | ```compile_fail,E0265 |
7453a54e SL |
129 | const X: u32 = Y; |
130 | const Y: u32 = X; | |
131 | ``` | |
132 | "##, | |
133 | ||
134 | E0267: r##" | |
135 | This error indicates the use of a loop keyword (`break` or `continue`) inside a | |
136 | closure but outside of any loop. Erroneous code example: | |
137 | ||
5bcae85e | 138 | ```compile_fail,E0267 |
7453a54e SL |
139 | let w = || { break; }; // error: `break` inside of a closure |
140 | ``` | |
141 | ||
142 | `break` and `continue` keywords can be used as normal inside closures as long as | |
143 | they are also contained within a loop. To halt the execution of a closure you | |
144 | should instead use a return statement. Example: | |
145 | ||
146 | ``` | |
147 | let w = || { | |
148 | for _ in 0..10 { | |
149 | break; | |
150 | } | |
151 | }; | |
152 | ||
153 | w(); | |
154 | ``` | |
155 | "##, | |
156 | ||
157 | E0268: r##" | |
158 | This error indicates the use of a loop keyword (`break` or `continue`) outside | |
159 | of a loop. Without a loop to break out of or continue in, no sensible action can | |
160 | be taken. Erroneous code example: | |
161 | ||
5bcae85e | 162 | ```compile_fail,E0268 |
7453a54e SL |
163 | fn some_func() { |
164 | break; // error: `break` outside of loop | |
165 | } | |
166 | ``` | |
167 | ||
168 | Please verify that you are using `break` and `continue` only in loops. Example: | |
169 | ||
170 | ``` | |
171 | fn some_func() { | |
172 | for _ in 0..10 { | |
173 | break; // ok! | |
174 | } | |
175 | } | |
176 | ``` | |
177 | "##, | |
178 | ||
9e0c209e SL |
179 | E0379: r##" |
180 | Trait methods cannot be declared `const` by design. For more information, see | |
181 | [RFC 911]. | |
182 | ||
183 | [RFC 911]: https://github.com/rust-lang/rfcs/pull/911 | |
184 | "##, | |
185 | ||
3157f602 XL |
186 | E0449: r##" |
187 | A visibility qualifier was used when it was unnecessary. Erroneous code | |
188 | examples: | |
189 | ||
190 | ```compile_fail | |
191 | struct Bar; | |
192 | ||
193 | trait Foo { | |
194 | fn foo(); | |
195 | } | |
196 | ||
197 | pub impl Bar {} // error: unnecessary visibility qualifier | |
198 | ||
199 | pub impl Foo for Bar { // error: unnecessary visibility qualifier | |
200 | pub fn foo() {} // error: unnecessary visibility qualifier | |
201 | } | |
202 | ``` | |
203 | ||
204 | To fix this error, please remove the visibility qualifier when it is not | |
205 | required. Example: | |
206 | ||
207 | ```ignore | |
208 | struct Bar; | |
209 | ||
210 | trait Foo { | |
211 | fn foo(); | |
212 | } | |
213 | ||
214 | // Directly implemented methods share the visibility of the type itself, | |
215 | // so `pub` is unnecessary here | |
216 | impl Bar {} | |
217 | ||
218 | // Trait methods share the visibility of the trait, so `pub` is | |
219 | // unnecessary in either case | |
220 | pub impl Foo for Bar { | |
221 | pub fn foo() {} | |
222 | } | |
223 | ``` | |
224 | "##, | |
225 | ||
9cc50fc6 SL |
226 | } |
227 | ||
228 | register_diagnostics! { | |
229 | E0472, // asm! is unsupported on this target | |
5bcae85e | 230 | E0561, // patterns aren't allowed in function pointer types |
9cc50fc6 | 231 | } |