@@ -25,8 +25,8 @@ one is too specific or the ordering is incorrect.
2525
2626For example, the following `match` block has too many arms:
2727
28- ```compile_fail
29- match foo {
28+ ```compile_fail,E0001
29+ match Some(0) {
3030 Some(bar) => {/* ... */}
3131 None => {/* ... */}
3232 _ => {/* ... */} // All possible cases have already been handled
@@ -108,7 +108,7 @@ one or more possible inputs to a match expression. Guaranteed matches are
108108required in order to assign values to match expressions, or alternatively,
109109determine the flow of execution. Erroneous code example:
110110
111- ```compile_fail
111+ ```compile_fail,E0004
112112enum Terminator {
113113 HastaLaVistaBaby,
114114 TalkToMyHand,
@@ -153,7 +153,7 @@ E0005: r##"
153153Patterns used to bind names must be irrefutable, that is, they must guarantee
154154that a name will be extracted in all cases. Erroneous code example:
155155
156- ```compile_fail
156+ ```compile_fail,E0005
157157let x = Some(1);
158158let Some(y) = x;
159159// error: refutable pattern in local binding: `None` not covered
@@ -187,7 +187,7 @@ like the following is invalid as it requires the entire `Option<String>` to be
187187moved into a variable called `op_string` while simultaneously requiring the
188188inner `String` to be moved into a variable called `s`.
189189
190- ```compile_fail
190+ ```compile_fail,E0007
191191let x = Some("s".to_string());
192192
193193match x {
@@ -205,7 +205,7 @@ name is bound by move in a pattern, it should also be moved to wherever it is
205205referenced in the pattern guard code. Doing so however would prevent the name
206206from being available in the body of the match arm. Consider the following:
207207
208- ```compile_fail
208+ ```compile_fail,E0008
209209match Some("hi".to_string()) {
210210 Some(s) if s.len() == 0 => {}, // use s.
211211 _ => {},
@@ -229,7 +229,7 @@ match Some("hi".to_string()) {
229229Though this example seems innocuous and easy to solve, the problem becomes clear
230230when it encounters functions which consume the value:
231231
232- ```compile_fail
232+ ```compile_fail,E0008
233233struct A{}
234234
235235impl A {
@@ -283,7 +283,7 @@ This limitation may be removed in a future version of Rust.
283283
284284Erroneous code example:
285285
286- ```compile_fail
286+ ```compile_fail,E0009
287287struct X { x: (), }
288288
289289let x = Some((X { x: () }, X { x: () }));
@@ -351,25 +351,25 @@ An if-let pattern attempts to match the pattern, and enters the body if the
351351match was successful. If the match is irrefutable (when it cannot fail to
352352match), use a regular `let`-binding instead. For instance:
353353
354- ```compile_fail
354+ ```compile_fail,E0162
355355struct Irrefutable(i32);
356356let irr = Irrefutable(0);
357357
358358// This fails to compile because the match is irrefutable.
359359if let Irrefutable(x) = irr {
360360 // This body will always be executed.
361- foo(x);
361+ // ...
362362}
363363```
364364
365365Try this instead:
366366
367- ```ignore
367+ ```
368368struct Irrefutable(i32);
369369let irr = Irrefutable(0);
370370
371371let Irrefutable(x) = irr;
372- foo( x);
372+ println!("{}", x);
373373```
374374"## ,
375375
@@ -378,7 +378,7 @@ A while-let pattern attempts to match the pattern, and enters the body if the
378378match was successful. If the match is irrefutable (when it cannot fail to
379379match), use a regular `let`-binding inside a `loop` instead. For instance:
380380
381- ```compile_fail
381+ ```compile_fail,E0165
382382struct Irrefutable(i32);
383383let irr = Irrefutable(0);
384384
@@ -455,7 +455,7 @@ that a name will be extracted in all cases. Instead of pattern matching the
455455loop variable, consider using a `match` or `if let` inside the loop body. For
456456instance:
457457
458- ```compile_fail
458+ ```compile_fail,E0297
459459let xs : Vec<Option<i32>> = vec!(Some(1), None);
460460
461461// This fails because `None` is not covered.
@@ -497,7 +497,7 @@ on which the match depends in such a way, that the match would not be
497497exhaustive. For instance, the following would not match any arm if mutable
498498borrows were allowed:
499499
500- ```compile_fail
500+ ```compile_fail,E0301
501501match Some(()) {
502502 None => { },
503503 option if option.take().is_none() => {
@@ -515,10 +515,10 @@ on which the match depends in such a way, that the match would not be
515515exhaustive. For instance, the following would not match any arm if assignments
516516were allowed:
517517
518- ```compile_fail
518+ ```compile_fail,E0302
519519match Some(()) {
520520 None => { },
521- option if { option = None; false } { },
521+ option if { option = None; false } => { },
522522 Some(_) => { } // When the previous match failed, the option became `None`.
523523}
524524```
@@ -529,14 +529,18 @@ In certain cases it is possible for sub-bindings to violate memory safety.
529529Updates to the borrow checker in a future version of Rust may remove this
530530restriction, but for now patterns must be rewritten without sub-bindings.
531531
532- ```ignore
533- // Before.
532+ Before:
533+
534+ ```compile_fail,E0303
534535match Some("hi".to_string()) {
535536 ref op_string_ref @ Some(s) => {},
536537 None => {},
537538}
539+ ```
540+
541+ After:
538542
539- // After.
543+ ```
540544match Some("hi".to_string()) {
541545 Some(ref s) => {
542546 let op_string_ref = &Some(s);
@@ -556,7 +560,7 @@ This error indicates that the compiler was unable to sensibly evaluate an
556560constant expression that had to be evaluated. Attempting to divide by 0
557561or causing integer overflow are two ways to induce this error. For example:
558562
559- ```compile_fail
563+ ```compile_fail,E0080
560564enum Enum {
561565 X = (1 << 500),
562566 Y = (1 / 0)
@@ -575,7 +579,7 @@ E0306: r##"
575579In an array literal `[x; N]`, `N` is the number of elements in the array. This
576580must be an unsigned integer. Erroneous code example:
577581
578- ```compile_fail
582+ ```compile_fail,E0306
579583let x = [0i32; true]; // error: expected positive integer for repeat count,
580584 // found boolean
581585```
0 commit comments