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/binding/match-vec-alternatives.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/binding/match-vec-alternatives.rs')
-rw-r--r-- | tests/ui/binding/match-vec-alternatives.rs | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/ui/binding/match-vec-alternatives.rs b/tests/ui/binding/match-vec-alternatives.rs new file mode 100644 index 000000000..af95eb95d --- /dev/null +++ b/tests/ui/binding/match-vec-alternatives.rs @@ -0,0 +1,80 @@ +// run-pass + +fn match_vecs<'a, T>(l1: &'a [T], l2: &'a [T]) -> &'static str { + match (l1, l2) { + (&[], &[]) => "both empty", + (&[], &[..]) | (&[..], &[]) => "one empty", + (&[..], &[..]) => "both non-empty" + } +} + +fn match_vecs_cons<'a, T>(l1: &'a [T], l2: &'a [T]) -> &'static str { + match (l1, l2) { + (&[], &[]) => "both empty", + (&[], &[_, ..]) | (&[_, ..], &[]) => "one empty", + (&[_, ..], &[_, ..]) => "both non-empty" + } +} + +fn match_vecs_snoc<'a, T>(l1: &'a [T], l2: &'a [T]) -> &'static str { + match (l1, l2) { + (&[], &[]) => "both empty", + (&[], &[.., _]) | (&[.., _], &[]) => "one empty", + (&[.., _], &[.., _]) => "both non-empty" + } +} + +fn match_nested_vecs_cons<'a, T>(l1: Option<&'a [T]>, l2: Result<&'a [T], ()>) -> &'static str { + match (l1, l2) { + (Some(&[]), Ok(&[])) => "Some(empty), Ok(empty)", + (Some(&[_, ..]), Ok(_)) | (Some(&[_, ..]), Err(())) => "Some(non-empty), any", + (None, Ok(&[])) | (None, Err(())) | (None, Ok(&[_])) => "None, Ok(less than one element)", + (None, Ok(&[_, _, ..])) => "None, Ok(at least two elements)", + _ => "other" + } +} + +fn match_nested_vecs_snoc<'a, T>(l1: Option<&'a [T]>, l2: Result<&'a [T], ()>) -> &'static str { + match (l1, l2) { + (Some(&[]), Ok(&[])) => "Some(empty), Ok(empty)", + (Some(&[.., _]), Ok(_)) | (Some(&[.., _]), Err(())) => "Some(non-empty), any", + (None, Ok(&[])) | (None, Err(())) | (None, Ok(&[_])) => "None, Ok(less than one element)", + (None, Ok(&[.., _, _])) => "None, Ok(at least two elements)", + _ => "other" + } +} + +fn main() { + assert_eq!(match_vecs(&[1, 2], &[2, 3]), "both non-empty"); + assert_eq!(match_vecs(&[], &[1, 2, 3, 4]), "one empty"); + assert_eq!(match_vecs::<usize>(&[], &[]), "both empty"); + assert_eq!(match_vecs(&[1, 2, 3], &[]), "one empty"); + + assert_eq!(match_vecs_cons(&[1, 2], &[2, 3]), "both non-empty"); + assert_eq!(match_vecs_cons(&[], &[1, 2, 3, 4]), "one empty"); + assert_eq!(match_vecs_cons::<usize>(&[], &[]), "both empty"); + assert_eq!(match_vecs_cons(&[1, 2, 3], &[]), "one empty"); + + assert_eq!(match_vecs_snoc(&[1, 2], &[2, 3]), "both non-empty"); + assert_eq!(match_vecs_snoc(&[], &[1, 2, 3, 4]), "one empty"); + assert_eq!(match_vecs_snoc::<usize>(&[], &[]), "both empty"); + assert_eq!(match_vecs_snoc(&[1, 2, 3], &[]), "one empty"); + + assert_eq!(match_nested_vecs_cons(None, Ok::<&[_], ()>(&[4_usize, 2_usize])), + "None, Ok(at least two elements)"); + assert_eq!(match_nested_vecs_cons::<usize>(None, Err(())), "None, Ok(less than one element)"); + assert_eq!(match_nested_vecs_cons::<bool>(Some::<&[_]>(&[]), Ok::<&[_], ()>(&[])), + "Some(empty), Ok(empty)"); + assert_eq!(match_nested_vecs_cons(Some::<&[_]>(&[1]), Err(())), "Some(non-empty), any"); + assert_eq!(match_nested_vecs_cons(Some::<&[_]>(&[(42, ())]), Ok::<&[_], ()>(&[(1, ())])), + "Some(non-empty), any"); + + assert_eq!(match_nested_vecs_snoc(None, Ok::<&[_], ()>(&[4_usize, 2_usize])), + "None, Ok(at least two elements)"); + assert_eq!(match_nested_vecs_snoc::<usize>(None, Err(())), "None, Ok(less than one element)"); + assert_eq!(match_nested_vecs_snoc::<bool>(Some::<&[_]>(&[]), Ok::<&[_], ()>(&[])), + "Some(empty), Ok(empty)"); + assert_eq!(match_nested_vecs_snoc(Some::<&[_]>(&[1]), Err(())), "Some(non-empty), any"); + assert_eq!(match_nested_vecs_snoc(Some::<&[_]>(&[(42, ())]), Ok::<&[_], ()>(&[(1, ())])), + "Some(non-empty), any"); +} |