From b855308521a4d3c508a722e970c4de1829651232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Sun, 30 Apr 2023 00:00:00 +0000 Subject: [PATCH] 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). --- .../run_pass/multivariant.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/ui/closures/2229_closure_analysis/run_pass/multivariant.rs diff --git a/tests/ui/closures/2229_closure_analysis/run_pass/multivariant.rs b/tests/ui/closures/2229_closure_analysis/run_pass/multivariant.rs new file mode 100644 index 00000000000..72652ef6034 --- /dev/null +++ b/tests/ui/closures/2229_closure_analysis/run_pass/multivariant.rs @@ -0,0 +1,21 @@ +// Test precise capture of a multi-variant enum (when remaining variants are +// visibly uninhabited). +// edition:2021 +// run-pass +#![feature(exhaustive_patterns)] +#![feature(never_type)] + +pub fn main() { + let mut r = Result::::Err((0, 0)); + let mut f = || { + let Err((ref mut a, _)) = r; + *a = 1; + }; + let mut g = || { + let Err((_, ref mut b)) = r; + *b = 2; + }; + f(); + g(); + assert_eq!(r, Err((1, 2))); +}