From fb632c747d953d615575850477d4662802be320f Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Wed, 3 Jun 2020 15:21:47 -0400 Subject: Parse default unsafe & default const --- crates/ra_parser/src/grammar/items.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'crates/ra_parser') diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs index 67a924de5..41f8bb0b6 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs @@ -118,7 +118,15 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul && p.at_contextual_kw("default") && (match p.nth(1) { T![impl] => true, - T![fn] | T![type] => { + T![unsafe] => { + if T![impl] == p.nth(2) { + p.bump_remap(T![default]); + p.bump_remap(T![unsafe]); + has_mods = true; + } + false + } + T![fn] | T![type] | T![const] => { if let ItemFlavor::Mod = flavor { true } else { @@ -187,6 +195,9 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul // test default_impl // default impl Foo {} + // test default_unsafe_impl + // default unsafe impl Foo {} + // test_err default_fn_type // trait T { // default type T = Bar; @@ -199,6 +210,19 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul // default fn foo() {} // } + // test_err default_const + // trait T { + // default const f: u8 = 0; + // } + + // test default_const + // impl T for Foo { + // default const f: u8 = 0; + // } + T![const] => { + consts::const_def(p, m); + } + // test unsafe_default_impl // unsafe default impl Foo {} T![impl] => { -- cgit v1.2.3 From 3ec2dcfc0d7ea7d9fb9c499616e9eca06b5c865b Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Thu, 4 Jun 2020 13:00:21 -0400 Subject: Address review --- crates/ra_parser/src/grammar/items.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'crates/ra_parser') diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs index 41f8bb0b6..0d3568e5f 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs @@ -119,9 +119,11 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul && (match p.nth(1) { T![impl] => true, T![unsafe] => { - if T![impl] == p.nth(2) { + // test default_unsafe_impl + // default unsafe impl Foo {} + if p.nth(2) == T![impl] { p.bump_remap(T![default]); - p.bump_remap(T![unsafe]); + p.bump(T![unsafe]); has_mods = true; } false @@ -195,9 +197,6 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul // test default_impl // default impl Foo {} - // test default_unsafe_impl - // default unsafe impl Foo {} - // test_err default_fn_type // trait T { // default type T = Bar; -- cgit v1.2.3 From c4fd46398132a409d7947141094d7301c0f0af73 Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Thu, 4 Jun 2020 13:06:26 -0400 Subject: Move default const test out of line --- crates/ra_parser/src/grammar/items.rs | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'crates/ra_parser') diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs index 0d3568e5f..9c14b954a 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs @@ -208,16 +208,6 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul // default type T = Bar; // default fn foo() {} // } - - // test_err default_const - // trait T { - // default const f: u8 = 0; - // } - - // test default_const - // impl T for Foo { - // default const f: u8 = 0; - // } T![const] => { consts::const_def(p, m); } -- cgit v1.2.3