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 +++-- crates/ide_assists/src/utils.rs | 4 ++-- 5 files changed, 9 insertions(+), 7 deletions(-) (limited to 'crates/ide_assists/src') 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(); diff --git a/crates/ide_assists/src/utils.rs b/crates/ide_assists/src/utils.rs index 62f959082..9de9e4dbd 100644 --- a/crates/ide_assists/src/utils.rs +++ b/crates/ide_assists/src/utils.rs @@ -246,7 +246,7 @@ fn invert_special_case(sema: &Semantics, expr: &ast::Expr) -> Opti let method = mce.name_ref()?; let arg_list = mce.arg_list()?; - let method = match method.text() { + let method = match method.text().as_str() { "is_some" => "is_none", "is_none" => "is_some", "is_ok" => "is_err", @@ -442,7 +442,7 @@ fn generate_impl_text_inner(adt: &ast::Adt, trait_text: Option<&str>, code: &str buf.push_str(trait_text); buf.push_str(" for "); } - buf.push_str(adt.name().unwrap().text()); + buf.push_str(&adt.name().unwrap().text()); if let Some(generic_params) = generic_params { let lifetime_params = generic_params .lifetime_params() -- cgit v1.2.3