Skip to content

Commit f9451c3

Browse files
committed
Mention refutable matching on variant types
1 parent 508b43b commit f9451c3

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

text/0000-enum-variant-types.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,22 @@ enum Sum { A(u32), B, C }
6464

6565
fn print_A(a: Sum::A) {
6666
let A(x) = a;
67-
println!("a is {}", a);
67+
println!("a is {}", x);
6868
}
6969
```
70+
However, in order to be backwards-compatible with existing handling of variants as enums, matches on
71+
variant types will permit (and simply ignore) arms that correspond to other variants:
72+
73+
```rust
74+
let a = Sum::A(20);
75+
76+
match a {
77+
A(x) => println!("a is {}", x),
78+
B => println!("a is B"), // ok, but unreachable
79+
C => println!("a is C"), // ok, but unreachable
80+
}
81+
```
82+
7083
- You may project the fields of a variant type, similarly to tuples or structs:
7184

7285
```rust

0 commit comments

Comments
 (0)