@@ -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,8 +217,9 @@ 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.
221
+
222
+ Erroneous code example:
216
223
217
224
```compile_fail,E0010
218
225
#![feature(box_syntax)]
@@ -223,15 +230,17 @@ const CON : Box<i32> = box 0;
223
230
224
231
E0013 : r##"
225
232
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:
228
236
229
237
```compile_fail,E0013
230
238
static X: i32 = 42;
231
239
const Y: i32 = X;
232
240
```
233
241
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:
235
244
236
245
```
237
246
const A: i32 = 42;
@@ -260,6 +269,7 @@ See [RFC 911] for more details on the design of `const fn`s.
260
269
261
270
E0017 : r##"
262
271
References in statics and constants may only refer to immutable values.
272
+
263
273
Erroneous code example:
264
274
265
275
```compile_fail,E0017
@@ -282,24 +292,17 @@ If you really want global mutable state, try using `static mut` or a global
282
292
283
293
E0019 : r##"
284
294
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.
287
296
288
- ```compile_fail
289
- enum Test {
290
- V1
291
- }
297
+ Erroneous code example:
292
298
293
- impl Test {
294
- fn test(&self) -> i32 {
295
- 12
296
- }
297
- }
299
+ ```compile_fail,E0019
300
+ #![feature(box_syntax)]
298
301
299
302
fn main() {
300
- const FOO: Test = Test::V1 ;
303
+ struct MyOwned ;
301
304
302
- const A: i32 = FOO.test() ; // You can't call Test::func() here !
305
+ static STATIC11: Box<MyOwned> = box MyOwned ; // error !
303
306
}
304
307
```
305
308
@@ -328,13 +331,13 @@ fn main() {
328
331
329
332
E0030 : r##"
330
333
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
332
335
requiring the start of the range to be less than or equal to the end of the
333
336
range.
334
337
335
- For example:
338
+ Erroneous code example:
336
339
337
- ```compile_fail
340
+ ```compile_fail,E0030
338
341
match 5u32 {
339
342
// This range is ok, albeit pointless.
340
343
1 ..= 1 => {}
@@ -379,6 +382,26 @@ See also https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html
379
382
"## ,
380
383
381
384
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
+
382
405
`const` and `static` mean different things. A `const` is a compile-time
383
406
constant, an alias for a literal value. This property means you can match it
384
407
directly within a pattern.
@@ -405,7 +428,7 @@ values of a known size can be moved.
405
428
406
429
Erroneous code example:
407
430
408
- ```compile_fail
431
+ ```compile_fail,E0161
409
432
#![feature(box_syntax)]
410
433
411
434
fn main() {
@@ -705,7 +728,9 @@ about safety.
705
728
"## ,
706
729
707
730
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:
709
734
710
735
```compile_fail,E0381
711
736
fn main() {
@@ -727,7 +752,9 @@ fn main() {
727
752
728
753
E0382 : r##"
729
754
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:
731
758
732
759
```compile_fail,E0382
733
760
struct MyStruct { s: u32 }
@@ -934,7 +961,9 @@ E0387: r##"
934
961
#### Note: this error code is no longer emitted by the compiler.
935
962
936
963
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:
938
967
939
968
```compile_fail
940
969
// 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
999
1028
commonly occurs when attempting to assign to a non-mutable reference of a
1000
1029
mutable reference (`&(&mut T)`).
1001
1030
1002
- Example of erroneous code:
1031
+ Erroneous code example :
1003
1032
1004
1033
```compile_fail
1005
1034
struct FancyNum {
@@ -1059,8 +1088,9 @@ fn main() {
1059
1088
"## ,
1060
1089
1061
1090
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:
1064
1094
1065
1095
```compile_fail,E0492
1066
1096
use std::sync::atomic::AtomicUsize;
@@ -1177,7 +1207,9 @@ static FOO: Foo = Foo { field1: DropType::A }; // We initialize all fields
1177
1207
"## ,
1178
1208
1179
1209
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:
1181
1213
1182
1214
```compile_fail,E0499
1183
1215
let mut i = 0;
1208
1240
"## ,
1209
1241
1210
1242
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:
1212
1246
1213
1247
```compile_fail,E0500
1214
1248
fn you_know_nothing(jon_snow: &mut i32) {
@@ -1259,7 +1293,7 @@ situation, the closure is borrowing the variable. Take a look at
1259
1293
http://rustbyexample.com/fn/closures/capture.html for more information about
1260
1294
capturing.
1261
1295
1262
- Example of erroneous code:
1296
+ Erroneous code example :
1263
1297
1264
1298
```compile_fail,E0501
1265
1299
fn inside_closure(x: &mut i32) {
@@ -1332,7 +1366,7 @@ E0502: r##"
1332
1366
This error indicates that you are trying to borrow a variable as mutable when it
1333
1367
has already been borrowed as immutable.
1334
1368
1335
- Example of erroneous code:
1369
+ Erroneous code example :
1336
1370
1337
1371
```compile_fail,E0502
1338
1372
fn bar(x: &mut i32) {}
@@ -1363,7 +1397,7 @@ https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html.
1363
1397
E0503 : r##"
1364
1398
A value was used after it was mutably borrowed.
1365
1399
1366
- Example of erroneous code:
1400
+ Erroneous code example :
1367
1401
1368
1402
```compile_fail,E0503
1369
1403
fn main() {
@@ -1421,7 +1455,7 @@ E0504: r##"
1421
1455
This error occurs when an attempt is made to move a borrowed variable into a
1422
1456
closure.
1423
1457
1424
- Example of erroneous code:
1458
+ Erroneous code example :
1425
1459
1426
1460
```compile_fail
1427
1461
struct FancyNum {
@@ -1612,7 +1646,7 @@ http://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html
1612
1646
E0506 : r##"
1613
1647
This error occurs when an attempt is made to assign to a borrowed value.
1614
1648
1615
- Example of erroneous code:
1649
+ Erroneous code example :
1616
1650
1617
1651
```compile_fail,E0506
1618
1652
struct FancyNum {
@@ -1830,7 +1864,7 @@ http://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html
1830
1864
E0508 : r##"
1831
1865
A value was moved out of a non-copy fixed-size array.
1832
1866
1833
- Example of erroneous code:
1867
+ Erroneous code example :
1834
1868
1835
1869
```compile_fail,E0508
1836
1870
struct NonCopy;
@@ -1875,7 +1909,7 @@ E0509: r##"
1875
1909
This error occurs when an attempt is made to move out of a value whose type
1876
1910
implements the `Drop` trait.
1877
1911
1878
- Example of erroneous code:
1912
+ Erroneous code example :
1879
1913
1880
1914
```compile_fail,E0509
1881
1915
struct FancyNum {
@@ -1991,6 +2025,8 @@ Cannot return value that references local variable
1991
2025
Local variables, function parameters and temporaries are all dropped before the
1992
2026
end of the function body. So a reference to them cannot be returned.
1993
2027
2028
+ Erroneous code example:
2029
+
1994
2030
```compile_fail,E0515
1995
2031
fn get_dangling_reference() -> &'static i32 {
1996
2032
let x = 0;
@@ -2092,14 +2128,18 @@ is non-empty. Exclusive range patterns include the start point but not the end
2092
2128
point, so this is equivalent to requiring the start of the range to be less
2093
2129
than the end of the range.
2094
2130
2095
- For example:
2131
+ Erroneous code example:
2096
2132
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
+ }
2103
2143
}
2104
2144
```
2105
2145
"## ,
@@ -2127,7 +2167,7 @@ let mut c = || { x += 1 };
2127
2167
E0596 : r##"
2128
2168
This error occurs because you tried to mutably borrow a non-mutable variable.
2129
2169
2130
- Example of erroneous code:
2170
+ Erroneous code example :
2131
2171
2132
2172
```compile_fail,E0596
2133
2173
let x = 1;
@@ -2146,7 +2186,7 @@ let y = &mut x; // ok!
2146
2186
E0597 : r##"
2147
2187
This error occurs because a value was dropped while it was still borrowed
2148
2188
2149
- Example of erroneous code:
2189
+ Erroneous code example :
2150
2190
2151
2191
```compile_fail,E0597
2152
2192
struct Foo<'a> {
@@ -2183,6 +2223,8 @@ E0626: r##"
2183
2223
This error occurs because a borrow in a generator persists across a
2184
2224
yield point.
2185
2225
2226
+ Erroneous code example:
2227
+
2186
2228
```compile_fail,E0626
2187
2229
# #![feature(generators, generator_trait, pin)]
2188
2230
# use std::ops::Generator;
@@ -2274,7 +2316,7 @@ E0712: r##"
2274
2316
This error occurs because a borrow of a thread-local variable was made inside a
2275
2317
function which outlived the lifetime of the function.
2276
2318
2277
- Example of erroneous code:
2319
+ Erroneous code example :
2278
2320
2279
2321
```compile_fail,E0712
2280
2322
#![feature(thread_local)]
@@ -2296,7 +2338,7 @@ E0713: r##"
2296
2338
This error occurs when an attempt is made to borrow state past the end of the
2297
2339
lifetime of a type that implements the `Drop` trait.
2298
2340
2299
- Example of erroneous code:
2341
+ Erroneous code example :
2300
2342
2301
2343
```compile_fail,E0713
2302
2344
#![feature(nll)]
0 commit comments