diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
commit | 64d98f8ee037282c35007b64c2649055c56af1db (patch) | |
tree | 5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/or-patterns/consistent-bindings.rs | |
parent | Adding debian version 1.67.1+dfsg1-1. (diff) | |
download | rustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/or-patterns/consistent-bindings.rs')
-rw-r--r-- | tests/ui/or-patterns/consistent-bindings.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/ui/or-patterns/consistent-bindings.rs b/tests/ui/or-patterns/consistent-bindings.rs new file mode 100644 index 000000000..ecae1d8a2 --- /dev/null +++ b/tests/ui/or-patterns/consistent-bindings.rs @@ -0,0 +1,39 @@ +// Check that or-patterns with consistent bindings across arms are allowed. + +// edition:2018 + +// check-pass + +fn main() { + // One level: + let (Ok(a) | Err(a)) = Ok(0); + let (Ok(ref a) | Err(ref a)) = Ok(0); + let (Ok(ref mut a) | Err(ref mut a)) = Ok(0); + + // Two levels: + enum Tri<S, T, U> { + V1(S), + V2(T), + V3(U), + } + use Tri::*; + + let (Ok((V1(a) | V2(a) | V3(a), b)) | Err(Ok((a, b)) | Err((a, b)))): Result<_, Result<_, _>> = + Ok((V1(1), 1)); + + let (Ok((V1(a) | V2(a) | V3(a), ref b)) | Err(Ok((a, ref b)) | Err((a, ref b)))): Result< + _, + Result<_, _>, + > = Ok((V1(1), 1)); + + // Three levels: + let ( + a, + Err((ref mut b, ref c, d)) + | Ok(( + Ok(V1((ref c, d)) | V2((d, ref c)) | V3((ref c, Ok((_, d)) | Err((d, _))))) + | Err((ref c, d)), + ref mut b, + )), + ): (_, Result<_, _>) = (1, Ok((Ok(V3((1, Ok::<_, (i32, i32)>((1, 1))))), 1))); +} |