From 526dc4b5f567df5416261fbfe1c01bb9f7e35e6e Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Sat, 10 Apr 2021 20:30:19 +0200 Subject: Revert "Use `name![derive]`" This reverts commit d6187de4cd34a1288c7820c5477b81b1e9b692a9. --- crates/hir_expand/src/input.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'crates/hir_expand/src/input.rs') diff --git a/crates/hir_expand/src/input.rs b/crates/hir_expand/src/input.rs index d1f22aba4..40f8da696 100644 --- a/crates/hir_expand/src/input.rs +++ b/crates/hir_expand/src/input.rs @@ -5,11 +5,7 @@ use syntax::{ AstNode, SyntaxNode, }; -use crate::{ - db::AstDatabase, - name::{name, AsName}, - AttrId, LazyMacroId, MacroCallKind, MacroCallLoc, -}; +use crate::{db::AstDatabase, name::AsName, AttrId, LazyMacroId, MacroCallKind, MacroCallLoc}; pub(crate) fn process_macro_input( db: &dyn AstDatabase, @@ -39,7 +35,7 @@ fn remove_derives_up_to(item: ast::Item, attr: AttrId) -> ast::Item { if let Some(name) = attr.path().and_then(|path| path.as_single_segment()).and_then(|seg| seg.name_ref()) { - if name.as_name() == name![derive] { + if name.as_name().to_string() == "derive" { attr.syntax().detach(); } } -- cgit v1.2.3 From 050dc93e00c9b4be3982c82fa1babd31c3b13b7b Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Sat, 10 Apr 2021 20:30:24 +0200 Subject: Revert "Use `pub(crate)`" This reverts commit c51213c2e7de21b7e68e6773ca3be0cdfc7c18af. --- crates/hir_expand/src/input.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'crates/hir_expand/src/input.rs') diff --git a/crates/hir_expand/src/input.rs b/crates/hir_expand/src/input.rs index 40f8da696..8f652cd7c 100644 --- a/crates/hir_expand/src/input.rs +++ b/crates/hir_expand/src/input.rs @@ -7,11 +7,7 @@ use syntax::{ use crate::{db::AstDatabase, name::AsName, AttrId, LazyMacroId, MacroCallKind, MacroCallLoc}; -pub(crate) fn process_macro_input( - db: &dyn AstDatabase, - node: SyntaxNode, - id: LazyMacroId, -) -> SyntaxNode { +pub fn process_macro_input(db: &dyn AstDatabase, node: SyntaxNode, id: LazyMacroId) -> SyntaxNode { let loc: MacroCallLoc = db.lookup_intern_macro(id); match loc.kind { -- cgit v1.2.3 From 44b04ebe43534f749bc3a8431449bc019cc9c3b2 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Sat, 10 Apr 2021 20:30:28 +0200 Subject: Revert "Rewrite `#[derive]` removal to be based on AST" This reverts commit 7e78aebc8fbbb4043d62949681e4d700f1a2ec46. --- crates/hir_expand/src/input.rs | 87 ------------------------------------------ 1 file changed, 87 deletions(-) delete mode 100644 crates/hir_expand/src/input.rs (limited to 'crates/hir_expand/src/input.rs') diff --git a/crates/hir_expand/src/input.rs b/crates/hir_expand/src/input.rs deleted file mode 100644 index 8f652cd7c..000000000 --- a/crates/hir_expand/src/input.rs +++ /dev/null @@ -1,87 +0,0 @@ -//! Macro input conditioning. - -use syntax::{ - ast::{self, AttrsOwner}, - AstNode, SyntaxNode, -}; - -use crate::{db::AstDatabase, name::AsName, AttrId, LazyMacroId, MacroCallKind, MacroCallLoc}; - -pub fn process_macro_input(db: &dyn AstDatabase, node: SyntaxNode, id: LazyMacroId) -> SyntaxNode { - let loc: MacroCallLoc = db.lookup_intern_macro(id); - - match loc.kind { - MacroCallKind::FnLike { .. } => node, - MacroCallKind::Derive { derive_attr, .. } => { - let item = match ast::Item::cast(node.clone()) { - Some(item) => item, - None => return node, - }; - - remove_derives_up_to(item, derive_attr).syntax().clone() - } - } -} - -/// Removes `#[derive]` attributes from `item`, up to `attr`. -fn remove_derives_up_to(item: ast::Item, attr: AttrId) -> ast::Item { - let item = item.clone_for_update(); - let idx = attr.0 as usize; - for attr in item.attrs().take(idx + 1) { - if let Some(name) = - attr.path().and_then(|path| path.as_single_segment()).and_then(|seg| seg.name_ref()) - { - if name.as_name().to_string() == "derive" { - attr.syntax().detach(); - } - } - } - item -} - -#[cfg(test)] -mod tests { - use base_db::fixture::WithFixture; - use base_db::SourceDatabase; - use expect_test::{expect, Expect}; - - use crate::test_db::TestDB; - - use super::*; - - fn test_remove_derives_up_to(attr: AttrId, ra_fixture: &str, expect: Expect) { - let (db, file_id) = TestDB::with_single_file(&ra_fixture); - let parsed = db.parse(file_id); - - let mut items: Vec<_> = - parsed.syntax_node().descendants().filter_map(ast::Item::cast).collect(); - assert_eq!(items.len(), 1); - - let item = remove_derives_up_to(items.pop().unwrap(), attr); - expect.assert_eq(&item.to_string()); - } - - #[test] - fn remove_derive() { - test_remove_derives_up_to( - AttrId(2), - r#" -#[allow(unused)] -#[derive(Copy)] -#[derive(Hello)] -#[derive(Clone)] -struct A { - bar: u32 -} - "#, - expect![[r#" -#[allow(unused)] - - -#[derive(Clone)] -struct A { - bar: u32 -}"#]], - ); - } -} -- cgit v1.2.3