ide-assists: Fix warnings about clippy str_to_string rule

This commit is contained in:
Tetsuharu Ohzeki 2024-02-10 00:40:35 +09:00
parent b89a4038c9
commit 80e684254d
18 changed files with 25 additions and 25 deletions

View file

@ -96,7 +96,7 @@ pub(crate) fn apply_demorgan(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
let dm_lhs = demorganed.lhs()?; let dm_lhs = demorganed.lhs()?;
acc.add_group( acc.add_group(
&GroupLabel("Apply De Morgan's law".to_string()), &GroupLabel("Apply De Morgan's law".to_owned()),
AssistId("apply_demorgan", AssistKind::RefactorRewrite), AssistId("apply_demorgan", AssistKind::RefactorRewrite),
"Apply De Morgan's law", "Apply De Morgan's law",
op_range, op_range,
@ -187,7 +187,7 @@ pub(crate) fn apply_demorgan_iterator(acc: &mut Assists, ctx: &AssistContext<'_>
let op_range = method_call.syntax().text_range(); let op_range = method_call.syntax().text_range();
let label = format!("Apply De Morgan's law to `Iterator::{}`", name.text().as_str()); let label = format!("Apply De Morgan's law to `Iterator::{}`", name.text().as_str());
acc.add_group( acc.add_group(
&GroupLabel("Apply De Morgan's law".to_string()), &GroupLabel("Apply De Morgan's law".to_owned()),
AssistId("apply_demorgan_iterator", AssistKind::RefactorRewrite), AssistId("apply_demorgan_iterator", AssistKind::RefactorRewrite),
label, label,
op_range, op_range,

View file

@ -57,7 +57,7 @@ fn block_to_line(acc: &mut Assists, comment: ast::Comment) -> Option<()> {
// Don't introduce trailing whitespace // Don't introduce trailing whitespace
if line.is_empty() { if line.is_empty() {
line_prefix.to_string() line_prefix.to_owned()
} else { } else {
format!("{line_prefix} {line}") format!("{line_prefix} {line}")
} }

View file

@ -244,7 +244,7 @@ fn make_function_name(semantics_scope: &hir::SemanticsScope<'_>) -> ast::NameRef
let default_name = "fun_name"; let default_name = "fun_name";
let mut name = default_name.to_string(); let mut name = default_name.to_owned();
let mut counter = 0; let mut counter = 0;
while names_in_scope.contains(&name) { while names_in_scope.contains(&name) {
counter += 1; counter += 1;
@ -1949,7 +1949,7 @@ fn with_tail_expr(block: ast::BlockExpr, tail_expr: ast::Expr) -> ast::BlockExpr
} }
fn format_type(ty: &hir::Type, ctx: &AssistContext<'_>, module: hir::Module) -> String { fn format_type(ty: &hir::Type, ctx: &AssistContext<'_>, module: hir::Module) -> String {
ty.display_source_code(ctx.db(), module.into(), true).ok().unwrap_or_else(|| "_".to_string()) ty.display_source_code(ctx.db(), module.into(), true).ok().unwrap_or_else(|| "_".to_owned())
} }
fn make_ty(ty: &hir::Type, ctx: &AssistContext<'_>, module: hir::Module) -> ast::Type { fn make_ty(ty: &hir::Type, ctx: &AssistContext<'_>, module: hir::Module) -> ast::Type {

View file

@ -115,7 +115,7 @@ pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
let trailing_ws = if prev_ws.is_some_and(|it| it.text().starts_with('\n')) { let trailing_ws = if prev_ws.is_some_and(|it| it.text().starts_with('\n')) {
format!("\n{indent_to}") format!("\n{indent_to}")
} else { } else {
" ".to_string() " ".to_owned()
}; };
ted::insert_all_raw( ted::insert_all_raw(

View file

@ -416,9 +416,9 @@ fn arguments_from_params(param_list: &ast::ParamList) -> String {
true => format!("&mut {name}"), true => format!("&mut {name}"),
false => name.to_string(), false => name.to_string(),
}, },
None => "_".to_string(), None => "_".to_owned(),
}, },
_ => "_".to_string(), _ => "_".to_owned(),
}); });
args_iter.format(", ").to_string() args_iter.format(", ").to_string()
} }

View file

@ -162,7 +162,7 @@ fn make_record_field_list(
fn name_from_field(field: &ast::RecordExprField) -> ast::Name { fn name_from_field(field: &ast::RecordExprField) -> ast::Name {
let text = match field.name_ref() { let text = match field.name_ref() {
Some(it) => it.to_string(), Some(it) => it.to_string(),
None => name_from_field_shorthand(field).unwrap_or("unknown".to_string()), None => name_from_field_shorthand(field).unwrap_or("unknown".to_owned()),
}; };
make::name(&text) make::name(&text)
} }

View file

@ -202,7 +202,7 @@ fn get_adt_source(
let file = ctx.sema.parse(range.file_id); let file = ctx.sema.parse(range.file_id);
let adt_source = let adt_source =
ctx.sema.find_node_at_offset_with_macros(file.syntax(), range.range.start())?; ctx.sema.find_node_at_offset_with_macros(file.syntax(), range.range.start())?;
find_struct_impl(ctx, &adt_source, &[fn_name.to_string()]).map(|impl_| (impl_, range.file_id)) find_struct_impl(ctx, &adt_source, &[fn_name.to_owned()]).map(|impl_| (impl_, range.file_id))
} }
struct FunctionTemplate { struct FunctionTemplate {
@ -1007,7 +1007,7 @@ fn fn_arg_name(sema: &Semantics<'_, RootDatabase>, arg_expr: &ast::Expr) -> Stri
name name
} }
Some(name) => name, Some(name) => name,
None => "arg".to_string(), None => "arg".to_owned(),
} }
} }

View file

@ -79,7 +79,7 @@ pub(crate) fn generate_is_empty_from_len(acc: &mut Assists, ctx: &AssistContext<
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {
self.len() == 0 self.len() == 0
}"# }"#
.to_string(); .to_owned();
builder.insert(range.end(), code) builder.insert(range.end(), code)
}, },
) )

View file

@ -118,7 +118,7 @@ pub(crate) fn generate_trait_from_impl(acc: &mut Assists, ctx: &AssistContext<'_
let arg_list = if let Some(genpars) = impl_ast.generic_param_list() { let arg_list = if let Some(genpars) = impl_ast.generic_param_list() {
genpars.to_generic_args().to_string() genpars.to_generic_args().to_string()
} else { } else {
"".to_string() "".to_owned()
}; };
if let Some(snippet_cap) = ctx.config.snippet_cap { if let Some(snippet_cap) = ctx.config.snippet_cap {

View file

@ -60,7 +60,7 @@ pub(crate) fn inline_const_as_literal(acc: &mut Assists, ctx: &AssistContext<'_>
let id = AssistId("inline_const_as_literal", AssistKind::RefactorInline); let id = AssistId("inline_const_as_literal", AssistKind::RefactorInline);
let label = "Inline const as literal".to_string(); let label = "Inline const as literal".to_owned();
let target = variable.syntax().text_range(); let target = variable.syntax().text_range();
return acc.add(id, label, target, |edit| { return acc.add(id, label, target, |edit| {

View file

@ -41,7 +41,7 @@ pub(crate) fn inline_macro(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
acc.add( acc.add(
AssistId("inline_macro", AssistKind::RefactorInline), AssistId("inline_macro", AssistKind::RefactorInline),
"Inline macro".to_string(), "Inline macro".to_owned(),
text_range, text_range,
|builder| builder.replace(text_range, expanded.to_string()), |builder| builder.replace(text_range, expanded.to_string()),
) )

View file

@ -129,7 +129,7 @@ fn generate_unique_lifetime_param_name(
type_params.lifetime_params().map(|p| p.syntax().text().to_string()).collect(); type_params.lifetime_params().map(|p| p.syntax().text().to_string()).collect();
('a'..='z').map(|it| format!("'{it}")).find(|it| !used_lifetime_params.contains(it)) ('a'..='z').map(|it| format!("'{it}")).find(|it| !used_lifetime_params.contains(it))
} }
None => Some("'a".to_string()), None => Some("'a".to_owned()),
} }
.map(|it| make::lifetime(&it)) .map(|it| make::lifetime(&it))
} }

View file

@ -75,7 +75,7 @@ pub(crate) fn move_module_to_file(acc: &mut Assists, ctx: &AssistContext<'_>) ->
let contents = { let contents = {
let items = module_items.dedent(IndentLevel(1)).to_string(); let items = module_items.dedent(IndentLevel(1)).to_string();
let mut items = let mut items =
items.trim_start_matches('{').trim_end_matches('}').trim().to_string(); items.trim_start_matches('{').trim_end_matches('}').trim().to_owned();
if !items.is_empty() { if !items.is_empty() {
items.push('\n'); items.push('\n');
} }

View file

@ -33,7 +33,7 @@ pub(crate) fn reformat_number_literal(acc: &mut Assists, ctx: &AssistContext<'_>
} }
let radix = literal.radix(); let radix = literal.radix();
let mut converted = prefix.to_string(); let mut converted = prefix.to_owned();
converted.push_str(&add_group_separators(value, group_size(radix))); converted.push_str(&add_group_separators(value, group_size(radix)));
converted.push_str(suffix); converted.push_str(suffix);

View file

@ -474,7 +474,7 @@ pub fn test_some_range(a: int) -> bool {
&db, &db,
&cfg, &cfg,
AssistResolveStrategy::Single(SingleResolve { AssistResolveStrategy::Single(SingleResolve {
assist_id: "SOMETHING_MISMATCHING".to_string(), assist_id: "SOMETHING_MISMATCHING".to_owned(),
assist_kind: AssistKind::RefactorExtract, assist_kind: AssistKind::RefactorExtract,
}), }),
frange, frange,
@ -520,7 +520,7 @@ pub fn test_some_range(a: int) -> bool {
&db, &db,
&cfg, &cfg,
AssistResolveStrategy::Single(SingleResolve { AssistResolveStrategy::Single(SingleResolve {
assist_id: "extract_variable".to_string(), assist_id: "extract_variable".to_owned(),
assist_kind: AssistKind::RefactorExtract, assist_kind: AssistKind::RefactorExtract,
}), }),
frange, frange,

View file

@ -15,7 +15,7 @@ fn sourcegen_assists_docs() {
let mut buf = " let mut buf = "
use super::check_doc_test; use super::check_doc_test;
" "
.to_string(); .to_owned();
for assist in assists.iter() { for assist in assists.iter() {
for (idx, section) in assist.sections.iter().enumerate() { for (idx, section) in assist.sections.iter().enumerate() {
let test_id = let test_id =
@ -101,7 +101,7 @@ impl Assist {
let mut assist = Assist { id, location, sections: Vec::new() }; let mut assist = Assist { id, location, sections: Vec::new() };
while lines.peek().is_some() { while lines.peek().is_some() {
let doc = take_until(lines.by_ref(), "```").trim().to_string(); let doc = take_until(lines.by_ref(), "```").trim().to_owned();
assert!( assert!(
(doc.chars().next().unwrap().is_ascii_uppercase() && doc.ends_with('.')) (doc.chars().next().unwrap().is_ascii_uppercase() && doc.ends_with('.'))
|| !assist.sections.is_empty(), || !assist.sections.is_empty(),

View file

@ -673,7 +673,7 @@ impl ReferenceConversion {
pub(crate) fn convert_type(&self, db: &dyn HirDatabase) -> ast::Type { pub(crate) fn convert_type(&self, db: &dyn HirDatabase) -> ast::Type {
let ty = match self.conversion { let ty = match self.conversion {
ReferenceConversionType::Copy => self.ty.display(db).to_string(), ReferenceConversionType::Copy => self.ty.display(db).to_string(),
ReferenceConversionType::AsRefStr => "&str".to_string(), ReferenceConversionType::AsRefStr => "&str".to_owned(),
ReferenceConversionType::AsRefSlice => { ReferenceConversionType::AsRefSlice => {
let type_argument_name = let type_argument_name =
self.ty.type_arguments().next().unwrap().display(db).to_string(); self.ty.type_arguments().next().unwrap().display(db).to_string();

View file

@ -77,7 +77,7 @@ pub(crate) fn for_unique_generic_name(
p => p.to_string(), p => p.to_string(),
}) })
.collect::<FxHashSet<_>>(); .collect::<FxHashSet<_>>();
let mut name = name.to_string(); let mut name = name.to_owned();
let base_len = name.len(); let base_len = name.len();
let mut count = 0; let mut count = 0;
while param_names.contains(&name) { while param_names.contains(&name) {
@ -165,7 +165,7 @@ pub(crate) fn for_variable(expr: &ast::Expr, sema: &Semantics<'_, RootDatabase>)
} }
} }
"var_name".to_string() "var_name".to_owned()
} }
fn normalize(name: &str) -> Option<String> { fn normalize(name: &str) -> Option<String> {