Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions crates/ide-assists/src/handlers/generate_deref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use syntax::{
use crate::{
AssistId,
assist_context::{AssistContext, Assists, SourceChangeBuilder},
utils::generate_trait_impl_text,
utils::generate_trait_impl_text_intransitive,
};

// Assist: generate_deref
Expand Down Expand Up @@ -150,7 +150,7 @@ fn generate_edit(
),
};
let strukt_adt = ast::Adt::Struct(strukt);
let deref_impl = generate_trait_impl_text(
let deref_impl = generate_trait_impl_text_intransitive(
&strukt_adt,
&trait_path.display(db, edition).to_string(),
&impl_code,
Expand Down Expand Up @@ -227,6 +227,28 @@ impl core::ops::Deref for B {
);
}

#[test]
fn test_generate_record_deref_with_generic() {
check_assist(
generate_deref,
r#"
//- minicore: deref
struct A<T>($0T);
"#,
r#"
struct A<T>(T);

impl<T> core::ops::Deref for A<T> {
type Target = T;

fn deref(&self) -> &Self::Target {
&self.0
}
}
"#,
);
}

#[test]
fn test_generate_record_deref_short_path() {
check_assist(
Expand Down
1 change: 1 addition & 0 deletions crates/ide-assists/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ pub(crate) fn generate_impl_text(adt: &ast::Adt, code: &str) -> String {
///
/// This is useful for traits like `PartialEq`, since `impl<T> PartialEq for U<T>` often requires `T: PartialEq`.
// FIXME: migrate remaining uses to `generate_trait_impl`
#[allow(dead_code)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to keep the old function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will deleting this function affect other PRs?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, but ok.

pub(crate) fn generate_trait_impl_text(adt: &ast::Adt, trait_text: &str, code: &str) -> String {
generate_impl_text_inner(adt, Some(trait_text), true, code)
}
Expand Down
Loading