From 5ff3299dd61ea5c5790c01819994c9d8fa6afc09 Mon Sep 17 00:00:00 2001 From: cynecx Date: Fri, 26 Mar 2021 18:30:59 +0100 Subject: syntax: return owned string instead of leaking string --- crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs | 2 +- crates/ide_assists/src/handlers/generate_enum_is_method.rs | 2 +- crates/ide_assists/src/handlers/generate_enum_projection_method.rs | 3 ++- crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs | 5 +++-- 4 files changed, 7 insertions(+), 5 deletions(-) (limited to 'crates/ide_assists/src/handlers') 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( fn update_variant(rewriter: &mut SyntaxRewriter, variant: &ast::Variant) -> Option<()> { let name = variant.name()?; - let tuple_field = make::tuple_field(None, make::ty(name.text())); + let tuple_field = make::tuple_field(None, make::ty(&name.text())); let replacement = make::variant( name, 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) -> }; let enum_lowercase_name = to_lower_snake_case(&parent_enum.name()?.to_string()); - let fn_name = format!("is_{}", &to_lower_snake_case(variant_name.text())); + let fn_name = format!("is_{}", &to_lower_snake_case(&variant_name.text())); // Return early if we've found an existing new fn 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( ast::StructKind::Unit => return None, }; - let fn_name = format!("{}_{}", props.fn_name_prefix, &to_lower_snake_case(variant_name.text())); + let fn_name = + format!("{}_{}", props.fn_name_prefix, &to_lower_snake_case(&variant_name.text())); // Return early if we've found an existing new fn 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( } let impl_def = make::impl_trait( trait_path.clone(), - make::path_unqualified(make::path_segment(make::name_ref(annotated_name.text()))), + make::path_unqualified(make::path_segment(make::name_ref(&annotated_name.text()))), ); let (impl_def, first_assoc_item) = add_trait_assoc_items_to_impl(sema, trait_items, trait_, impl_def, target_scope); @@ -178,12 +178,13 @@ fn update_attribute( trait_name: &ast::NameRef, attr: &ast::Attr, ) { + let trait_name = trait_name.text(); let new_attr_input = input .syntax() .descendants_with_tokens() .filter(|t| t.kind() == IDENT) .filter_map(|t| t.into_token().map(|t| t.text().to_string())) - .filter(|t| t != trait_name.text()) + .filter(|t| t != &trait_name) .collect::>(); let has_more_derives = !new_attr_input.is_empty(); -- cgit v1.2.3