about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTheDoctor314 <64731940+TheDoctor314@users.noreply.github.com>2021-11-08 21:19:22 +0530
committerTheDoctor314 <64731940+TheDoctor314@users.noreply.github.com>2021-11-10 12:53:48 +0530
commit05b368f065cefeff31cbc04283453d6a4027532c (patch)
tree1eca7024bcb0e965c3301e220751fad2732bc833
parent4f93fa12134e47b12a27bd456e59247e8e9d51df (diff)
downloadrust-05b368f065cefeff31cbc04283453d6a4027532c.tar.gz
rust-05b368f065cefeff31cbc04283453d6a4027532c.zip
Add generic parameters for manual impl assist
The `impl_trait` function takes an optional `GenericParamList` to create
the trait impl.
-rw-r--r--crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs9
-rw-r--r--crates/syntax/src/ast/make.rs9
2 files changed, 13 insertions, 5 deletions
diff --git a/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs b/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs
index a86fe3fa169..7aeaedf5f05 100644
--- a/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs
+++ b/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs
@@ -3,7 +3,7 @@ use ide_db::helpers::{import_assets::NameToImport, mod_path_to_ast};
 use ide_db::items_locator;
 use itertools::Itertools;
 use syntax::{
-    ast::{self, make, AstNode, HasName},
+    ast::{self, make, AstNode, HasGenericParams, HasName},
     SyntaxKind::{IDENT, WHITESPACE},
 };
 
@@ -160,8 +160,11 @@ fn impl_def_from_trait(
     if trait_items.is_empty() {
         return None;
     }
-    let impl_def =
-        make::impl_trait(trait_path.clone(), make::ext::ident_path(&annotated_name.text()));
+    let impl_def = make::impl_trait(
+        trait_path.clone(),
+        make::ext::ident_path(&annotated_name.text()),
+        adt.generic_param_list(),
+    );
     let (impl_def, first_assoc_item) =
         add_trait_assoc_items_to_impl(sema, trait_items, trait_, impl_def, target_scope);
 
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs
index ed69973af92..e1938307cf3 100644
--- a/crates/syntax/src/ast/make.rs
+++ b/crates/syntax/src/ast/make.rs
@@ -149,8 +149,13 @@ pub fn impl_(
     ast_from_text(&format!("impl{} {}{} {{}}", params, ty, ty_params))
 }
 
-pub fn impl_trait(trait_: ast::Path, ty: ast::Path) -> ast::Impl {
-    ast_from_text(&format!("impl {} for {} {{}}", trait_, ty))
+pub fn impl_trait(
+    trait_: ast::Path,
+    ty: ast::Path,
+    ty_params: Option<ast::GenericParamList>,
+) -> ast::Impl {
+    let ty_params = ty_params.map_or_else(String::new, |params| params.to_string());
+    ast_from_text(&format!("impl{2} {} for {}{2} {{}}", trait_, ty, ty_params))
 }
 
 pub(crate) fn generic_arg_list() -> ast::GenericArgList {