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