diff options
| author | bors <bors@rust-lang.org> | 2024-06-17 17:44:35 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-06-17 17:44:35 +0000 |
| commit | 6891225afa15b2ab1091e0a7e17be9fe1808c53e (patch) | |
| tree | 2ac3f405e3cd3484c5aa13a0ce37879266240087 | |
| parent | 5d5c29824cac88f2c05aff951acdc726abb2ba58 (diff) | |
| parent | d2f975a06005d6b68cf9c005bd0f9c86ad8074c6 (diff) | |
| download | rust-6891225afa15b2ab1091e0a7e17be9fe1808c53e.tar.gz rust-6891225afa15b2ab1091e0a7e17be9fe1808c53e.zip | |
Auto merge of #17442 - Veykril:pat-eof, r=Veykril
fix: Fix pat fragment parsers choking on <eoi> Fixes https://github.com/rust-lang/rust-analyzer/issues/17441
| -rw-r--r-- | src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/mbe.rs | 38 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/crates/parser/src/grammar/patterns.rs | 2 |
2 files changed, 39 insertions, 1 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/mbe.rs b/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/mbe.rs index c5c26e26bc0..4058159cefe 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/mbe.rs +++ b/src/tools/rust-analyzer/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/src/tools/rust-analyzer/crates/parser/src/grammar/patterns.rs b/src/tools/rust-analyzer/crates/parser/src/grammar/patterns.rs index eff6b664049..882c243b0cd 100644 --- a/src/tools/rust-analyzer/crates/parser/src/grammar/patterns.rs +++ b/src/tools/rust-analyzer/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() { |
