@@ -64,7 +64,9 @@ E0004: r##"
6464This error indicates that the compiler cannot guarantee a matching pattern for
6565one or more possible inputs to a match expression. Guaranteed matches are
6666required 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
7072enum Terminator {
@@ -109,7 +111,9 @@ match x {
109111
110112E0005 : r##"
111113Patterns 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
115119let x = Some(1);
@@ -145,6 +149,8 @@ like the following is invalid as it requires the entire `Option<String>` to be
145149moved into a variable called `op_string` while simultaneously requiring the
146150inner `String` to be moved into a variable called `s`.
147151
152+ Erroneous code example:
153+
148154```compile_fail,E0007
149155let x = Some("s".to_string());
150156
@@ -211,27 +217,28 @@ match x {
211217E0010 : r##"
212218The value of statics and constants must be known at compile time, and they live
213219for 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
224229E0013 : r##"
225230Static 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
230236static X: i32 = 42;
231237const 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```
237244const A: i32 = 42;
@@ -260,6 +267,7 @@ See [RFC 911] for more details on the design of `const fn`s.
260267
261268E0017 : r##"
262269References in statics and constants may only refer to immutable values.
270+
263271Erroneous 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
283291E0019 : r##"
284292A 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
299300fn 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
329330E0030 : r##"
330331When 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
332333requiring the start of the range to be less than or equal to the end of the
333334range.
334335
335- For example:
336+ Erroneous code example:
336337
337- ```compile_fail
338+ ```compile_fail,E0030
338339match 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
381382E0158 : 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
383404constant, an alias for a literal value. This property means you can match it
384405directly within a pattern.
@@ -405,7 +426,7 @@ values of a known size can be moved.
405426
406427Erroneous code example:
407428
408- ```compile_fail
429+ ```compile_fail,E0161
409430#![feature(box_syntax)]
410431
411432fn main() {
@@ -705,7 +726,9 @@ about safety.
705726"## ,
706727
707728E0381 : 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
711734fn main() {
@@ -727,7 +750,9 @@ fn main() {
727750
728751E0382 : r##"
729752This 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
733758struct MyStruct { s: u32 }
@@ -934,7 +959,9 @@ E0387: r##"
934959#### Note: this error code is no longer emitted by the compiler.
935960
936961This 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
9991026commonly occurs when attempting to assign to a non-mutable reference of a
10001027mutable reference (`&(&mut T)`).
10011028
1002- Example of erroneous code:
1029+ Erroneous code example :
10031030
10041031```compile_fail
10051032struct FancyNum {
@@ -1059,8 +1086,9 @@ fn main() {
10591086"## ,
10601087
10611088E0492 : 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
10661094use std::sync::atomic::AtomicUsize;
@@ -1177,7 +1205,9 @@ static FOO: Foo = Foo { field1: DropType::A }; // We initialize all fields
11771205"## ,
11781206
11791207E0499 : 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
11831213let mut i = 0;
12081238"## ,
12091239
12101240E0500 : 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
12141246fn you_know_nothing(jon_snow: &mut i32) {
@@ -1259,7 +1291,7 @@ situation, the closure is borrowing the variable. Take a look at
12591291http://rustbyexample.com/fn/closures/capture.html for more information about
12601292capturing.
12611293
1262- Example of erroneous code:
1294+ Erroneous code example :
12631295
12641296```compile_fail,E0501
12651297fn inside_closure(x: &mut i32) {
@@ -1332,7 +1364,7 @@ E0502: r##"
13321364This error indicates that you are trying to borrow a variable as mutable when it
13331365has already been borrowed as immutable.
13341366
1335- Example of erroneous code:
1367+ Erroneous code example :
13361368
13371369```compile_fail,E0502
13381370fn bar(x: &mut i32) {}
@@ -1363,7 +1395,7 @@ https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html.
13631395E0503 : r##"
13641396A value was used after it was mutably borrowed.
13651397
1366- Example of erroneous code:
1398+ Erroneous code example :
13671399
13681400```compile_fail,E0503
13691401fn main() {
@@ -1421,7 +1453,7 @@ E0504: r##"
14211453This error occurs when an attempt is made to move a borrowed variable into a
14221454closure.
14231455
1424- Example of erroneous code:
1456+ Erroneous code example :
14251457
14261458```compile_fail
14271459struct FancyNum {
@@ -1612,7 +1644,7 @@ http://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html
16121644E0506 : r##"
16131645This 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
16181650struct FancyNum {
@@ -1830,7 +1862,7 @@ http://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html
18301862E0508 : r##"
18311863A 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
18361868struct NonCopy;
@@ -1875,7 +1907,7 @@ E0509: r##"
18751907This error occurs when an attempt is made to move out of a value whose type
18761908implements the `Drop` trait.
18771909
1878- Example of erroneous code:
1910+ Erroneous code example :
18791911
18801912```compile_fail,E0509
18811913struct FancyNum {
@@ -1991,6 +2023,8 @@ Cannot return value that references local variable
19912023Local variables, function parameters and temporaries are all dropped before the
19922024end of the function body. So a reference to them cannot be returned.
19932025
2026+ Erroneous code example:
2027+
19942028```compile_fail,E0515
19952029fn 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
20922126point, so this is equivalent to requiring the start of the range to be less
20932127than 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 };
21272165E0596 : r##"
21282166This 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
21332171let x = 1;
@@ -2146,7 +2184,7 @@ let y = &mut x; // ok!
21462184E0597 : r##"
21472185This 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
21522190struct Foo<'a> {
@@ -2183,6 +2221,8 @@ E0626: r##"
21832221This error occurs because a borrow in a generator persists across a
21842222yield 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##"
22742314This error occurs because a borrow of a thread-local variable was made inside a
22752315function 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##"
22962336This error occurs when an attempt is made to borrow state past the end of the
22972337lifetime 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