Skip to content

Commit 6545819

Browse files
Unification and cleanup of librustc_mir error codes
1 parent c6de3eb commit 6545819

File tree

1 file changed

+92
-50
lines changed

1 file changed

+92
-50
lines changed

src/librustc_mir/error_codes.rs

+92-50
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ E0004: r##"
6464
This error indicates that the compiler cannot guarantee a matching pattern for
6565
one or more possible inputs to a match expression. Guaranteed matches are
6666
required in order to assign values to match expressions, or alternatively,
67-
determine the flow of execution. Erroneous code example:
67+
determine the flow of execution.
68+
69+
Erroneous code example:
6870
6971
```compile_fail,E0004
7072
enum Terminator {
@@ -109,7 +111,9 @@ match x {
109111

110112
E0005: r##"
111113
Patterns used to bind names must be irrefutable, that is, they must guarantee
112-
that a name will be extracted in all cases. Erroneous code example:
114+
that a name will be extracted in all cases.
115+
116+
Erroneous code example:
113117
114118
```compile_fail,E0005
115119
let x = Some(1);
@@ -145,6 +149,8 @@ like the following is invalid as it requires the entire `Option<String>` to be
145149
moved into a variable called `op_string` while simultaneously requiring the
146150
inner `String` to be moved into a variable called `s`.
147151
152+
Erroneous code example:
153+
148154
```compile_fail,E0007
149155
let x = Some("s".to_string());
150156
@@ -211,8 +217,9 @@ match x {
211217
E0010: r##"
212218
The value of statics and constants must be known at compile time, and they live
213219
for the entire lifetime of a program. Creating a boxed value allocates memory on
214-
the heap at runtime, and therefore cannot be done at compile time. Erroneous
215-
code example:
220+
the heap at runtime, and therefore cannot be done at compile time.
221+
222+
Erroneous code example:
216223
217224
```compile_fail,E0010
218225
#![feature(box_syntax)]
@@ -223,15 +230,17 @@ const CON : Box<i32> = box 0;
223230

224231
E0013: r##"
225232
Static and const variables can refer to other const variables. But a const
226-
variable cannot refer to a static variable. For example, `Y` cannot refer to
227-
`X` here:
233+
variable cannot refer to a static variable.
234+
235+
Erroneous code example:
228236
229237
```compile_fail,E0013
230238
static X: i32 = 42;
231239
const Y: i32 = X;
232240
```
233241
234-
To fix this, the value can be extracted as a const and then used:
242+
In this example, `Y` cannot refer to `X` here. To fix this, the value can be
243+
extracted as a const and then used:
235244
236245
```
237246
const A: i32 = 42;
@@ -260,6 +269,7 @@ See [RFC 911] for more details on the design of `const fn`s.
260269

261270
E0017: r##"
262271
References in statics and constants may only refer to immutable values.
272+
263273
Erroneous code example:
264274
265275
```compile_fail,E0017
@@ -282,24 +292,17 @@ If you really want global mutable state, try using `static mut` or a global
282292

283293
E0019: r##"
284294
A function call isn't allowed in the const's initialization expression
285-
because the expression's value must be known at compile-time. Erroneous code
286-
example:
295+
because the expression's value must be known at compile-time.
287296
288-
```compile_fail
289-
enum Test {
290-
V1
291-
}
297+
Erroneous code example:
292298
293-
impl Test {
294-
fn test(&self) -> i32 {
295-
12
296-
}
297-
}
299+
```compile_fail,E0019
300+
#![feature(box_syntax)]
298301
299302
fn main() {
300-
const FOO: Test = Test::V1;
303+
struct MyOwned;
301304
302-
const A: i32 = FOO.test(); // You can't call Test::func() here!
305+
static STATIC11: Box<MyOwned> = box MyOwned; // error!
303306
}
304307
```
305308
@@ -328,13 +331,13 @@ fn main() {
328331

329332
E0030: r##"
330333
When matching against a range, the compiler verifies that the range is
331-
non-empty. Range patterns include both end-points, so this is equivalent to
334+
non-empty. Range patterns include both end-points, so this is equivalent to
332335
requiring the start of the range to be less than or equal to the end of the
333336
range.
334337
335-
For example:
338+
Erroneous code example:
336339
337-
```compile_fail
340+
```compile_fail,E0030
338341
match 5u32 {
339342
// This range is ok, albeit pointless.
340343
1 ..= 1 => {}
@@ -379,6 +382,26 @@ See also https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html
379382
"##,
380383

381384
E0158: r##"
385+
An associated const has been referenced in a pattern.
386+
387+
Erroneous code example:
388+
389+
```compile_fail,E0158
390+
enum EFoo { A, B, C, D }
391+
392+
trait Foo {
393+
const X: EFoo;
394+
}
395+
396+
fn test<A: Foo>(arg: EFoo) {
397+
match arg {
398+
A::X => { // error!
399+
println!("A::X");
400+
}
401+
}
402+
}
403+
```
404+
382405
`const` and `static` mean different things. A `const` is a compile-time
383406
constant, an alias for a literal value. This property means you can match it
384407
directly within a pattern.
@@ -405,7 +428,7 @@ values of a known size can be moved.
405428
406429
Erroneous code example:
407430
408-
```compile_fail
431+
```compile_fail,E0161
409432
#![feature(box_syntax)]
410433
411434
fn main() {
@@ -705,7 +728,9 @@ about safety.
705728
"##,
706729

707730
E0381: r##"
708-
It is not allowed to use or capture an uninitialized variable. For example:
731+
It is not allowed to use or capture an uninitialized variable.
732+
733+
Erroneous code example:
709734
710735
```compile_fail,E0381
711736
fn main() {
@@ -727,7 +752,9 @@ fn main() {
727752

728753
E0382: r##"
729754
This error occurs when an attempt is made to use a variable after its contents
730-
have been moved elsewhere. For example:
755+
have been moved elsewhere.
756+
757+
Erroneous code example:
731758
732759
```compile_fail,E0382
733760
struct MyStruct { s: u32 }
@@ -934,7 +961,9 @@ E0387: r##"
934961
#### Note: this error code is no longer emitted by the compiler.
935962
936963
This error occurs when an attempt is made to mutate or mutably reference data
937-
that a closure has captured immutably. Examples of this error are shown below:
964+
that a closure has captured immutably.
965+
966+
Erroneous code example:
938967
939968
```compile_fail
940969
// Accepts a function or a closure that captures its environment immutably.
@@ -999,7 +1028,7 @@ An attempt was made to mutate data using a non-mutable reference. This
9991028
commonly occurs when attempting to assign to a non-mutable reference of a
10001029
mutable reference (`&(&mut T)`).
10011030
1002-
Example of erroneous code:
1031+
Erroneous code example:
10031032
10041033
```compile_fail
10051034
struct FancyNum {
@@ -1059,8 +1088,9 @@ fn main() {
10591088
"##,
10601089

10611090
E0492: r##"
1062-
A borrow of a constant containing interior mutability was attempted. Erroneous
1063-
code example:
1091+
A borrow of a constant containing interior mutability was attempted.
1092+
1093+
Erroneous code example:
10641094
10651095
```compile_fail,E0492
10661096
use std::sync::atomic::AtomicUsize;
@@ -1177,7 +1207,9 @@ static FOO: Foo = Foo { field1: DropType::A }; // We initialize all fields
11771207
"##,
11781208

11791209
E0499: r##"
1180-
A variable was borrowed as mutable more than once. Erroneous code example:
1210+
A variable was borrowed as mutable more than once.
1211+
1212+
Erroneous code example:
11811213
11821214
```compile_fail,E0499
11831215
let mut i = 0;
@@ -1208,7 +1240,9 @@ a;
12081240
"##,
12091241

12101242
E0500: r##"
1211-
A borrowed variable was used by a closure. Example of erroneous code:
1243+
A borrowed variable was used by a closure.
1244+
1245+
Erroneous code example:
12121246
12131247
```compile_fail,E0500
12141248
fn you_know_nothing(jon_snow: &mut i32) {
@@ -1259,7 +1293,7 @@ situation, the closure is borrowing the variable. Take a look at
12591293
http://rustbyexample.com/fn/closures/capture.html for more information about
12601294
capturing.
12611295
1262-
Example of erroneous code:
1296+
Erroneous code example:
12631297
12641298
```compile_fail,E0501
12651299
fn inside_closure(x: &mut i32) {
@@ -1332,7 +1366,7 @@ E0502: r##"
13321366
This error indicates that you are trying to borrow a variable as mutable when it
13331367
has already been borrowed as immutable.
13341368
1335-
Example of erroneous code:
1369+
Erroneous code example:
13361370
13371371
```compile_fail,E0502
13381372
fn bar(x: &mut i32) {}
@@ -1363,7 +1397,7 @@ https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html.
13631397
E0503: r##"
13641398
A value was used after it was mutably borrowed.
13651399
1366-
Example of erroneous code:
1400+
Erroneous code example:
13671401
13681402
```compile_fail,E0503
13691403
fn main() {
@@ -1421,7 +1455,7 @@ E0504: r##"
14211455
This error occurs when an attempt is made to move a borrowed variable into a
14221456
closure.
14231457
1424-
Example of erroneous code:
1458+
Erroneous code example:
14251459
14261460
```compile_fail
14271461
struct FancyNum {
@@ -1612,7 +1646,7 @@ http://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html
16121646
E0506: r##"
16131647
This error occurs when an attempt is made to assign to a borrowed value.
16141648
1615-
Example of erroneous code:
1649+
Erroneous code example:
16161650
16171651
```compile_fail,E0506
16181652
struct FancyNum {
@@ -1830,7 +1864,7 @@ http://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html
18301864
E0508: r##"
18311865
A value was moved out of a non-copy fixed-size array.
18321866
1833-
Example of erroneous code:
1867+
Erroneous code example:
18341868
18351869
```compile_fail,E0508
18361870
struct NonCopy;
@@ -1875,7 +1909,7 @@ E0509: r##"
18751909
This error occurs when an attempt is made to move out of a value whose type
18761910
implements the `Drop` trait.
18771911
1878-
Example of erroneous code:
1912+
Erroneous code example:
18791913
18801914
```compile_fail,E0509
18811915
struct FancyNum {
@@ -1991,6 +2025,8 @@ Cannot return value that references local variable
19912025
Local variables, function parameters and temporaries are all dropped before the
19922026
end of the function body. So a reference to them cannot be returned.
19932027
2028+
Erroneous code example:
2029+
19942030
```compile_fail,E0515
19952031
fn get_dangling_reference() -> &'static i32 {
19962032
let x = 0;
@@ -2092,14 +2128,18 @@ is non-empty. Exclusive range patterns include the start point but not the end
20922128
point, so this is equivalent to requiring the start of the range to be less
20932129
than the end of the range.
20942130
2095-
For example:
2131+
Erroneous code example:
20962132
2097-
```compile_fail
2098-
match 5u32 {
2099-
// This range is ok, albeit pointless.
2100-
1 .. 2 => {}
2101-
// This range is empty, and the compiler can tell.
2102-
5 .. 5 => {}
2133+
```compile_fail,E0579
2134+
#![feature(exclusive_range_pattern)]
2135+
2136+
fn main() {
2137+
match 5u32 {
2138+
// This range is ok, albeit pointless.
2139+
1 .. 2 => {}
2140+
// This range is empty, and the compiler can tell.
2141+
5 .. 5 => {} // error!
2142+
}
21032143
}
21042144
```
21052145
"##,
@@ -2127,7 +2167,7 @@ let mut c = || { x += 1 };
21272167
E0596: r##"
21282168
This error occurs because you tried to mutably borrow a non-mutable variable.
21292169
2130-
Example of erroneous code:
2170+
Erroneous code example:
21312171
21322172
```compile_fail,E0596
21332173
let x = 1;
@@ -2146,7 +2186,7 @@ let y = &mut x; // ok!
21462186
E0597: r##"
21472187
This error occurs because a value was dropped while it was still borrowed
21482188
2149-
Example of erroneous code:
2189+
Erroneous code example:
21502190
21512191
```compile_fail,E0597
21522192
struct Foo<'a> {
@@ -2183,6 +2223,8 @@ E0626: r##"
21832223
This error occurs because a borrow in a generator persists across a
21842224
yield point.
21852225
2226+
Erroneous code example:
2227+
21862228
```compile_fail,E0626
21872229
# #![feature(generators, generator_trait, pin)]
21882230
# use std::ops::Generator;
@@ -2274,7 +2316,7 @@ E0712: r##"
22742316
This error occurs because a borrow of a thread-local variable was made inside a
22752317
function which outlived the lifetime of the function.
22762318
2277-
Example of erroneous code:
2319+
Erroneous code example:
22782320
22792321
```compile_fail,E0712
22802322
#![feature(thread_local)]
@@ -2296,7 +2338,7 @@ E0713: r##"
22962338
This error occurs when an attempt is made to borrow state past the end of the
22972339
lifetime of a type that implements the `Drop` trait.
22982340
2299-
Example of erroneous code:
2341+
Erroneous code example:
23002342
23012343
```compile_fail,E0713
23022344
#![feature(nll)]

0 commit comments

Comments
 (0)