Skip to content

Commit a6f17f7

Browse files
committed
minor: more readable code
1 parent 9abea74 commit a6f17f7

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

crates/parser/src/grammar/expressions.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
mod atom;
22

3+
use super::*;
4+
35
pub(crate) use self::atom::{block_expr, match_arm_list};
46
pub(super) use self::atom::{literal, LITERAL_FIRST};
5-
use super::*;
67

78
pub(super) enum StmtWithSemi {
89
Yes,
@@ -47,11 +48,6 @@ fn expr_no_struct(p: &mut Parser) {
4748
expr_bp(p, r, 1);
4849
}
4950

50-
fn is_expr_stmt_attr_allowed(kind: SyntaxKind) -> bool {
51-
let forbid = matches!(kind, BIN_EXPR | RANGE_EXPR);
52-
!forbid
53-
}
54-
5551
pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi, prefer_expr: bool) {
5652
let m = p.start();
5753
// test attr_on_expr_stmt
@@ -79,13 +75,15 @@ pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi, prefer_expr: bool) {
7975
let (cm, blocklike) = expr_stmt(p);
8076
let kind = cm.as_ref().map(|cm| cm.kind()).unwrap_or(ERROR);
8177

82-
if has_attrs && !is_expr_stmt_attr_allowed(kind) {
83-
// test_err attr_on_expr_not_allowed
84-
// fn foo() {
85-
// #[A] 1 + 2;
86-
// #[B] if true {};
87-
// }
88-
p.error(format!("attributes are not allowed on {:?}", kind));
78+
if has_attrs {
79+
if matches!(kind, BIN_EXPR | RANGE_EXPR) {
80+
// test_err attr_on_expr_not_allowed
81+
// fn foo() {
82+
// #[A] 1 + 2;
83+
// #[B] if true {};
84+
// }
85+
p.error(format!("attributes are not allowed on {:?}", kind));
86+
}
8987
}
9088

9189
if p.at(T!['}']) || (prefer_expr && p.at(EOF)) {

0 commit comments

Comments
 (0)