minor: more readable code

This commit is contained in:
Aleksey Kladov 2021-09-25 13:27:53 +03:00
parent 9abea7492e
commit a6f17f7436

View file

@ -1,8 +1,9 @@
mod atom; mod atom;
use super::*;
pub(crate) use self::atom::{block_expr, match_arm_list}; pub(crate) use self::atom::{block_expr, match_arm_list};
pub(super) use self::atom::{literal, LITERAL_FIRST}; pub(super) use self::atom::{literal, LITERAL_FIRST};
use super::*;
pub(super) enum StmtWithSemi { pub(super) enum StmtWithSemi {
Yes, Yes,
@ -47,11 +48,6 @@ fn expr_no_struct(p: &mut Parser) {
expr_bp(p, r, 1); expr_bp(p, r, 1);
} }
fn is_expr_stmt_attr_allowed(kind: SyntaxKind) -> bool {
let forbid = matches!(kind, BIN_EXPR | RANGE_EXPR);
!forbid
}
pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi, prefer_expr: bool) { pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi, prefer_expr: bool) {
let m = p.start(); let m = p.start();
// test attr_on_expr_stmt // test attr_on_expr_stmt
@ -79,13 +75,15 @@ pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi, prefer_expr: bool) {
let (cm, blocklike) = expr_stmt(p); let (cm, blocklike) = expr_stmt(p);
let kind = cm.as_ref().map(|cm| cm.kind()).unwrap_or(ERROR); let kind = cm.as_ref().map(|cm| cm.kind()).unwrap_or(ERROR);
if has_attrs && !is_expr_stmt_attr_allowed(kind) { if has_attrs {
// test_err attr_on_expr_not_allowed if matches!(kind, BIN_EXPR | RANGE_EXPR) {
// fn foo() { // test_err attr_on_expr_not_allowed
// #[A] 1 + 2; // fn foo() {
// #[B] if true {}; // #[A] 1 + 2;
// } // #[B] if true {};
p.error(format!("attributes are not allowed on {:?}", kind)); // }
p.error(format!("attributes are not allowed on {:?}", kind));
}
} }
if p.at(T!['}']) || (prefer_expr && p.at(EOF)) { if p.at(T!['}']) || (prefer_expr && p.at(EOF)) {