Skip to content

Commit 06a02b5

Browse files
Unification and cleanup of librustc_mir error codes
1 parent 019fba8 commit 06a02b5

File tree

1 file changed

+93
-53
lines changed

1 file changed

+93
-53
lines changed

src/librustc_mir/error_codes.rs

+93-53
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,27 +217,28 @@ 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.
216221
217-
```compile_fail,E0010
218-
#![feature(box_syntax)]
222+
Erroneous code example:
219223
220-
const CON : Box<i32> = box 0;
224+
```compile_fail,E0010
225+
const CON: Vec<i32> = vec![0]; // error!
221226
```
222227
"##,
223228

224229
E0013: r##"
225230
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:
231+
variable cannot refer to a static variable.
232+
233+
Erroneous code example:
228234
229235
```compile_fail,E0013
230236
static X: i32 = 42;
231237
const Y: i32 = X;
232238
```
233239
234-
To fix this, the value can be extracted as a const and then used:
240+
In this example, `Y` cannot refer to `X` here. To fix this, the value can be
241+
extracted as a const and then used:
235242
236243
```
237244
const A: i32 = 42;
@@ -260,6 +267,7 @@ See [RFC 911] for more details on the design of `const fn`s.
260267

261268
E0017: r##"
262269
References in statics and constants may only refer to immutable values.
270+
263271
Erroneous code example:
264272
265273
```compile_fail,E0017
@@ -282,24 +290,17 @@ If you really want global mutable state, try using `static mut` or a global
282290

283291
E0019: r##"
284292
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:
293+
because the expression's value must be known at compile-time.
287294
288-
```compile_fail
289-
enum Test {
290-
V1
291-
}
295+
Erroneous code example:
292296
293-
impl Test {
294-
fn test(&self) -> i32 {
295-
12
296-
}
297-
}
297+
```compile_fail,E0019
298+
#![feature(box_syntax)]
298299
299300
fn main() {
300-
const FOO: Test = Test::V1;
301+
struct MyOwned;
301302
302-
const A: i32 = FOO.test(); // You can't call Test::func() here!
303+
static STATIC11: Box<MyOwned> = box MyOwned; // error!
303304
}
304305
```
305306
@@ -328,13 +329,13 @@ fn main() {
328329

329330
E0030: r##"
330331
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
332+
non-empty. Range patterns include both end-points, so this is equivalent to
332333
requiring the start of the range to be less than or equal to the end of the
333334
range.
334335
335-
For example:
336+
Erroneous code example:
336337
337-
```compile_fail
338+
```compile_fail,E0030
338339
match 5u32 {
339340
// This range is ok, albeit pointless.
340341
1 ..= 1 => {}
@@ -379,6 +380,26 @@ See also https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html
379380
"##,
380381

381382
E0158: r##"
383+
An associated const has been referenced in a pattern.
384+
385+
Erroneous code example:
386+
387+
```compile_fail,E0158
388+
enum EFoo { A, B, C, D }
389+
390+
trait Foo {
391+
const X: EFoo;
392+
}
393+
394+
fn test<A: Foo>(arg: EFoo) {
395+
match arg {
396+
A::X => { // error!
397+
println!("A::X");
398+
}
399+
}
400+
}
401+
```
402+
382403
`const` and `static` mean different things. A `const` is a compile-time
383404
constant, an alias for a literal value. This property means you can match it
384405
directly within a pattern.
@@ -405,7 +426,7 @@ values of a known size can be moved.
405426
406427
Erroneous code example:
407428
408-
```compile_fail
429+
```compile_fail,E0161
409430
#![feature(box_syntax)]
410431
411432
fn main() {
@@ -705,7 +726,9 @@ about safety.
705726
"##,
706727

707728
E0381: r##"
708-
It is not allowed to use or capture an uninitialized variable. For example:
729+
It is not allowed to use or capture an uninitialized variable.
730+
731+
Erroneous code example:
709732
710733
```compile_fail,E0381
711734
fn main() {
@@ -727,7 +750,9 @@ fn main() {
727750

728751
E0382: r##"
729752
This error occurs when an attempt is made to use a variable after its contents
730-
have been moved elsewhere. For example:
753+
have been moved elsewhere.
754+
755+
Erroneous code example:
731756
732757
```compile_fail,E0382
733758
struct MyStruct { s: u32 }
@@ -934,7 +959,9 @@ E0387: r##"
934959
#### Note: this error code is no longer emitted by the compiler.
935960
936961
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:
962+
that a closure has captured immutably.
963+
964+
Erroneous code example:
938965
939966
```compile_fail
940967
// Accepts a function or a closure that captures its environment immutably.
@@ -999,7 +1026,7 @@ An attempt was made to mutate data using a non-mutable reference. This
9991026
commonly occurs when attempting to assign to a non-mutable reference of a
10001027
mutable reference (`&(&mut T)`).
10011028
1002-
Example of erroneous code:
1029+
Erroneous code example:
10031030
10041031
```compile_fail
10051032
struct FancyNum {
@@ -1059,8 +1086,9 @@ fn main() {
10591086
"##,
10601087

10611088
E0492: r##"
1062-
A borrow of a constant containing interior mutability was attempted. Erroneous
1063-
code example:
1089+
A borrow of a constant containing interior mutability was attempted.
1090+
1091+
Erroneous code example:
10641092
10651093
```compile_fail,E0492
10661094
use std::sync::atomic::AtomicUsize;
@@ -1177,7 +1205,9 @@ static FOO: Foo = Foo { field1: DropType::A }; // We initialize all fields
11771205
"##,
11781206

11791207
E0499: r##"
1180-
A variable was borrowed as mutable more than once. Erroneous code example:
1208+
A variable was borrowed as mutable more than once.
1209+
1210+
Erroneous code example:
11811211
11821212
```compile_fail,E0499
11831213
let mut i = 0;
@@ -1208,7 +1238,9 @@ a;
12081238
"##,
12091239

12101240
E0500: r##"
1211-
A borrowed variable was used by a closure. Example of erroneous code:
1241+
A borrowed variable was used by a closure.
1242+
1243+
Erroneous code example:
12121244
12131245
```compile_fail,E0500
12141246
fn you_know_nothing(jon_snow: &mut i32) {
@@ -1259,7 +1291,7 @@ situation, the closure is borrowing the variable. Take a look at
12591291
http://rustbyexample.com/fn/closures/capture.html for more information about
12601292
capturing.
12611293
1262-
Example of erroneous code:
1294+
Erroneous code example:
12631295
12641296
```compile_fail,E0501
12651297
fn inside_closure(x: &mut i32) {
@@ -1332,7 +1364,7 @@ E0502: r##"
13321364
This error indicates that you are trying to borrow a variable as mutable when it
13331365
has already been borrowed as immutable.
13341366
1335-
Example of erroneous code:
1367+
Erroneous code example:
13361368
13371369
```compile_fail,E0502
13381370
fn bar(x: &mut i32) {}
@@ -1363,7 +1395,7 @@ https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html.
13631395
E0503: r##"
13641396
A value was used after it was mutably borrowed.
13651397
1366-
Example of erroneous code:
1398+
Erroneous code example:
13671399
13681400
```compile_fail,E0503
13691401
fn main() {
@@ -1421,7 +1453,7 @@ E0504: r##"
14211453
This error occurs when an attempt is made to move a borrowed variable into a
14221454
closure.
14231455
1424-
Example of erroneous code:
1456+
Erroneous code example:
14251457
14261458
```compile_fail
14271459
struct FancyNum {
@@ -1612,7 +1644,7 @@ http://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html
16121644
E0506: r##"
16131645
This error occurs when an attempt is made to assign to a borrowed value.
16141646
1615-
Example of erroneous code:
1647+
Erroneous code example:
16161648
16171649
```compile_fail,E0506
16181650
struct FancyNum {
@@ -1830,7 +1862,7 @@ http://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html
18301862
E0508: r##"
18311863
A value was moved out of a non-copy fixed-size array.
18321864
1833-
Example of erroneous code:
1865+
Erroneous code example:
18341866
18351867
```compile_fail,E0508
18361868
struct NonCopy;
@@ -1875,7 +1907,7 @@ E0509: r##"
18751907
This error occurs when an attempt is made to move out of a value whose type
18761908
implements the `Drop` trait.
18771909
1878-
Example of erroneous code:
1910+
Erroneous code example:
18791911
18801912
```compile_fail,E0509
18811913
struct FancyNum {
@@ -1991,6 +2023,8 @@ Cannot return value that references local variable
19912023
Local variables, function parameters and temporaries are all dropped before the
19922024
end of the function body. So a reference to them cannot be returned.
19932025
2026+
Erroneous code example:
2027+
19942028
```compile_fail,E0515
19952029
fn get_dangling_reference() -> &'static i32 {
19962030
let x = 0;
@@ -2092,14 +2126,18 @@ is non-empty. Exclusive range patterns include the start point but not the end
20922126
point, so this is equivalent to requiring the start of the range to be less
20932127
than the end of the range.
20942128
2095-
For example:
2129+
Erroneous code example:
20962130
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 => {}
2131+
```compile_fail,E0579
2132+
#![feature(exclusive_range_pattern)]
2133+
2134+
fn main() {
2135+
match 5u32 {
2136+
// This range is ok, albeit pointless.
2137+
1 .. 2 => {}
2138+
// This range is empty, and the compiler can tell.
2139+
5 .. 5 => {} // error!
2140+
}
21032141
}
21042142
```
21052143
"##,
@@ -2127,7 +2165,7 @@ let mut c = || { x += 1 };
21272165
E0596: r##"
21282166
This error occurs because you tried to mutably borrow a non-mutable variable.
21292167
2130-
Example of erroneous code:
2168+
Erroneous code example:
21312169
21322170
```compile_fail,E0596
21332171
let x = 1;
@@ -2146,7 +2184,7 @@ let y = &mut x; // ok!
21462184
E0597: r##"
21472185
This error occurs because a value was dropped while it was still borrowed
21482186
2149-
Example of erroneous code:
2187+
Erroneous code example:
21502188
21512189
```compile_fail,E0597
21522190
struct Foo<'a> {
@@ -2183,6 +2221,8 @@ E0626: r##"
21832221
This error occurs because a borrow in a generator persists across a
21842222
yield point.
21852223
2224+
Erroneous code example:
2225+
21862226
```compile_fail,E0626
21872227
# #![feature(generators, generator_trait, pin)]
21882228
# use std::ops::Generator;
@@ -2274,7 +2314,7 @@ E0712: r##"
22742314
This error occurs because a borrow of a thread-local variable was made inside a
22752315
function which outlived the lifetime of the function.
22762316
2277-
Example of erroneous code:
2317+
Erroneous code example:
22782318
22792319
```compile_fail,E0712
22802320
#![feature(thread_local)]
@@ -2296,7 +2336,7 @@ E0713: r##"
22962336
This error occurs when an attempt is made to borrow state past the end of the
22972337
lifetime of a type that implements the `Drop` trait.
22982338
2299-
Example of erroneous code:
2339+
Erroneous code example:
23002340
23012341
```compile_fail,E0713
23022342
#![feature(nll)]

0 commit comments

Comments
 (0)