From 3daca3eb4d843199540edfb1092f57f49938d0f6 Mon Sep 17 00:00:00 2001 From: Marcus Klaas de Vries Date: Mon, 28 Jan 2019 23:06:11 +0100 Subject: Infer type of match guard --- crates/ra_syntax/src/grammar/expressions/atom.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'crates/ra_syntax/src/grammar/expressions') diff --git a/crates/ra_syntax/src/grammar/expressions/atom.rs b/crates/ra_syntax/src/grammar/expressions/atom.rs index 6d6d89f70..600774afd 100644 --- a/crates/ra_syntax/src/grammar/expressions/atom.rs +++ b/crates/ra_syntax/src/grammar/expressions/atom.rs @@ -360,8 +360,8 @@ fn match_arm(p: &mut Parser) -> BlockLike { while p.eat(PIPE) { patterns::pattern(p); } - if p.eat(IF_KW) { - expr(p); + if p.at(IF_KW) { + match_guard(p); } p.expect(FAT_ARROW); let ret = expr_stmt(p); @@ -369,6 +369,20 @@ fn match_arm(p: &mut Parser) -> BlockLike { ret } +// test match_guard +// fn foo() { +// match () { +// _ if foo => (), +// } +// } +fn match_guard(p: &mut Parser) -> CompletedMarker { + assert!(p.at(IF_KW)); + let m = p.start(); + p.bump(); + expr(p); + m.complete(p, MATCH_GUARD) +} + // test block_expr // fn foo() { // {}; -- cgit v1.2.3