Skip to content

Commit

Permalink
Test or-patterns inside deref patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Apr 8, 2024
1 parent dc59612 commit 91751db
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/ui/pattern/deref-patterns/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ fn ref_mut(val: u32) -> u32 {
*x
}

#[rustfmt::skip]
fn or_and_guard(tuple: (u32, u32)) -> u32 {
let mut sum = 0;
let b = Box::new(tuple);
match b {
deref!((x, _) | (_, x)) if { sum += x; false } => {},
_ => {},
}
sum
}

fn main() {
assert_eq!(simple_vec(vec![1]), 1);
assert_eq!(simple_vec(vec![1, 2]), 202);
Expand All @@ -48,5 +59,6 @@ fn main() {
assert_eq!(nested_vec(vec![vec![1, 2, 3]]), 6);
assert_eq!(nested_vec(vec![vec![], vec![1, 2, 3]]), 1);

assert_eq!(ref_mut(42), 42)
assert_eq!(ref_mut(42), 42);
assert_eq!(or_and_guard((10, 32)), 42);
}

0 comments on commit 91751db

Please sign in to comment.