From bd085df893d054c3dd8190dea089a82d40ea5e61 Mon Sep 17 00:00:00 2001 From: Ali Bektas Date: Sun, 8 Sep 2024 19:10:15 +0200 Subject: [PATCH] fix: Immutable tree panic in `generate_delegate_trait` --- .../src/handlers/generate_delegate_trait.rs | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_delegate_trait.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_delegate_trait.rs index c22d19574fb49..46ef1ff92929c 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_delegate_trait.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_delegate_trait.rs @@ -282,8 +282,11 @@ fn generate_impl( ai.assoc_items() .filter(|item| matches!(item, AssocItem::MacroCall(_)).not()) .for_each(|item| { - let assoc = - process_assoc_item(item, qualified_path_type.clone(), field_name); + let assoc = process_assoc_item( + item.clone_for_update(), + qualified_path_type.clone(), + field_name, + ); if let Some(assoc) = assoc { delegate_assoc_items.add_item(assoc); } @@ -1786,4 +1789,40 @@ impl T for B { "#, ); } + + #[test] + fn assoc_items_attributes_mutably_cloned() { + check_assist( + generate_delegate_trait, + r#" +pub struct A; +pub trait C { + #[allow(clippy::dead_code)] + fn a_funk(&self) -> &D; +} + +pub struct B> { + has_dr$0ain: T, +} +"#, + r#" +pub struct A; +pub trait C { + #[allow(clippy::dead_code)] + fn a_funk(&self) -> &D; +} + +pub struct B> { + has_drain: T, +} + +impl> C for B { + #[allow(clippy::dead_code)] + fn a_funk(&self) -> &D { + >::a_funk(&self.has_drain) + } +} +"#, + ) + } }