Skip to content

Commit 8f5a5e0

Browse files
committed
fix: Immutable tree panic in generate_delegate_trait
1 parent 08c7bbc commit 8f5a5e0

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

crates/ide-assists/src/handlers/generate_delegate_trait.rs

+41-2
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,11 @@ fn generate_impl(
282282
ai.assoc_items()
283283
.filter(|item| matches!(item, AssocItem::MacroCall(_)).not())
284284
.for_each(|item| {
285-
let assoc =
286-
process_assoc_item(item, qualified_path_type.clone(), field_name);
285+
let assoc = process_assoc_item(
286+
item.clone_for_update(),
287+
qualified_path_type.clone(),
288+
field_name,
289+
);
287290
if let Some(assoc) = assoc {
288291
delegate_assoc_items.add_item(assoc);
289292
}
@@ -1786,4 +1789,40 @@ impl T for B {
17861789
"#,
17871790
);
17881791
}
1792+
1793+
#[test]
1794+
fn assoc_items_attributes_mutably_cloned() {
1795+
check_assist(
1796+
generate_delegate_trait,
1797+
r#"
1798+
pub struct A;
1799+
pub trait C<D> {
1800+
#[allow(clippy::dead_code)]
1801+
fn a_funk(&self) -> &D;
1802+
}
1803+
1804+
pub struct B<T: C<A>> {
1805+
has_dr$0ain: T,
1806+
}
1807+
"#,
1808+
r#"
1809+
pub struct A;
1810+
pub trait C<D> {
1811+
#[allow(clippy::dead_code)]
1812+
fn a_funk(&self) -> &D;
1813+
}
1814+
1815+
pub struct B<T: C<A>> {
1816+
has_drain: T,
1817+
}
1818+
1819+
impl<D, T: C<A>> C<D> for B<T> {
1820+
#[allow(clippy::dead_code)]
1821+
fn a_funk(&self) -> &D {
1822+
<T as C<D>>::a_funk(&self.has_drain)
1823+
}
1824+
}
1825+
"#,
1826+
)
1827+
}
17891828
}

0 commit comments

Comments
 (0)