@@ -25,8 +25,8 @@ one is too specific or the ordering is incorrect.
25
25
26
26
For example, the following `match` block has too many arms:
27
27
28
- ```compile_fail
29
- match foo {
28
+ ```compile_fail,E0001
29
+ match Some(0) {
30
30
Some(bar) => {/* ... */}
31
31
None => {/* ... */}
32
32
_ => {/* ... */} // All possible cases have already been handled
@@ -108,7 +108,7 @@ one or more possible inputs to a match expression. Guaranteed matches are
108
108
required in order to assign values to match expressions, or alternatively,
109
109
determine the flow of execution. Erroneous code example:
110
110
111
- ```compile_fail
111
+ ```compile_fail,E0004
112
112
enum Terminator {
113
113
HastaLaVistaBaby,
114
114
TalkToMyHand,
@@ -153,7 +153,7 @@ E0005: r##"
153
153
Patterns used to bind names must be irrefutable, that is, they must guarantee
154
154
that a name will be extracted in all cases. Erroneous code example:
155
155
156
- ```compile_fail
156
+ ```compile_fail,E0005
157
157
let x = Some(1);
158
158
let Some(y) = x;
159
159
// 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
187
187
moved into a variable called `op_string` while simultaneously requiring the
188
188
inner `String` to be moved into a variable called `s`.
189
189
190
- ```compile_fail
190
+ ```compile_fail,E0007
191
191
let x = Some("s".to_string());
192
192
193
193
match x {
@@ -205,7 +205,7 @@ name is bound by move in a pattern, it should also be moved to wherever it is
205
205
referenced in the pattern guard code. Doing so however would prevent the name
206
206
from being available in the body of the match arm. Consider the following:
207
207
208
- ```compile_fail
208
+ ```compile_fail,E0008
209
209
match Some("hi".to_string()) {
210
210
Some(s) if s.len() == 0 => {}, // use s.
211
211
_ => {},
@@ -229,7 +229,7 @@ match Some("hi".to_string()) {
229
229
Though this example seems innocuous and easy to solve, the problem becomes clear
230
230
when it encounters functions which consume the value:
231
231
232
- ```compile_fail
232
+ ```compile_fail,E0008
233
233
struct A{}
234
234
235
235
impl A {
@@ -283,7 +283,7 @@ This limitation may be removed in a future version of Rust.
283
283
284
284
Erroneous code example:
285
285
286
- ```compile_fail
286
+ ```compile_fail,E0009
287
287
struct X { x: (), }
288
288
289
289
let 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
351
351
match was successful. If the match is irrefutable (when it cannot fail to
352
352
match), use a regular `let`-binding instead. For instance:
353
353
354
- ```compile_fail
354
+ ```compile_fail,E0162
355
355
struct Irrefutable(i32);
356
356
let irr = Irrefutable(0);
357
357
358
358
// This fails to compile because the match is irrefutable.
359
359
if let Irrefutable(x) = irr {
360
360
// This body will always be executed.
361
- foo(x);
361
+ // ...
362
362
}
363
363
```
364
364
365
365
Try this instead:
366
366
367
- ```ignore
367
+ ```
368
368
struct Irrefutable(i32);
369
369
let irr = Irrefutable(0);
370
370
371
371
let Irrefutable(x) = irr;
372
- foo( x);
372
+ println!("{}", x);
373
373
```
374
374
"## ,
375
375
@@ -378,7 +378,7 @@ A while-let pattern attempts to match the pattern, and enters the body if the
378
378
match was successful. If the match is irrefutable (when it cannot fail to
379
379
match), use a regular `let`-binding inside a `loop` instead. For instance:
380
380
381
- ```compile_fail
381
+ ```compile_fail,E0165
382
382
struct Irrefutable(i32);
383
383
let irr = Irrefutable(0);
384
384
@@ -455,7 +455,7 @@ that a name will be extracted in all cases. Instead of pattern matching the
455
455
loop variable, consider using a `match` or `if let` inside the loop body. For
456
456
instance:
457
457
458
- ```compile_fail
458
+ ```compile_fail,E0297
459
459
let xs : Vec<Option<i32>> = vec!(Some(1), None);
460
460
461
461
// 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
497
497
exhaustive. For instance, the following would not match any arm if mutable
498
498
borrows were allowed:
499
499
500
- ```compile_fail
500
+ ```compile_fail,E0301
501
501
match Some(()) {
502
502
None => { },
503
503
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
515
515
exhaustive. For instance, the following would not match any arm if assignments
516
516
were allowed:
517
517
518
- ```compile_fail
518
+ ```compile_fail,E0302
519
519
match Some(()) {
520
520
None => { },
521
- option if { option = None; false } { },
521
+ option if { option = None; false } => { },
522
522
Some(_) => { } // When the previous match failed, the option became `None`.
523
523
}
524
524
```
@@ -529,14 +529,18 @@ In certain cases it is possible for sub-bindings to violate memory safety.
529
529
Updates to the borrow checker in a future version of Rust may remove this
530
530
restriction, but for now patterns must be rewritten without sub-bindings.
531
531
532
- ```ignore
533
- // Before.
532
+ Before:
533
+
534
+ ```compile_fail,E0303
534
535
match Some("hi".to_string()) {
535
536
ref op_string_ref @ Some(s) => {},
536
537
None => {},
537
538
}
539
+ ```
540
+
541
+ After:
538
542
539
- // After.
543
+ ```
540
544
match Some("hi".to_string()) {
541
545
Some(ref s) => {
542
546
let op_string_ref = &Some(s);
@@ -556,7 +560,7 @@ This error indicates that the compiler was unable to sensibly evaluate an
556
560
constant expression that had to be evaluated. Attempting to divide by 0
557
561
or causing integer overflow are two ways to induce this error. For example:
558
562
559
- ```compile_fail
563
+ ```compile_fail,E0080
560
564
enum Enum {
561
565
X = (1 << 500),
562
566
Y = (1 / 0)
@@ -575,7 +579,7 @@ E0306: r##"
575
579
In an array literal `[x; N]`, `N` is the number of elements in the array. This
576
580
must be an unsigned integer. Erroneous code example:
577
581
578
- ```compile_fail
582
+ ```compile_fail,E0306
579
583
let x = [0i32; true]; // error: expected positive integer for repeat count,
580
584
// found boolean
581
585
```
0 commit comments