Infer type of match guard
This commit is contained in:
@@ -1981,7 +1981,11 @@ impl ToOwned for MatchGuard {
|
||||
}
|
||||
|
||||
|
||||
impl MatchGuard {}
|
||||
impl MatchGuard {
|
||||
pub fn expr(&self) -> Option<&Expr> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
}
|
||||
|
||||
// MethodCallExpr
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
|
||||
@@ -418,7 +418,7 @@ Grammar(
|
||||
],
|
||||
collections: [ [ "pats", "Pat" ] ]
|
||||
),
|
||||
"MatchGuard": (),
|
||||
"MatchGuard": (options: ["Expr"]),
|
||||
"StructLit": (options: ["Path", "NamedFieldList", ["spread", "Expr"]]),
|
||||
"NamedFieldList": (collections: [ ["fields", "NamedField"] ]),
|
||||
"NamedField": (options: ["NameRef", "Expr"]),
|
||||
|
||||
@@ -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() {
|
||||
// {};
|
||||
|
||||
Reference in New Issue
Block a user