@@ -64,7 +64,9 @@ E0004: r##"
64
64
This error indicates that the compiler cannot guarantee a matching pattern for
65
65
one or more possible inputs to a match expression. Guaranteed matches are
66
66
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:
68
70
69
71
```compile_fail,E0004
70
72
enum Terminator {
@@ -109,7 +111,9 @@ match x {
109
111
110
112
E0005 : r##"
111
113
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:
113
117
114
118
```compile_fail,E0005
115
119
let x = Some(1);
@@ -145,6 +149,8 @@ like the following is invalid as it requires the entire `Option<String>` to be
145
149
moved into a variable called `op_string` while simultaneously requiring the
146
150
inner `String` to be moved into a variable called `s`.
147
151
152
+ Erroneous code example:
153
+
148
154
```compile_fail,E0007
149
155
let x = Some("s".to_string());
150
156
@@ -211,27 +217,28 @@ match x {
211
217
E0010 : r##"
212
218
The value of statics and constants must be known at compile time, and they live
213
219
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.
216
221
217
- ```compile_fail,E0010
218
- #![feature(box_syntax)]
222
+ Erroneous code example:
219
223
220
- const CON : Box<i32> = box 0;
224
+ ```compile_fail,E0010
225
+ const CON: Vec<i32> = vec![0]; // error!
221
226
```
222
227
"## ,
223
228
224
229
E0013 : r##"
225
230
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:
228
234
229
235
```compile_fail,E0013
230
236
static X: i32 = 42;
231
237
const Y: i32 = X;
232
238
```
233
239
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:
235
242
236
243
```
237
244
const A: i32 = 42;
@@ -260,6 +267,7 @@ See [RFC 911] for more details on the design of `const fn`s.
260
267
261
268
E0017 : r##"
262
269
References in statics and constants may only refer to immutable values.
270
+
263
271
Erroneous code example:
264
272
265
273
```compile_fail,E0017
@@ -282,24 +290,17 @@ If you really want global mutable state, try using `static mut` or a global
282
290
283
291
E0019 : r##"
284
292
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.
287
294
288
- ```compile_fail
289
- enum Test {
290
- V1
291
- }
295
+ Erroneous code example:
292
296
293
- impl Test {
294
- fn test(&self) -> i32 {
295
- 12
296
- }
297
- }
297
+ ```compile_fail,E0019
298
+ #![feature(box_syntax)]
298
299
299
300
fn main() {
300
- const FOO: Test = Test::V1 ;
301
+ struct MyOwned ;
301
302
302
- const A: i32 = FOO.test() ; // You can't call Test::func() here !
303
+ static STATIC11: Box<MyOwned> = box MyOwned ; // error !
303
304
}
304
305
```
305
306
@@ -328,13 +329,13 @@ fn main() {
328
329
329
330
E0030 : r##"
330
331
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
332
333
requiring the start of the range to be less than or equal to the end of the
333
334
range.
334
335
335
- For example:
336
+ Erroneous code example:
336
337
337
- ```compile_fail
338
+ ```compile_fail,E0030
338
339
match 5u32 {
339
340
// This range is ok, albeit pointless.
340
341
1 ..= 1 => {}
@@ -379,6 +380,26 @@ See also https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html
379
380
"## ,
380
381
381
382
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
+
382
403
`const` and `static` mean different things. A `const` is a compile-time
383
404
constant, an alias for a literal value. This property means you can match it
384
405
directly within a pattern.
@@ -405,7 +426,7 @@ values of a known size can be moved.
405
426
406
427
Erroneous code example:
407
428
408
- ```compile_fail
429
+ ```compile_fail,E0161
409
430
#![feature(box_syntax)]
410
431
411
432
fn main() {
@@ -705,7 +726,9 @@ about safety.
705
726
"## ,
706
727
707
728
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:
709
732
710
733
```compile_fail,E0381
711
734
fn main() {
@@ -727,7 +750,9 @@ fn main() {
727
750
728
751
E0382 : r##"
729
752
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:
731
756
732
757
```compile_fail,E0382
733
758
struct MyStruct { s: u32 }
@@ -934,7 +959,9 @@ E0387: r##"
934
959
#### Note: this error code is no longer emitted by the compiler.
935
960
936
961
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:
938
965
939
966
```compile_fail
940
967
// 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
999
1026
commonly occurs when attempting to assign to a non-mutable reference of a
1000
1027
mutable reference (`&(&mut T)`).
1001
1028
1002
- Example of erroneous code:
1029
+ Erroneous code example :
1003
1030
1004
1031
```compile_fail
1005
1032
struct FancyNum {
@@ -1059,8 +1086,9 @@ fn main() {
1059
1086
"## ,
1060
1087
1061
1088
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:
1064
1092
1065
1093
```compile_fail,E0492
1066
1094
use std::sync::atomic::AtomicUsize;
@@ -1177,7 +1205,9 @@ static FOO: Foo = Foo { field1: DropType::A }; // We initialize all fields
1177
1205
"## ,
1178
1206
1179
1207
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:
1181
1211
1182
1212
```compile_fail,E0499
1183
1213
let mut i = 0;
1208
1238
"## ,
1209
1239
1210
1240
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:
1212
1244
1213
1245
```compile_fail,E0500
1214
1246
fn you_know_nothing(jon_snow: &mut i32) {
@@ -1259,7 +1291,7 @@ situation, the closure is borrowing the variable. Take a look at
1259
1291
http://rustbyexample.com/fn/closures/capture.html for more information about
1260
1292
capturing.
1261
1293
1262
- Example of erroneous code:
1294
+ Erroneous code example :
1263
1295
1264
1296
```compile_fail,E0501
1265
1297
fn inside_closure(x: &mut i32) {
@@ -1332,7 +1364,7 @@ E0502: r##"
1332
1364
This error indicates that you are trying to borrow a variable as mutable when it
1333
1365
has already been borrowed as immutable.
1334
1366
1335
- Example of erroneous code:
1367
+ Erroneous code example :
1336
1368
1337
1369
```compile_fail,E0502
1338
1370
fn bar(x: &mut i32) {}
@@ -1363,7 +1395,7 @@ https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html.
1363
1395
E0503 : r##"
1364
1396
A value was used after it was mutably borrowed.
1365
1397
1366
- Example of erroneous code:
1398
+ Erroneous code example :
1367
1399
1368
1400
```compile_fail,E0503
1369
1401
fn main() {
@@ -1421,7 +1453,7 @@ E0504: r##"
1421
1453
This error occurs when an attempt is made to move a borrowed variable into a
1422
1454
closure.
1423
1455
1424
- Example of erroneous code:
1456
+ Erroneous code example :
1425
1457
1426
1458
```compile_fail
1427
1459
struct FancyNum {
@@ -1612,7 +1644,7 @@ http://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html
1612
1644
E0506 : r##"
1613
1645
This error occurs when an attempt is made to assign to a borrowed value.
1614
1646
1615
- Example of erroneous code:
1647
+ Erroneous code example :
1616
1648
1617
1649
```compile_fail,E0506
1618
1650
struct FancyNum {
@@ -1830,7 +1862,7 @@ http://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html
1830
1862
E0508 : r##"
1831
1863
A value was moved out of a non-copy fixed-size array.
1832
1864
1833
- Example of erroneous code:
1865
+ Erroneous code example :
1834
1866
1835
1867
```compile_fail,E0508
1836
1868
struct NonCopy;
@@ -1875,7 +1907,7 @@ E0509: r##"
1875
1907
This error occurs when an attempt is made to move out of a value whose type
1876
1908
implements the `Drop` trait.
1877
1909
1878
- Example of erroneous code:
1910
+ Erroneous code example :
1879
1911
1880
1912
```compile_fail,E0509
1881
1913
struct FancyNum {
@@ -1991,6 +2023,8 @@ Cannot return value that references local variable
1991
2023
Local variables, function parameters and temporaries are all dropped before the
1992
2024
end of the function body. So a reference to them cannot be returned.
1993
2025
2026
+ Erroneous code example:
2027
+
1994
2028
```compile_fail,E0515
1995
2029
fn get_dangling_reference() -> &'static i32 {
1996
2030
let x = 0;
@@ -2092,14 +2126,18 @@ is non-empty. Exclusive range patterns include the start point but not the end
2092
2126
point, so this is equivalent to requiring the start of the range to be less
2093
2127
than the end of the range.
2094
2128
2095
- For example:
2129
+ Erroneous code example:
2096
2130
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
+ }
2103
2141
}
2104
2142
```
2105
2143
"## ,
@@ -2127,7 +2165,7 @@ let mut c = || { x += 1 };
2127
2165
E0596 : r##"
2128
2166
This error occurs because you tried to mutably borrow a non-mutable variable.
2129
2167
2130
- Example of erroneous code:
2168
+ Erroneous code example :
2131
2169
2132
2170
```compile_fail,E0596
2133
2171
let x = 1;
@@ -2146,7 +2184,7 @@ let y = &mut x; // ok!
2146
2184
E0597 : r##"
2147
2185
This error occurs because a value was dropped while it was still borrowed
2148
2186
2149
- Example of erroneous code:
2187
+ Erroneous code example :
2150
2188
2151
2189
```compile_fail,E0597
2152
2190
struct Foo<'a> {
@@ -2183,6 +2221,8 @@ E0626: r##"
2183
2221
This error occurs because a borrow in a generator persists across a
2184
2222
yield point.
2185
2223
2224
+ Erroneous code example:
2225
+
2186
2226
```compile_fail,E0626
2187
2227
# #![feature(generators, generator_trait, pin)]
2188
2228
# use std::ops::Generator;
@@ -2274,7 +2314,7 @@ E0712: r##"
2274
2314
This error occurs because a borrow of a thread-local variable was made inside a
2275
2315
function which outlived the lifetime of the function.
2276
2316
2277
- Example of erroneous code:
2317
+ Erroneous code example :
2278
2318
2279
2319
```compile_fail,E0712
2280
2320
#![feature(thread_local)]
@@ -2296,7 +2336,7 @@ E0713: r##"
2296
2336
This error occurs when an attempt is made to borrow state past the end of the
2297
2337
lifetime of a type that implements the `Drop` trait.
2298
2338
2299
- Example of erroneous code:
2339
+ Erroneous code example :
2300
2340
2301
2341
```compile_fail,E0713
2302
2342
#![feature(nll)]
0 commit comments