diff options
| author | A4-Tacks <wdsjxhno1001@163.com> | 2025-07-19 13:38:01 +0800 |
|---|---|---|
| committer | A4-Tacks <wdsjxhno1001@163.com> | 2025-07-19 13:38:01 +0800 |
| commit | 196833ccf2742f0975cd084aac4f354c025638d4 (patch) | |
| tree | 94e6245c198c6cbfa7a508161e4adbce73deb5a2 | |
| parent | 0901d513d89b38175e64c3ebee13d8d44ae6e943 (diff) | |
| download | rust-196833ccf2742f0975cd084aac4f354c025638d4.tar.gz rust-196833ccf2742f0975cd084aac4f354c025638d4.zip | |
Fix ide-assist: Deref transtive
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_deref.rs | 26 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide-assists/src/utils.rs | 1 |
2 files changed, 25 insertions, 2 deletions
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_deref.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_deref.rs index c7b97dcd231..55a09c5d775 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_deref.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_deref.rs @@ -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 @@ -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, @@ -228,6 +228,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( generate_deref, diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/utils.rs b/src/tools/rust-analyzer/crates/ide-assists/src/utils.rs index b1606fb7ba7..a302964e17b 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/utils.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/utils.rs @@ -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)] 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) } |
