diff --git a/crates/hir-def/src/macro_expansion_tests/mbe.rs b/crates/hir-def/src/macro_expansion_tests/mbe.rs index c5c26e26bc..4058159cef 100644 --- a/crates/hir-def/src/macro_expansion_tests/mbe.rs +++ b/crates/hir-def/src/macro_expansion_tests/mbe.rs @@ -1883,3 +1883,41 @@ fn test() { "#]], ); } + +#[test] +fn test_pat_fragment_eof_17441() { + check( + r#" +macro_rules! matches { + ($expression:expr, $pattern:pat $(if $guard:expr)? ) => { + match $expression { + $pattern $(if $guard)? => true, + _ => false + } + }; +} +fn f() { + matches!(0, 10..); + matches!(0, 10.. if true); +} + "#, + expect![[r#" +macro_rules! matches { + ($expression:expr, $pattern:pat $(if $guard:expr)? ) => { + match $expression { + $pattern $(if $guard)? => true, + _ => false + } + }; +} +fn f() { + match 0 { + 10.. =>true , _=>false + }; + match 0 { + 10..if true =>true , _=>false + }; +} + "#]], + ); +} diff --git a/crates/parser/src/grammar/patterns.rs b/crates/parser/src/grammar/patterns.rs index eff6b66404..882c243b0c 100644 --- a/crates/parser/src/grammar/patterns.rs +++ b/crates/parser/src/grammar/patterns.rs @@ -181,7 +181,7 @@ fn pattern_single_r(p: &mut Parser<'_>, recovery_set: TokenSet) { // ^ if matches!( p.current(), - T![=] | T![,] | T![:] | T![')'] | T!['}'] | T![']'] | T![if] + T![=] | T![,] | T![:] | T![')'] | T!['}'] | T![']'] | T![if] | EOF ) { // test half_open_range_pat // fn f() {