Skip to content

Commit bde3cbd

Browse files
authored
Rollup merge of #111023 - tmiasko:multi-variant-capture, r=compiler-errors
Test precise capture with a multi-variant enum and exhaustive patterns Add test checking that it is possible to capture fields of a multi-variant enum, when remaining variants are visibly uninhabited (under the `exhaustive_patterns` feature gate).
2 parents 07726e3 + b855308 commit bde3cbd

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Test precise capture of a multi-variant enum (when remaining variants are
2+
// visibly uninhabited).
3+
// edition:2021
4+
// run-pass
5+
#![feature(exhaustive_patterns)]
6+
#![feature(never_type)]
7+
8+
pub fn main() {
9+
let mut r = Result::<!, (u32, u32)>::Err((0, 0));
10+
let mut f = || {
11+
let Err((ref mut a, _)) = r;
12+
*a = 1;
13+
};
14+
let mut g = || {
15+
let Err((_, ref mut b)) = r;
16+
*b = 2;
17+
};
18+
f();
19+
g();
20+
assert_eq!(r, Err((1, 2)));
21+
}

0 commit comments

Comments
 (0)