]> git.proxmox.com Git - rustc.git/blob - src/librustc_passes/diagnostics.rs
Imported Upstream version 1.11.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 E0161: r##"
53 A value was moved. However, its size was not known at compile time, and only
54 values of a known size can be moved.
55
56 Erroneous code example:
57
58 ```compile_fail
59 #![feature(box_syntax)]
60
61 fn main() {
62 let array: &[isize] = &[1, 2, 3];
63 let _x: Box<[isize]> = box *array;
64 // error: cannot move a value of type [isize]: the size of [isize] cannot
65 // be statically determined
66 }
67 ```
68
69 In Rust, you can only move a value when its size is known at compile time.
70
71 To work around this restriction, consider "hiding" the value behind a reference:
72 either `&x` or `&mut x`. Since a reference has a fixed size, this lets you move
73 it around as usual. Example:
74
75 ```
76 #![feature(box_syntax)]
77
78 fn main() {
79 let array: &[isize] = &[1, 2, 3];
80 let _x: Box<&[isize]> = box array; // ok!
81 }
82 ```
83 "##,
84
85 E0265: r##"
86 This error indicates that a static or constant references itself.
87 All statics and constants need to resolve to a value in an acyclic manner.
88
89 For example, neither of the following can be sensibly compiled:
90
91 ```compile_fail
92 const X: u32 = X;
93 ```
94
95 ```compile_fail
96 const X: u32 = Y;
97 const Y: u32 = X;
98 ```
99 "##,
100
101 E0267: r##"
102 This error indicates the use of a loop keyword (`break` or `continue`) inside a
103 closure but outside of any loop. Erroneous code example:
104
105 ```compile_fail
106 let w = || { break; }; // error: `break` inside of a closure
107 ```
108
109 `break` and `continue` keywords can be used as normal inside closures as long as
110 they are also contained within a loop. To halt the execution of a closure you
111 should instead use a return statement. Example:
112
113 ```
114 let w = || {
115 for _ in 0..10 {
116 break;
117 }
118 };
119
120 w();
121 ```
122 "##,
123
124 E0268: r##"
125 This error indicates the use of a loop keyword (`break` or `continue`) outside
126 of a loop. Without a loop to break out of or continue in, no sensible action can
127 be taken. Erroneous code example:
128
129 ```compile_fail
130 fn some_func() {
131 break; // error: `break` outside of loop
132 }
133 ```
134
135 Please verify that you are using `break` and `continue` only in loops. Example:
136
137 ```
138 fn some_func() {
139 for _ in 0..10 {
140 break; // ok!
141 }
142 }
143 ```
144 "##,
145
146 E0449: r##"
147 A visibility qualifier was used when it was unnecessary. Erroneous code
148 examples:
149
150 ```compile_fail
151 struct Bar;
152
153 trait Foo {
154 fn foo();
155 }
156
157 pub impl Bar {} // error: unnecessary visibility qualifier
158
159 pub impl Foo for Bar { // error: unnecessary visibility qualifier
160 pub fn foo() {} // error: unnecessary visibility qualifier
161 }
162 ```
163
164 To fix this error, please remove the visibility qualifier when it is not
165 required. Example:
166
167 ```ignore
168 struct Bar;
169
170 trait Foo {
171 fn foo();
172 }
173
174 // Directly implemented methods share the visibility of the type itself,
175 // so `pub` is unnecessary here
176 impl Bar {}
177
178 // Trait methods share the visibility of the trait, so `pub` is
179 // unnecessary in either case
180 pub impl Foo for Bar {
181 pub fn foo() {}
182 }
183 ```
184 "##,
185
186 }
187
188 register_diagnostics! {
189 E0472, // asm! is unsupported on this target
190 }