From 8aba6bfef511acb2c5dc968bd75ef291c2ad3425 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 12 Aug 2020 10:14:08 +0200 Subject: Simplify --- crates/ra_parser/src/parser.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'crates/ra_parser') diff --git a/crates/ra_parser/src/parser.rs b/crates/ra_parser/src/parser.rs index d797f2cc9..d2487acc3 100644 --- a/crates/ra_parser/src/parser.rs +++ b/crates/ra_parser/src/parser.rs @@ -269,8 +269,8 @@ impl Marker { pub(crate) fn complete(mut self, p: &mut Parser, kind: SyntaxKind) -> CompletedMarker { self.bomb.defuse(); let idx = self.pos as usize; - match p.events[idx] { - Event::Start { kind: ref mut slot, .. } => { + match &mut p.events[idx] { + Event::Start { kind: slot, .. } => { *slot = kind; } _ => unreachable!(), @@ -320,8 +320,8 @@ impl CompletedMarker { pub(crate) fn precede(self, p: &mut Parser) -> Marker { let new_pos = p.start(); let idx = self.start_pos as usize; - match p.events[idx] { - Event::Start { ref mut forward_parent, .. } => { + match &mut p.events[idx] { + Event::Start { forward_parent, .. } => { *forward_parent = Some(new_pos.pos - self.start_pos); } _ => unreachable!(), @@ -333,12 +333,12 @@ impl CompletedMarker { pub(crate) fn undo_completion(self, p: &mut Parser) -> Marker { let start_idx = self.start_pos as usize; let finish_idx = self.finish_pos as usize; - match p.events[start_idx] { - Event::Start { ref mut kind, forward_parent: None } => *kind = TOMBSTONE, + match &mut p.events[start_idx] { + Event::Start { kind, forward_parent: None } => *kind = TOMBSTONE, _ => unreachable!(), } - match p.events[finish_idx] { - ref mut slot @ Event::Finish => *slot = Event::tombstone(), + match &mut p.events[finish_idx] { + slot @ Event::Finish => *slot = Event::tombstone(), _ => unreachable!(), } Marker::new(self.start_pos) -- cgit v1.2.3 From 49af51129b943784a3e6dbe33b05b6f683965b28 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 12 Aug 2020 12:45:38 +0200 Subject: Deny clippy --- crates/ra_parser/src/grammar/expressions.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'crates/ra_parser') diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index e1c25a838..51eaf7af6 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs @@ -509,7 +509,6 @@ fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { // x.1i32; // x.0x01; // } -#[allow(clippy::if_same_then_else)] fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { assert!(p.at(T![.])); let m = lhs.precede(p); -- cgit v1.2.3 From f73a6419d43b21d07b7ee5d3804bdd586ee8036f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 12 Aug 2020 14:26:36 +0200 Subject: Allow default everywhere closes #5681 --- crates/ra_parser/src/grammar.rs | 2 +- crates/ra_parser/src/grammar/expressions.rs | 2 +- crates/ra_parser/src/grammar/items.rs | 50 ++++++++++------------------ crates/ra_parser/src/grammar/items/traits.rs | 4 +-- 4 files changed, 22 insertions(+), 36 deletions(-) (limited to 'crates/ra_parser') diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs index c2e1d701e..88468bc97 100644 --- a/crates/ra_parser/src/grammar.rs +++ b/crates/ra_parser/src/grammar.rs @@ -110,7 +110,7 @@ pub(crate) mod fragments { } pub(crate) fn item(p: &mut Parser) { - items::item_or_macro(p, true, items::ItemFlavor::Mod) + items::item_or_macro(p, true) } pub(crate) fn macro_items(p: &mut Parser) { diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index 51eaf7af6..3291e3f14 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs @@ -73,7 +73,7 @@ pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi) { // test block_items // fn a() { fn b() {} } - let m = match items::maybe_item(p, m, items::ItemFlavor::Mod) { + let m = match items::maybe_item(p, m) { Ok(()) => return, Err(m) => m, }; diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs index cca524cea..9b7623434 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs @@ -22,24 +22,19 @@ use super::*; pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) { attributes::inner_attributes(p); while !(stop_on_r_curly && p.at(T!['}']) || p.at(EOF)) { - item_or_macro(p, stop_on_r_curly, ItemFlavor::Mod) + item_or_macro(p, stop_on_r_curly) } } -pub(super) enum ItemFlavor { - Mod, - Trait, -} - pub(super) const ITEM_RECOVERY_SET: TokenSet = token_set![ FN_KW, STRUCT_KW, ENUM_KW, IMPL_KW, TRAIT_KW, CONST_KW, STATIC_KW, LET_KW, MOD_KW, PUB_KW, CRATE_KW, USE_KW, MACRO_KW ]; -pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemFlavor) { +pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool) { let m = p.start(); attributes::outer_attributes(p); - let m = match maybe_item(p, m, flavor) { + let m = match maybe_item(p, m) { Ok(()) => { if p.at(T![;]) { p.err_and_bump( @@ -76,7 +71,7 @@ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemF } } -pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Result<(), Marker> { +pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> { // test_err pub_expr // fn foo() { pub 92; } let has_visibility = opt_visibility(p); @@ -114,38 +109,29 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul has_mods = true; } - if p.at(IDENT) - && p.at_contextual_kw("default") - && (match p.nth(1) { - T![impl] => true, + // test default_item + // default impl T for Foo {} + if p.at(IDENT) && p.at_contextual_kw("default") { + match p.nth(1) { + T![fn] | T![type] | T![const] | T![impl] => { + p.bump_remap(T![default]); + has_mods = true; + } T![unsafe] => { - // test default_unsafe_impl - // default unsafe impl Foo {} - - // test default_unsafe_fn - // impl T for Foo { + // test default_unsafe_item + // default unsafe impl T for Foo { // default unsafe fn foo() {} // } - if p.nth(2) == T![impl] || p.nth(2) == T![fn] { + if matches!(p.nth(2), T![impl] | T![fn]) { p.bump_remap(T![default]); p.bump(T![unsafe]); has_mods = true; } - false - } - T![fn] | T![type] | T![const] => { - if let ItemFlavor::Mod = flavor { - true - } else { - false - } } - _ => false, - }) - { - p.bump_remap(T![default]); - has_mods = true; + _ => (), + } } + if p.at(IDENT) && p.at_contextual_kw("existential") && p.nth(1) == T![type] { p.bump_remap(T![existential]); has_mods = true; diff --git a/crates/ra_parser/src/grammar/items/traits.rs b/crates/ra_parser/src/grammar/items/traits.rs index ef9c8ff5b..751ce65f2 100644 --- a/crates/ra_parser/src/grammar/items/traits.rs +++ b/crates/ra_parser/src/grammar/items/traits.rs @@ -47,7 +47,7 @@ pub(crate) fn trait_item_list(p: &mut Parser) { error_block(p, "expected an item"); continue; } - item_or_macro(p, true, ItemFlavor::Trait); + item_or_macro(p, true); } p.expect(T!['}']); m.complete(p, ASSOC_ITEM_LIST); @@ -104,7 +104,7 @@ pub(crate) fn impl_item_list(p: &mut Parser) { error_block(p, "expected an item"); continue; } - item_or_macro(p, true, ItemFlavor::Mod); + item_or_macro(p, true); } p.expect(T!['}']); m.complete(p, ASSOC_ITEM_LIST); -- cgit v1.2.3 From f8bfd77e84e5b51dc28ff219e99fdfd6fd9f92c2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 12 Aug 2020 14:52:37 +0200 Subject: Cleanup parser modifiers tests --- crates/ra_parser/src/grammar/items.rs | 62 +++++------------------------------ 1 file changed, 8 insertions(+), 54 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 9b7623434..d091b0fbb 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs @@ -132,6 +132,8 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> { } } + // test existential_type + // existential type Foo: Fn() -> usize; if p.at(IDENT) && p.at_contextual_kw("existential") && p.nth(1) == T![type] { p.bump_remap(T![existential]); has_mods = true; @@ -139,79 +141,31 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> { // items match p.current() { - // test async_fn - // async fn foo() {} - - // test extern_fn - // extern fn foo() {} - - // test const_fn - // const fn foo() {} - - // test const_unsafe_fn - // const unsafe fn foo() {} - - // test unsafe_extern_fn - // unsafe extern "C" fn foo() {} - - // test unsafe_fn - // unsafe fn foo() {} - - // test combined_fns - // async unsafe fn foo() {} - // const unsafe fn bar() {} - - // test_err wrong_order_fns - // unsafe async fn foo() {} - // unsafe const fn bar() {} + // test fn + // fn foo() {} T![fn] => { fn_def(p); m.complete(p, FN); } - // test unsafe_trait - // unsafe trait T {} - - // test auto_trait - // auto trait T {} - - // test unsafe_auto_trait - // unsafe auto trait T {} + // test trait + // trait T {} T![trait] => { traits::trait_def(p); m.complete(p, TRAIT); } - // test unsafe_impl - // unsafe impl Foo {} - - // test default_impl - // default impl Foo {} - - // test_err default_fn_type - // trait T { - // default type T = Bar; - // default fn foo() {} - // } - - // test default_fn_type - // impl T for Foo { - // default type T = Bar; - // default fn foo() {} - // } T![const] => { consts::const_def(p, m); } - // test unsafe_default_impl - // unsafe default impl Foo {} + // test impl + // impl T for S {} T![impl] => { traits::impl_def(p); m.complete(p, IMPL); } - // test existential_type - // existential type Foo: Fn() -> usize; T![type] => { type_def(p, m); } -- cgit v1.2.3