Skip to content

Commit 7622338

Browse files
committed
Allow Rust matches! macro
1 parent dd9e781 commit 7622338

File tree

1 file changed

+18
-0
lines changed
  • crates/parser/src/grammar/expressions

1 file changed

+18
-0
lines changed

crates/parser/src/grammar/expressions/atom.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ pub(super) const ATOM_EXPR_FIRST: TokenSet =
6969
T![forall],
7070
T![exists],
7171
T![choose],
72+
T![matches],
7273
]));
7374

7475
pub(super) const EXPR_RECOVERY_SET: TokenSet = TokenSet::new(&[T![')'], T![']']]);
@@ -90,6 +91,23 @@ pub(super) fn atom_expr(
9091
if p.at_contextual_kw(T![proof_fn]) {
9192
return Some((closure_expr(p), BlockLike::NotBlock));
9293
}
94+
// Special-case `matches!` as a macro call.
95+
// `matches` is a first-class keyword for the Verus postfix operator (`x matches Pattern`),
96+
// but `matches!` is a standard Rust macro. When followed by `!`, treat it as a macro call.
97+
if p.at(T![matches]) && p.nth_at(1, T![!]) {
98+
let m = p.start();
99+
let macro_call = p.start();
100+
let path = p.start();
101+
let path_segment = p.start();
102+
let name_ref = p.start();
103+
p.bump_remap(IDENT);
104+
name_ref.complete(p, NAME_REF);
105+
path_segment.complete(p, PATH_SEGMENT);
106+
path.complete(p, PATH);
107+
let block_like = items::macro_call_after_excl(p);
108+
macro_call.complete(p, MACRO_CALL);
109+
return Some((m.complete(p, MACRO_EXPR), block_like));
110+
}
93111
if paths::is_path_start(p) {
94112
return Some(path_expr(p, r));
95113
}

0 commit comments

Comments
 (0)