aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_assists/src/handlers
diff options
context:
space:
mode:
authorcynecx <[email protected]>2021-03-26 17:30:59 +0000
committercynecx <[email protected]>2021-03-26 17:30:59 +0000
commit5ff3299dd61ea5c5790c01819994c9d8fa6afc09 (patch)
treee691982730fe01802f874066927b2ebbe8badc75 /crates/ide_assists/src/handlers
parent4ecaad98e074c42dbf637a11afcb630aafffd7b3 (diff)
syntax: return owned string instead of leaking string
Diffstat (limited to 'crates/ide_assists/src/handlers')
-rw-r--r--crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs2
-rw-r--r--crates/ide_assists/src/handlers/generate_enum_is_method.rs2
-rw-r--r--crates/ide_assists/src/handlers/generate_enum_projection_method.rs3
-rw-r--r--crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs5
4 files changed, 7 insertions, 5 deletions
diff --git a/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs
index 596c536a7..a8d6355bd 100644
--- a/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs
+++ b/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs
@@ -195,7 +195,7 @@ fn extract_struct_def(
195 195
196fn update_variant(rewriter: &mut SyntaxRewriter, variant: &ast::Variant) -> Option<()> { 196fn update_variant(rewriter: &mut SyntaxRewriter, variant: &ast::Variant) -> Option<()> {
197 let name = variant.name()?; 197 let name = variant.name()?;
198 let tuple_field = make::tuple_field(None, make::ty(name.text())); 198 let tuple_field = make::tuple_field(None, make::ty(&name.text()));
199 let replacement = make::variant( 199 let replacement = make::variant(
200 name, 200 name,
201 Some(ast::FieldList::TupleFieldList(make::tuple_field_list(iter::once(tuple_field)))), 201 Some(ast::FieldList::TupleFieldList(make::tuple_field_list(iter::once(tuple_field)))),
diff --git a/crates/ide_assists/src/handlers/generate_enum_is_method.rs b/crates/ide_assists/src/handlers/generate_enum_is_method.rs
index 7e181a480..a9f71a703 100644
--- a/crates/ide_assists/src/handlers/generate_enum_is_method.rs
+++ b/crates/ide_assists/src/handlers/generate_enum_is_method.rs
@@ -44,7 +44,7 @@ pub(crate) fn generate_enum_is_method(acc: &mut Assists, ctx: &AssistContext) ->
44 }; 44 };
45 45
46 let enum_lowercase_name = to_lower_snake_case(&parent_enum.name()?.to_string()); 46 let enum_lowercase_name = to_lower_snake_case(&parent_enum.name()?.to_string());
47 let fn_name = format!("is_{}", &to_lower_snake_case(variant_name.text())); 47 let fn_name = format!("is_{}", &to_lower_snake_case(&variant_name.text()));
48 48
49 // Return early if we've found an existing new fn 49 // Return early if we've found an existing new fn
50 let impl_def = find_struct_impl(&ctx, &parent_enum, &fn_name)?; 50 let impl_def = find_struct_impl(&ctx, &parent_enum, &fn_name)?;
diff --git a/crates/ide_assists/src/handlers/generate_enum_projection_method.rs b/crates/ide_assists/src/handlers/generate_enum_projection_method.rs
index 871bcab50..e2f572ba3 100644
--- a/crates/ide_assists/src/handlers/generate_enum_projection_method.rs
+++ b/crates/ide_assists/src/handlers/generate_enum_projection_method.rs
@@ -132,7 +132,8 @@ fn generate_enum_projection_method(
132 ast::StructKind::Unit => return None, 132 ast::StructKind::Unit => return None,
133 }; 133 };
134 134
135 let fn_name = format!("{}_{}", props.fn_name_prefix, &to_lower_snake_case(variant_name.text())); 135 let fn_name =
136 format!("{}_{}", props.fn_name_prefix, &to_lower_snake_case(&variant_name.text()));
136 137
137 // Return early if we've found an existing new fn 138 // Return early if we've found an existing new fn
138 let impl_def = find_struct_impl(&ctx, &parent_enum, &fn_name)?; 139 let impl_def = find_struct_impl(&ctx, &parent_enum, &fn_name)?;
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 4f0ef52ca..f872d20c8 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
@@ -165,7 +165,7 @@ fn impl_def_from_trait(
165 } 165 }
166 let impl_def = make::impl_trait( 166 let impl_def = make::impl_trait(
167 trait_path.clone(), 167 trait_path.clone(),
168 make::path_unqualified(make::path_segment(make::name_ref(annotated_name.text()))), 168 make::path_unqualified(make::path_segment(make::name_ref(&annotated_name.text()))),
169 ); 169 );
170 let (impl_def, first_assoc_item) = 170 let (impl_def, first_assoc_item) =
171 add_trait_assoc_items_to_impl(sema, trait_items, trait_, impl_def, target_scope); 171 add_trait_assoc_items_to_impl(sema, trait_items, trait_, impl_def, target_scope);
@@ -178,12 +178,13 @@ fn update_attribute(
178 trait_name: &ast::NameRef, 178 trait_name: &ast::NameRef,
179 attr: &ast::Attr, 179 attr: &ast::Attr,
180) { 180) {
181 let trait_name = trait_name.text();
181 let new_attr_input = input 182 let new_attr_input = input
182 .syntax() 183 .syntax()
183 .descendants_with_tokens() 184 .descendants_with_tokens()
184 .filter(|t| t.kind() == IDENT) 185 .filter(|t| t.kind() == IDENT)
185 .filter_map(|t| t.into_token().map(|t| t.text().to_string())) 186 .filter_map(|t| t.into_token().map(|t| t.text().to_string()))
186 .filter(|t| t != trait_name.text()) 187 .filter(|t| t != &trait_name)
187 .collect::<Vec<_>>(); 188 .collect::<Vec<_>>();
188 let has_more_derives = !new_attr_input.is_empty(); 189 let has_more_derives = !new_attr_input.is_empty();
189 190