Skip to content

Commit cccdd2c

Browse files
committed
Add type annotation pattern
1 parent b428a1c commit cccdd2c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ macro_rules! __if_chain {
152152
$($pat)|+ => __if_chain! { @expand $other $($tt)+ }
153153
}
154154
};
155+
(@expand $other:block let $ident:ident:$ty:ty = $expr:expr; $($tt:tt)+) => {
156+
let $ident:$ty = $expr;
157+
__if_chain! { @expand $other $($tt)+ }
158+
};
155159
(@expand $other:block if let $($pat:pat)|+ = $expr:expr; $($tt:tt)+) => {
156160
match $expr {
157161
$($pat)|+ => __if_chain! { @expand $other $($tt)+ },
@@ -236,4 +240,17 @@ mod tests {
236240
else { panic!(); }
237241
}
238242
}
243+
244+
#[test]
245+
fn let_type_annotation_patterns() {
246+
let mut x: u32 = 1;
247+
if_chain! {
248+
if x > 0;
249+
let y: u32 = 2;
250+
251+
then { x += y; }
252+
else { x += 1; }
253+
};
254+
assert_eq!(x, 3);
255+
}
239256
}

0 commit comments

Comments
 (0)