aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_assists/src/handlers
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-05-09 15:58:03 +0100
committerAleksey Kladov <[email protected]>2021-05-09 15:58:03 +0100
commitd9c9f6dc2cd3080009c4ce2c3f0f340949f4f53c (patch)
treeaf7620ddcab6df6b746e6b8b928acbc193248844 /crates/ide_assists/src/handlers
parentedeb4927829380ed25e3899e85b2809bbb39a846 (diff)
cleanups
Diffstat (limited to 'crates/ide_assists/src/handlers')
-rw-r--r--crates/ide_assists/src/handlers/introduce_named_lifetime.rs4
-rw-r--r--crates/ide_assists/src/handlers/replace_impl_trait_with_generic.rs24
2 files changed, 14 insertions, 14 deletions
diff --git a/crates/ide_assists/src/handlers/introduce_named_lifetime.rs b/crates/ide_assists/src/handlers/introduce_named_lifetime.rs
index 9f4f71d6c..cb71ca8bd 100644
--- a/crates/ide_assists/src/handlers/introduce_named_lifetime.rs
+++ b/crates/ide_assists/src/handlers/introduce_named_lifetime.rs
@@ -139,12 +139,12 @@ fn generate_unique_lifetime_param_name(
139 139
140fn add_lifetime_param(type_params: ast::GenericParamList, new_lifetime_param: char) { 140fn add_lifetime_param(type_params: ast::GenericParamList, new_lifetime_param: char) {
141 let generic_param = 141 let generic_param =
142 make::generic_param(format!("'{}", new_lifetime_param), None).clone_for_update(); 142 make::generic_param(&format!("'{}", new_lifetime_param), None).clone_for_update();
143 type_params.add_generic_param(generic_param); 143 type_params.add_generic_param(generic_param);
144} 144}
145 145
146fn make_ast_lifetime(new_lifetime_param: char) -> ast::Lifetime { 146fn make_ast_lifetime(new_lifetime_param: char) -> ast::Lifetime {
147 make::generic_param(format!("'{}", new_lifetime_param), None) 147 make::generic_param(&format!("'{}", new_lifetime_param), None)
148 .syntax() 148 .syntax()
149 .descendants() 149 .descendants()
150 .find_map(ast::Lifetime::cast) 150 .find_map(ast::Lifetime::cast)
diff --git a/crates/ide_assists/src/handlers/replace_impl_trait_with_generic.rs b/crates/ide_assists/src/handlers/replace_impl_trait_with_generic.rs
index 8509a5e11..26a0e81f0 100644
--- a/crates/ide_assists/src/handlers/replace_impl_trait_with_generic.rs
+++ b/crates/ide_assists/src/handlers/replace_impl_trait_with_generic.rs
@@ -1,6 +1,6 @@
1use syntax::ast::{self, edit::AstNodeEdit, make, AstNode, GenericParamsOwner}; 1use syntax::ast::{self, edit::AstNodeEdit, make, AstNode, GenericParamsOwner};
2 2
3use crate::{AssistContext, AssistId, AssistKind, Assists}; 3use crate::{utils::suggest_name, AssistContext, AssistId, AssistKind, Assists};
4 4
5// Assist: replace_impl_trait_with_generic 5// Assist: replace_impl_trait_with_generic
6// 6//
@@ -17,30 +17,30 @@ pub(crate) fn replace_impl_trait_with_generic(
17 acc: &mut Assists, 17 acc: &mut Assists,
18 ctx: &AssistContext, 18 ctx: &AssistContext,
19) -> Option<()> { 19) -> Option<()> {
20 let type_impl_trait = ctx.find_node_at_offset::<ast::ImplTraitType>()?; 20 let impl_trait_type = ctx.find_node_at_offset::<ast::ImplTraitType>()?;
21 let type_param = type_impl_trait.syntax().parent().and_then(ast::Param::cast)?; 21 let param = impl_trait_type.syntax().parent().and_then(ast::Param::cast)?;
22 let type_fn = type_param.syntax().ancestors().find_map(ast::Fn::cast)?; 22 let fn_ = param.syntax().ancestors().find_map(ast::Fn::cast)?;
23 23
24 let impl_trait_ty = type_impl_trait.type_bound_list()?; 24 let type_bound_list = impl_trait_type.type_bound_list()?;
25 25
26 let target = type_fn.syntax().text_range(); 26 let target = fn_.syntax().text_range();
27 acc.add( 27 acc.add(
28 AssistId("replace_impl_trait_with_generic", AssistKind::RefactorRewrite), 28 AssistId("replace_impl_trait_with_generic", AssistKind::RefactorRewrite),
29 "Replace impl trait with generic", 29 "Replace impl trait with generic",
30 target, 30 target,
31 |edit| { 31 |edit| {
32 let generic_letter = impl_trait_ty.to_string().chars().next().unwrap().to_string(); 32 let type_param_name = suggest_name::generic_parameter(&impl_trait_type);
33 33
34 let generic_param_list = type_fn 34 let generic_param_list = fn_
35 .generic_param_list() 35 .generic_param_list()
36 .unwrap_or_else(|| make::generic_param_list(None)) 36 .unwrap_or_else(|| make::generic_param_list(None))
37 .append_param(make::generic_param(generic_letter.clone(), Some(impl_trait_ty))); 37 .append_param(make::generic_param(&type_param_name, Some(type_bound_list)));
38 38
39 let new_type_fn = type_fn 39 let new_type_fn = fn_
40 .replace_descendant::<ast::Type>(type_impl_trait.into(), make::ty(&generic_letter)) 40 .replace_descendant::<ast::Type>(impl_trait_type.into(), make::ty(&type_param_name))
41 .with_generic_param_list(generic_param_list); 41 .with_generic_param_list(generic_param_list);
42 42
43 edit.replace_ast(type_fn.clone(), new_type_fn); 43 edit.replace_ast(fn_.clone(), new_type_fn);
44 }, 44 },
45 ) 45 )
46} 46}