Rollup merge of #104035 - m-ou-se:weird-expr-closure-match, r=compiler-errors

Add 'closure match' test to weird-exprs.rs.

Having fun with patterns that look like closures.
This commit is contained in:
Matthias Krüger 2022-11-06 08:35:28 +01:00 committed by GitHub
commit 619add319f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,6 +8,7 @@
#![allow(unreachable_code)] #![allow(unreachable_code)]
#![allow(unused_braces, unused_must_use, unused_parens)] #![allow(unused_braces, unused_must_use, unused_parens)]
#![allow(uncommon_codepoints, confusable_idents)] #![allow(uncommon_codepoints, confusable_idents)]
#![allow(unreachable_patterns)]
#![recursion_limit = "256"] #![recursion_limit = "256"]
@ -194,6 +195,15 @@ fn bathroom_stall() {
assert_eq!(i, 13); assert_eq!(i, 13);
} }
fn closure_matching() {
let x = |_| Some(1);
let (|x| x) = match x(..) {
|_| Some(2) => |_| Some(3),
|_| _ => unreachable!(),
};
assert!(matches!(x(..), |_| Some(4)));
}
pub fn main() { pub fn main() {
strange(); strange();
funny(); funny();
@ -216,4 +226,5 @@ pub fn main() {
𝚌𝚘𝚗𝚝𝚒𝚗𝚞𝚎(); 𝚌𝚘𝚗𝚝𝚒𝚗𝚞𝚎();
function(); function();
bathroom_stall(); bathroom_stall();
closure_matching();
} }