LIFETIME_IDENT,
]));
-const EXPR_RECOVERY_SET: TokenSet = TokenSet::new(&[LET_KW, R_DOLLAR]);
+const EXPR_RECOVERY_SET: TokenSet = TokenSet::new(&[T![let], R_DOLLAR]);
pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMarker, BlockLike)> {
if let Some(m) = literal(p) {
// test labeled_block
// fn f() { 'label: {}; }
T!['{'] => {
- block_expr(p);
- m.complete(p, EFFECT_EXPR)
+ stmt_list(p);
+ m.complete(p, BLOCK_EXPR)
}
_ => {
// test_err misplaced_label_err
let m = p.start();
p.bump(T![async]);
p.eat(T![move]);
- block_expr(p);
- m.complete(p, EFFECT_EXPR)
+ stmt_list(p);
+ m.complete(p, BLOCK_EXPR)
}
T![match] => match_expr(p),
// test unsafe_block
T![unsafe] if la == T!['{'] => {
let m = p.start();
p.bump(T![unsafe]);
- block_expr(p);
- m.complete(p, EFFECT_EXPR)
+ stmt_list(p);
+ m.complete(p, BLOCK_EXPR)
}
// test const_block
// fn f() { const { } }
T![const] if la == T!['{'] => {
let m = p.start();
p.bump(T![const]);
- block_expr(p);
- m.complete(p, EFFECT_EXPR)
+ stmt_list(p);
+ m.complete(p, BLOCK_EXPR)
}
T!['{'] => {
// test for_range_from
// break;
// }
// }
- block_expr_unchecked(p)
+ let m = p.start();
+ stmt_list(p);
+ m.complete(p, BLOCK_EXPR)
}
T![return] => return_expr(p),
T![yield] => yield_expr(p),
}
};
let blocklike = match done.kind() {
- IF_EXPR | WHILE_EXPR | FOR_EXPR | LOOP_EXPR | MATCH_EXPR | BLOCK_EXPR | EFFECT_EXPR => {
- BlockLike::Block
- }
+ IF_EXPR | WHILE_EXPR | FOR_EXPR | LOOP_EXPR | MATCH_EXPR | BLOCK_EXPR => BlockLike::Block,
_ => BlockLike::NotBlock,
};
Some((done, blocklike))
// test tuple_attrs
// const A: (i64, i64) = (1, #[cfg(test)] 2);
- if !expr_with_attrs(p) {
+ if !expr(p) {
break;
}
// test array_attrs
// const A: &[i64] = &[1, #[cfg(test)] 2];
- if !expr_with_attrs(p) {
+ if !expr(p) {
break;
}
// test lambda_ret_block
// fn main() { || -> i32 { 92 }(); }
block_expr(p);
+ } else if p.at_ts(EXPR_FIRST) {
+ expr(p);
} else {
- if p.at_ts(EXPR_FIRST) {
- expr(p);
- } else {
- p.error("expected expression");
- }
+ p.error("expected expression");
}
m.complete(p, CLOSURE_EXPR)
}
if p.at(T!['{']) {
match_arm_list(p);
} else {
- p.error("expected `{`")
+ p.error("expected `{`");
}
m.complete(p, MATCH_EXPR)
}
error_block(p, "expected match arm");
continue;
}
-
- // test match_arms_commas
- // fn foo() {
- // match () {
- // _ => (),
- // _ => {}
- // _ => ()
- // }
- // }
- if match_arm(p).is_block() {
- p.eat(T![,]);
- } else if !p.at(T!['}']) {
- p.expect(T![,]);
- }
+ match_arm(p);
}
p.expect(T!['}']);
m.complete(p, MATCH_ARM_LIST);
// | X => (),
// };
// }
-fn match_arm(p: &mut Parser) -> BlockLike {
+fn match_arm(p: &mut Parser) {
let m = p.start();
// test match_arms_outer_attributes
// fn foo() {
match_guard(p);
}
p.expect(T![=>]);
- let blocklike = expr_stmt(p).1;
+ let blocklike = match expr_stmt(p, None) {
+ Some((_, blocklike)) => blocklike,
+ None => BlockLike::NotBlock,
+ };
+
+ // test match_arms_commas
+ // fn foo() {
+ // match () {
+ // _ => (),
+ // _ => {}
+ // _ => ()
+ // }
+ // }
+ if !p.eat(T![,]) && !blocklike.is_block() && !p.at(T!['}']) {
+ p.error("expected `,`");
+ }
m.complete(p, MATCH_ARM);
- blocklike
}
// test match_guard
// fn foo() {
// match () {
// _ if foo => (),
+// _ if let foo = bar => (),
// }
// }
fn match_guard(p: &mut Parser) -> CompletedMarker {
assert!(p.at(T![if]));
let m = p.start();
p.bump(T![if]);
+ if p.eat(T![let]) {
+ patterns::pattern_top(p);
+ p.expect(T![=]);
+ }
expr(p);
m.complete(p, MATCH_GUARD)
}
p.error("expected a block");
return;
}
- block_expr_unchecked(p);
+ let m = p.start();
+ stmt_list(p);
+ m.complete(p, BLOCK_EXPR);
}
-fn block_expr_unchecked(p: &mut Parser) -> CompletedMarker {
+fn stmt_list(p: &mut Parser) -> CompletedMarker {
assert!(p.at(T!['{']));
let m = p.start();
p.bump(T!['{']);
expr_block_contents(p);
p.expect(T!['}']);
- m.complete(p, BLOCK_EXPR)
+ m.complete(p, STMT_LIST)
}
// test return_expr
}
p.bump(T![try]);
- block_expr(p);
- m.complete(p, EFFECT_EXPR)
+ if p.at(T!['{']) {
+ stmt_list(p);
+ } else {
+ p.error("expected a block");
+ }
+ m.complete(p, BLOCK_EXPR)
}
// test box_expr
assert!(p.at(L_DOLLAR));
let m = p.start();
p.bump(L_DOLLAR);
- let (completed, _is_block) =
- expr_bp(p, Restrictions { forbid_structs: false, prefer_stmt: false }, 1);
+ let expr = expr_bp(p, None, Restrictions { forbid_structs: false, prefer_stmt: false }, 1);
- match (completed, p.current()) {
- (Some(it), R_DOLLAR) => {
+ match (expr, p.current()) {
+ (Some((cm, _)), R_DOLLAR) => {
p.bump(R_DOLLAR);
+ // FIXME: this leaves the dollar hanging in the air...
m.abandon(p);
- it
+ cm
}
_ => {
while !p.at(R_DOLLAR) {
- p.bump_any()
+ p.bump_any();
}
p.bump(R_DOLLAR);
m.complete(p, ERROR)