Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4221354

Browse files
committedSep 13, 2024·
Auto merge of #18073 - alibektas:immutable_tree_panics, r=lnicola
fix: Immutable tree panic in `generate_delegate_trait` fixes #17835
2 parents fd243cd + 8f5a5e0 commit 4221354

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
}
@@ -1797,4 +1800,40 @@ impl T for B {
17971800
"#,
17981801
);
17991802
}
1803+
1804+
#[test]
1805+
fn assoc_items_attributes_mutably_cloned() {
1806+
check_assist(
1807+
generate_delegate_trait,
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_dr$0ain: T,
1817+
}
1818+
"#,
1819+
r#"
1820+
pub struct A;
1821+
pub trait C<D> {
1822+
#[allow(clippy::dead_code)]
1823+
fn a_funk(&self) -> &D;
1824+
}
1825+
1826+
pub struct B<T: C<A>> {
1827+
has_drain: T,
1828+
}
1829+
1830+
impl<D, T: C<A>> C<D> for B<T> {
1831+
#[allow(clippy::dead_code)]
1832+
fn a_funk(&self) -> &D {
1833+
<T as C<D>>::a_funk(&self.has_drain)
1834+
}
1835+
}
1836+
"#,
1837+
)
1838+
}
18001839
}

0 commit comments

Comments
 (0)
Please sign in to comment.