]> git.proxmox.com Git - rustc.git/blob - src/librustc_passes/diagnostics.rs
New upstream version 1.12.0+dfsg1
[rustc.git] / src / librustc_passes / diagnostics.rs
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! {
14 /*
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 "##,
33 */
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
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
85 E0161: r##"
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
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
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 ```
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
124 ```compile_fail,E0265
125 const X: u32 = X;
126 ```
127
128 ```compile_fail,E0265
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
138 ```compile_fail,E0267
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
162 ```compile_fail,E0268
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
179 E0449: r##"
180 A visibility qualifier was used when it was unnecessary. Erroneous code
181 examples:
182
183 ```compile_fail
184 struct Bar;
185
186 trait Foo {
187 fn foo();
188 }
189
190 pub impl Bar {} // error: unnecessary visibility qualifier
191
192 pub impl Foo for Bar { // error: unnecessary visibility qualifier
193 pub fn foo() {} // error: unnecessary visibility qualifier
194 }
195 ```
196
197 To fix this error, please remove the visibility qualifier when it is not
198 required. Example:
199
200 ```ignore
201 struct Bar;
202
203 trait Foo {
204 fn foo();
205 }
206
207 // Directly implemented methods share the visibility of the type itself,
208 // so `pub` is unnecessary here
209 impl Bar {}
210
211 // Trait methods share the visibility of the trait, so `pub` is
212 // unnecessary in either case
213 pub impl Foo for Bar {
214 pub fn foo() {}
215 }
216 ```
217 "##,
218
219 }
220
221 register_diagnostics! {
222 E0472, // asm! is unsupported on this target
223 E0561, // patterns aren't allowed in function pointer types
224 }