Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #20972 from A4-Tacks/impl-never-type
Fix not parse never type in inherent impl
Shoyu Vanilla (Flint) 5 months ago
parent 95a0b20 · commit ca83ff3
-rw-r--r--crates/parser/src/grammar/items/traits.rs11
-rw-r--r--crates/parser/test_data/generated/runner.rs4
-rw-r--r--crates/parser/test_data/parser/inline/ok/impl_item_never_type.rast11
-rw-r--r--crates/parser/test_data/parser/inline/ok/impl_item_never_type.rs1
4 files changed, 22 insertions, 5 deletions
diff --git a/crates/parser/src/grammar/items/traits.rs b/crates/parser/src/grammar/items/traits.rs
index c1b1a3fc8a..4e48a4c506 100644
--- a/crates/parser/src/grammar/items/traits.rs
+++ b/crates/parser/src/grammar/items/traits.rs
@@ -54,12 +54,13 @@ pub(super) fn impl_(p: &mut Parser<'_>, m: Marker) {
// impl const Send for S {}
p.eat(T![const]);
- // FIXME: never type
+ // test impl_item_never_type
// impl ! {}
-
- // test impl_item_neg
- // impl !Send for S {}
- p.eat(T![!]);
+ if p.at(T![!]) && !p.nth_at(1, T!['{']) {
+ // test impl_item_neg
+ // impl !Send for S {}
+ p.eat(T![!]);
+ }
impl_type(p);
if p.eat(T![for]) {
impl_type(p);
diff --git a/crates/parser/test_data/generated/runner.rs b/crates/parser/test_data/generated/runner.rs
index 7f5ff0ec07..7b0d32d9d1 100644
--- a/crates/parser/test_data/generated/runner.rs
+++ b/crates/parser/test_data/generated/runner.rs
@@ -322,6 +322,10 @@ mod ok {
#[test]
fn impl_item_neg() { run_and_expect_no_errors("test_data/parser/inline/ok/impl_item_neg.rs"); }
#[test]
+ fn impl_item_never_type() {
+ run_and_expect_no_errors("test_data/parser/inline/ok/impl_item_never_type.rs");
+ }
+ #[test]
fn impl_trait_type() {
run_and_expect_no_errors("test_data/parser/inline/ok/impl_trait_type.rs");
}
diff --git a/crates/parser/test_data/parser/inline/ok/impl_item_never_type.rast b/crates/parser/test_data/parser/inline/ok/impl_item_never_type.rast
new file mode 100644
index 0000000000..fa4575e0ce
--- /dev/null
+++ b/crates/parser/test_data/parser/inline/ok/impl_item_never_type.rast
@@ -0,0 +1,11 @@
+SOURCE_FILE
+ IMPL
+ IMPL_KW "impl"
+ WHITESPACE " "
+ NEVER_TYPE
+ BANG "!"
+ WHITESPACE " "
+ ASSOC_ITEM_LIST
+ L_CURLY "{"
+ R_CURLY "}"
+ WHITESPACE "\n"
diff --git a/crates/parser/test_data/parser/inline/ok/impl_item_never_type.rs b/crates/parser/test_data/parser/inline/ok/impl_item_never_type.rs
new file mode 100644
index 0000000000..ed8057b04f
--- /dev/null
+++ b/crates/parser/test_data/parser/inline/ok/impl_item_never_type.rs
@@ -0,0 +1 @@
+impl ! {}