diff options
author | Marcus Klaas de Vries <[email protected]> | 2019-01-28 22:06:11 +0000 |
---|---|---|
committer | Marcus Klaas de Vries <[email protected]> | 2019-01-28 22:09:14 +0000 |
commit | 3daca3eb4d843199540edfb1092f57f49938d0f6 (patch) | |
tree | 4cdc5c921b024d8b348b73e1a7c3e6a56fc11305 /crates/ra_syntax/src | |
parent | 3f4f50baaa21cb2d0f6c102f1ca521946071a8dc (diff) |
Infer type of match guard
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 6 | ||||
-rw-r--r-- | crates/ra_syntax/src/grammar.ron | 2 | ||||
-rw-r--r-- | crates/ra_syntax/src/grammar/expressions/atom.rs | 18 |
3 files changed, 22 insertions, 4 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 3ace6533c..4f5a96014 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -1981,7 +1981,11 @@ impl ToOwned for MatchGuard { | |||
1981 | } | 1981 | } |
1982 | 1982 | ||
1983 | 1983 | ||
1984 | impl MatchGuard {} | 1984 | impl MatchGuard { |
1985 | pub fn expr(&self) -> Option<&Expr> { | ||
1986 | super::child_opt(self) | ||
1987 | } | ||
1988 | } | ||
1985 | 1989 | ||
1986 | // MethodCallExpr | 1990 | // MethodCallExpr |
1987 | #[derive(Debug, PartialEq, Eq, Hash)] | 1991 | #[derive(Debug, PartialEq, Eq, Hash)] |
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index 85fc79038..e4cad4eb3 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron | |||
@@ -418,7 +418,7 @@ Grammar( | |||
418 | ], | 418 | ], |
419 | collections: [ [ "pats", "Pat" ] ] | 419 | collections: [ [ "pats", "Pat" ] ] |
420 | ), | 420 | ), |
421 | "MatchGuard": (), | 421 | "MatchGuard": (options: ["Expr"]), |
422 | "StructLit": (options: ["Path", "NamedFieldList", ["spread", "Expr"]]), | 422 | "StructLit": (options: ["Path", "NamedFieldList", ["spread", "Expr"]]), |
423 | "NamedFieldList": (collections: [ ["fields", "NamedField"] ]), | 423 | "NamedFieldList": (collections: [ ["fields", "NamedField"] ]), |
424 | "NamedField": (options: ["NameRef", "Expr"]), | 424 | "NamedField": (options: ["NameRef", "Expr"]), |
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 { | |||
360 | while p.eat(PIPE) { | 360 | while p.eat(PIPE) { |
361 | patterns::pattern(p); | 361 | patterns::pattern(p); |
362 | } | 362 | } |
363 | if p.eat(IF_KW) { | 363 | if p.at(IF_KW) { |
364 | expr(p); | 364 | match_guard(p); |
365 | } | 365 | } |
366 | p.expect(FAT_ARROW); | 366 | p.expect(FAT_ARROW); |
367 | let ret = expr_stmt(p); | 367 | let ret = expr_stmt(p); |
@@ -369,6 +369,20 @@ fn match_arm(p: &mut Parser) -> BlockLike { | |||
369 | ret | 369 | ret |
370 | } | 370 | } |
371 | 371 | ||
372 | // test match_guard | ||
373 | // fn foo() { | ||
374 | // match () { | ||
375 | // _ if foo => (), | ||
376 | // } | ||
377 | // } | ||
378 | fn match_guard(p: &mut Parser) -> CompletedMarker { | ||
379 | assert!(p.at(IF_KW)); | ||
380 | let m = p.start(); | ||
381 | p.bump(); | ||
382 | expr(p); | ||
383 | m.complete(p, MATCH_GUARD) | ||
384 | } | ||
385 | |||
372 | // test block_expr | 386 | // test block_expr |
373 | // fn foo() { | 387 | // fn foo() { |
374 | // {}; | 388 | // {}; |