From cacb32d88aa27b8e671173571325756890941b06 Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Mon, 24 Sep 2018 11:42:01 +0800 Subject: reject impl keyword in impl header --- crates/ra_syntax/src/grammar/items/traits.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'crates/ra_syntax/src/grammar') diff --git a/crates/ra_syntax/src/grammar/items/traits.rs b/crates/ra_syntax/src/grammar/items/traits.rs index c21cfb1a9..25b6cb66b 100644 --- a/crates/ra_syntax/src/grammar/items/traits.rs +++ b/crates/ra_syntax/src/grammar/items/traits.rs @@ -54,8 +54,16 @@ pub(super) fn impl_item(p: &mut Parser) { // test impl_item_neg // impl !Send for X {} - p.eat(EXCL); - types::type_(p); + if p.at(IMPL_KW) { + p.error("expected type"); + } else { + p.eat(EXCL); + if p.at(IMPL_KW) { + p.error("expected type"); + } else { + types::type_(p); + } + } if p.eat(FOR_KW) { types::type_(p); } -- cgit v1.2.3 From edf1cc3582a842837d64fa6ec08df00c028521f9 Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Tue, 25 Sep 2018 22:00:43 +0800 Subject: parse impl type --- crates/ra_syntax/src/grammar/items/traits.rs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'crates/ra_syntax/src/grammar') diff --git a/crates/ra_syntax/src/grammar/items/traits.rs b/crates/ra_syntax/src/grammar/items/traits.rs index 25b6cb66b..62ab877fc 100644 --- a/crates/ra_syntax/src/grammar/items/traits.rs +++ b/crates/ra_syntax/src/grammar/items/traits.rs @@ -54,16 +54,8 @@ pub(super) fn impl_item(p: &mut Parser) { // test impl_item_neg // impl !Send for X {} - if p.at(IMPL_KW) { - p.error("expected type"); - } else { - p.eat(EXCL); - if p.at(IMPL_KW) { - p.error("expected type"); - } else { - types::type_(p); - } - } + p.eat(EXCL); + impl_type(p); if p.eat(FOR_KW) { types::type_(p); } @@ -123,3 +115,17 @@ fn choose_type_params_over_qpath(p: &Parser) -> bool { (p.nth(1) == LIFETIME || p.nth(1) == IDENT) && (p.nth(2) == R_ANGLE || p.nth(2) == COMMA || p.nth(2) == COLON || p.nth(2) == EQ) } + +// impl Type {} +// ^^^^ +// impl Trait for T {} +// ^^^^^ +pub(crate) fn impl_type(p: &mut Parser) { + if p.at(IMPL_KW) { + p.error("expected trait or type"); + return; + } + types::type_(p); +} + + -- cgit v1.2.3 From 8b710e95353d9f840f78645c9593a66adb0636b6 Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Wed, 26 Sep 2018 10:01:42 +0800 Subject: generate testsuite for impl_type --- crates/ra_syntax/src/grammar/items/traits.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/ra_syntax/src/grammar') diff --git a/crates/ra_syntax/src/grammar/items/traits.rs b/crates/ra_syntax/src/grammar/items/traits.rs index 62ab877fc..5dfdb470c 100644 --- a/crates/ra_syntax/src/grammar/items/traits.rs +++ b/crates/ra_syntax/src/grammar/items/traits.rs @@ -57,7 +57,7 @@ pub(super) fn impl_item(p: &mut Parser) { p.eat(EXCL); impl_type(p); if p.eat(FOR_KW) { - types::type_(p); + impl_type(p); } type_params::opt_where_clause(p); if p.at(L_CURLY) { @@ -116,10 +116,11 @@ fn choose_type_params_over_qpath(p: &Parser) -> bool { && (p.nth(2) == R_ANGLE || p.nth(2) == COMMA || p.nth(2) == COLON || p.nth(2) == EQ) } +// test impl_type // impl Type {} -// ^^^^ -// impl Trait for T {} -// ^^^^^ +// impl Trait1 for T {} +// impl impl NotType {} +// impl Trait2 for impl NotType {} pub(crate) fn impl_type(p: &mut Parser) { if p.at(IMPL_KW) { p.error("expected trait or type"); @@ -128,4 +129,3 @@ pub(crate) fn impl_type(p: &mut Parser) { types::type_(p); } - -- cgit v1.2.3