ide-diagnostics: Fix warnings about clippy str_to_string rule

This commit is contained in:
Tetsuharu Ohzeki 2024-02-10 00:35:55 +09:00
parent eba1b13295
commit d00f1c1b16
22 changed files with 36 additions and 36 deletions

View file

@ -16,7 +16,7 @@ pub(crate) fn inactive_code(
} }
let inactive = DnfExpr::new(d.cfg.clone()).why_inactive(&d.opts); let inactive = DnfExpr::new(d.cfg.clone()).why_inactive(&d.opts);
let mut message = "code is inactive due to #[cfg] directives".to_string(); let mut message = "code is inactive due to #[cfg] directives".to_owned();
if let Some(inactive) = inactive { if let Some(inactive) = inactive {
let inactive_reasons = inactive.to_string(); let inactive_reasons = inactive.to_string();

View file

@ -9,7 +9,7 @@ pub(crate) fn incoherent_impl(ctx: &DiagnosticsContext<'_>, d: &hir::IncoherentI
Diagnostic::new_with_syntax_node_ptr( Diagnostic::new_with_syntax_node_ptr(
ctx, ctx,
DiagnosticCode::RustcHardError("E0210"), DiagnosticCode::RustcHardError("E0210"),
"cannot define inherent `impl` for foreign type".to_string(), "cannot define inherent `impl` for foreign type".to_owned(),
InFile::new(d.file_id, d.impl_.into()), InFile::new(d.file_id, d.impl_.into()),
) )
} }

View file

@ -512,7 +512,7 @@ impl BAD_TRAIT for () {
fn BadFunction() {} fn BadFunction() {}
} }
"#, "#,
std::iter::once("unused_variables".to_string()), std::iter::once("unused_variables".to_owned()),
); );
} }

View file

@ -42,12 +42,12 @@ impl State {
v.push("Deserialize"); v.push("Deserialize");
} }
match v.as_slice() { match v.as_slice() {
[] => "".to_string(), [] => "".to_owned(),
[x] => format!("#[derive({x})]\n"), [x] => format!("#[derive({x})]\n"),
[x, y] => format!("#[derive({x}, {y})]\n"), [x, y] => format!("#[derive({x}, {y})]\n"),
_ => { _ => {
never!(); never!();
"".to_string() "".to_owned()
} }
} }
} }
@ -176,7 +176,7 @@ mod tests {
#[test] #[test]
fn diagnostic_for_simple_case() { fn diagnostic_for_simple_case() {
let mut config = DiagnosticsConfig::test_sample(); let mut config = DiagnosticsConfig::test_sample();
config.disabled.insert("syntax-error".to_string()); config.disabled.insert("syntax-error".to_owned());
check_diagnostics_with_config( check_diagnostics_with_config(
config, config,
r#" r#"

View file

@ -99,7 +99,7 @@ pub macro panic {
// FIXME: This is a false-positive, the file is actually linked in via // FIXME: This is a false-positive, the file is actually linked in via
// `include!` macro // `include!` macro
config.disabled.insert("unlinked-file".to_string()); config.disabled.insert("unlinked-file".to_owned());
check_diagnostics_with_config( check_diagnostics_with_config(
config, config,
@ -268,8 +268,8 @@ fn f() {
#[test] #[test]
fn include_does_not_break_diagnostics() { fn include_does_not_break_diagnostics() {
let mut config = DiagnosticsConfig::test_sample(); let mut config = DiagnosticsConfig::test_sample();
config.disabled.insert("inactive-code".to_string()); config.disabled.insert("inactive-code".to_owned());
config.disabled.insert("unlinked-file".to_string()); config.disabled.insert("unlinked-file".to_owned());
check_diagnostics_with_config( check_diagnostics_with_config(
config, config,
r#" r#"

View file

@ -170,7 +170,7 @@ fn make_ty(ty: &hir::Type, db: &dyn HirDatabase, module: hir::Module) -> ast::Ty
let ty_str = match ty.as_adt() { let ty_str = match ty.as_adt() {
Some(adt) => adt.name(db).display(db.upcast()).to_string(), Some(adt) => adt.name(db).display(db.upcast()).to_string(),
None => { None => {
ty.display_source_code(db, module.into(), false).ok().unwrap_or_else(|| "_".to_string()) ty.display_source_code(db, module.into(), false).ok().unwrap_or_else(|| "_".to_owned())
} }
}; };

View file

@ -31,7 +31,7 @@ mod tests {
#[test] #[test]
fn empty_body() { fn empty_body() {
let mut config = DiagnosticsConfig::test_sample(); let mut config = DiagnosticsConfig::test_sample();
config.disabled.insert("syntax-error".to_string()); config.disabled.insert("syntax-error".to_owned());
check_diagnostics_with_config( check_diagnostics_with_config(
config, config,
r#" r#"

View file

@ -19,7 +19,7 @@ pub(crate) fn need_mut(ctx: &DiagnosticsContext<'_>, d: &hir::NeedMut) -> Diagno
for source in d.local.sources(ctx.sema.db) { for source in d.local.sources(ctx.sema.db) {
let Some(ast) = source.name() else { continue }; let Some(ast) = source.name() else { continue };
// FIXME: macros // FIXME: macros
edit_builder.insert(ast.value.syntax().text_range().start(), "mut ".to_string()); edit_builder.insert(ast.value.syntax().text_range().start(), "mut ".to_owned());
} }
let edit = edit_builder.finish(); let edit = edit_builder.finish();
Some(vec![fix( Some(vec![fix(
@ -448,7 +448,7 @@ fn main(b: bool) {
&mut x; &mut x;
} }
"#, "#,
std::iter::once("remove-unnecessary-else".to_string()), std::iter::once("remove-unnecessary-else".to_owned()),
); );
check_diagnostics_with_disabled( check_diagnostics_with_disabled(
r#" r#"
@ -463,7 +463,7 @@ fn main(b: bool) {
&mut x; &mut x;
} }
"#, "#,
std::iter::once("remove-unnecessary-else".to_string()), std::iter::once("remove-unnecessary-else".to_owned()),
); );
} }

View file

@ -140,7 +140,7 @@ fn foo(x: usize) -> u8 {
} //^^^^^^^^^ 💡 weak: replace return <expr>; with <expr> } //^^^^^^^^^ 💡 weak: replace return <expr>; with <expr>
} }
"#, "#,
std::iter::once("remove-unnecessary-else".to_string()), std::iter::once("remove-unnecessary-else".to_owned()),
); );
} }
@ -309,7 +309,7 @@ fn foo(x: usize) -> u8 {
} }
} }
"#, "#,
std::iter::once("remove-unnecessary-else".to_string()), std::iter::once("remove-unnecessary-else".to_owned()),
); );
check_fix( check_fix(
r#" r#"

View file

@ -90,7 +90,7 @@ mod tests {
use crate::tests::{check_diagnostics, check_diagnostics_with_disabled, check_fix}; use crate::tests::{check_diagnostics, check_diagnostics_with_disabled, check_fix};
fn check_diagnostics_with_needless_return_disabled(ra_fixture: &str) { fn check_diagnostics_with_needless_return_disabled(ra_fixture: &str) {
check_diagnostics_with_disabled(ra_fixture, std::iter::once("needless_return".to_string())); check_diagnostics_with_disabled(ra_fixture, std::iter::once("needless_return".to_owned()));
} }
#[test] #[test]

View file

@ -63,8 +63,8 @@ mod tests {
#[track_caller] #[track_caller]
pub(crate) fn check_diagnostics(ra_fixture: &str) { pub(crate) fn check_diagnostics(ra_fixture: &str) {
let mut config = DiagnosticsConfig::test_sample(); let mut config = DiagnosticsConfig::test_sample();
config.disabled.insert("inactive-code".to_string()); config.disabled.insert("inactive-code".to_owned());
config.disabled.insert("E0599".to_string()); config.disabled.insert("E0599".to_owned());
check_diagnostics_with_config(config, ra_fixture) check_diagnostics_with_config(config, ra_fixture)
} }

View file

@ -13,7 +13,7 @@ pub(crate) fn trait_impl_orphan(
ctx, ctx,
DiagnosticCode::RustcHardError("E0117"), DiagnosticCode::RustcHardError("E0117"),
"only traits defined in the current crate can be implemented for arbitrary types" "only traits defined in the current crate can be implemented for arbitrary types"
.to_string(), .to_owned(),
InFile::new(d.file_id, d.impl_.into()), InFile::new(d.file_id, d.impl_.into()),
) )
// Not yet checked for false positives // Not yet checked for false positives

View file

@ -103,7 +103,7 @@ fn quickfix_for_redundant_assoc_item(
Some(vec![Assist { Some(vec![Assist {
id: AssistId("add assoc item def into trait def", AssistKind::QuickFix), id: AssistId("add assoc item def into trait def", AssistKind::QuickFix),
label: Label::new("Add assoc item def into trait def".to_string()), label: Label::new("Add assoc item def into trait def".to_owned()),
group: None, group: None,
target: range, target: range,
source_change: Some(source_change_builder.finish()), source_change: Some(source_change_builder.finish()),

View file

@ -120,7 +120,7 @@ fn add_missing_ok_or_some(
let mut builder = TextEdit::builder(); let mut builder = TextEdit::builder();
builder.insert(expr.syntax().text_range().start(), format!("{variant_name}(")); builder.insert(expr.syntax().text_range().start(), format!("{variant_name}("));
builder.insert(expr.syntax().text_range().end(), ")".to_string()); builder.insert(expr.syntax().text_range().end(), ")".to_owned());
let source_change = let source_change =
SourceChange::from_text_edit(expr_ptr.file_id.original_file(ctx.sema.db), builder.finish()); SourceChange::from_text_edit(expr_ptr.file_id.original_file(ctx.sema.db), builder.finish());
let name = format!("Wrap in {variant_name}"); let name = format!("Wrap in {variant_name}");
@ -174,7 +174,7 @@ fn str_ref_to_owned(
let expr = expr_ptr.value.to_node(&root); let expr = expr_ptr.value.to_node(&root);
let expr_range = expr.syntax().text_range(); let expr_range = expr.syntax().text_range();
let to_owned = ".to_owned()".to_string(); let to_owned = ".to_owned()".to_owned();
let edit = TextEdit::insert(expr.syntax().text_range().end(), to_owned); let edit = TextEdit::insert(expr.syntax().text_range().end(), to_owned);
let source_change = let source_change =
@ -729,7 +729,7 @@ fn f() -> i32 {
} }
fn g() { return; } fn g() { return; }
"#, "#,
std::iter::once("needless_return".to_string()), std::iter::once("needless_return".to_owned()),
); );
} }

View file

@ -10,7 +10,7 @@ pub(crate) fn unimplemented_builtin_macro(
Diagnostic::new_with_syntax_node_ptr( Diagnostic::new_with_syntax_node_ptr(
ctx, ctx,
DiagnosticCode::Ra("unimplemented-builtin-macro", Severity::WeakWarning), DiagnosticCode::Ra("unimplemented-builtin-macro", Severity::WeakWarning),
"unimplemented built-in macro".to_string(), "unimplemented built-in macro".to_owned(),
d.node, d.node,
) )
} }

View file

@ -65,7 +65,7 @@ fn method_fix(
let FileRange { range, file_id } = ctx.sema.original_range_opt(expr.syntax())?; let FileRange { range, file_id } = ctx.sema.original_range_opt(expr.syntax())?;
Some(vec![Assist { Some(vec![Assist {
id: AssistId("expected-field-found-method-call-fix", AssistKind::QuickFix), id: AssistId("expected-field-found-method-call-fix", AssistKind::QuickFix),
label: Label::new("Use parentheses to call the method".to_string()), label: Label::new("Use parentheses to call the method".to_owned()),
group: None, group: None,
target: range, target: range,
source_change: Some(SourceChange::from_text_edit( source_change: Some(SourceChange::from_text_edit(

View file

@ -101,7 +101,7 @@ fn field_fix(
}; };
Some(Assist { Some(Assist {
id: AssistId("expected-method-found-field-fix", AssistKind::QuickFix), id: AssistId("expected-method-found-field-fix", AssistKind::QuickFix),
label: Label::new("Use parentheses to call the value of the field".to_string()), label: Label::new("Use parentheses to call the value of the field".to_owned()),
group: None, group: None,
target: range, target: range,
source_change: Some(SourceChange::from_iter([ source_change: Some(SourceChange::from_iter([

View file

@ -16,7 +16,7 @@ pub(crate) fn unresolved_module(
ctx, ctx,
DiagnosticCode::RustcHardError("E0583"), DiagnosticCode::RustcHardError("E0583"),
match &*d.candidates { match &*d.candidates {
[] => "unresolved module".to_string(), [] => "unresolved module".to_owned(),
[candidate] => format!("unresolved module, can't find module file: {candidate}"), [candidate] => format!("unresolved module, can't find module file: {candidate}"),
[candidates @ .., last] => { [candidates @ .., last] => {
format!( format!(
@ -46,7 +46,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::UnresolvedModule) -> Option<Vec<
anchor: d.decl.file_id.original_file(ctx.sema.db), anchor: d.decl.file_id.original_file(ctx.sema.db),
path: candidate.clone(), path: candidate.clone(),
}, },
initial_contents: "".to_string(), initial_contents: "".to_owned(),
} }
.into(), .into(),
unresolved_module.syntax().text_range(), unresolved_module.syntax().text_range(),

View file

@ -27,7 +27,7 @@ pub(crate) fn unresolved_proc_macro(
let not_expanded_message = match &d.macro_name { let not_expanded_message = match &d.macro_name {
Some(name) => format!("proc macro `{name}` not expanded"), Some(name) => format!("proc macro `{name}` not expanded"),
None => "proc macro not expanded".to_string(), None => "proc macro not expanded".to_owned(),
}; };
let severity = if config_enabled { Severity::Error } else { Severity::WeakWarning }; let severity = if config_enabled { Severity::Error } else { Severity::WeakWarning };
let def_map = ctx.sema.db.crate_def_map(d.krate); let def_map = ctx.sema.db.crate_def_map(d.krate);

View file

@ -40,7 +40,7 @@ pub(crate) fn useless_braces(
acc.push( acc.push(
Diagnostic::new( Diagnostic::new(
DiagnosticCode::RustcLint("unused_braces"), DiagnosticCode::RustcLint("unused_braces"),
"Unnecessary braces in use statement".to_string(), "Unnecessary braces in use statement".to_owned(),
FileRange { file_id, range: use_range }, FileRange { file_id, range: use_range },
) )
.with_main_node(InFile::new(file_id.into(), node.clone())) .with_main_node(InFile::new(file_id.into(), node.clone()))
@ -112,7 +112,7 @@ mod a {
); );
let mut config = DiagnosticsConfig::test_sample(); let mut config = DiagnosticsConfig::test_sample();
config.disabled.insert("syntax-error".to_string()); config.disabled.insert("syntax-error".to_owned());
check_diagnostics_with_config( check_diagnostics_with_config(
config, config,
r#" r#"

View file

@ -563,7 +563,7 @@ fn unresolved_fix(id: &'static str, label: &str, target: TextRange) -> Assist {
assert!(!id.contains(' ')); assert!(!id.contains(' '));
Assist { Assist {
id: AssistId(id, AssistKind::QuickFix), id: AssistId(id, AssistKind::QuickFix),
label: Label::new(label.to_string()), label: Label::new(label.to_owned()),
group: None, group: None,
target, target,
source_change: None, source_change: None,

View file

@ -108,7 +108,7 @@ pub(crate) fn check_no_fix(ra_fixture: &str) {
#[track_caller] #[track_caller]
pub(crate) fn check_diagnostics(ra_fixture: &str) { pub(crate) fn check_diagnostics(ra_fixture: &str) {
let mut config = DiagnosticsConfig::test_sample(); let mut config = DiagnosticsConfig::test_sample();
config.disabled.insert("inactive-code".to_string()); config.disabled.insert("inactive-code".to_owned());
check_diagnostics_with_config(config, ra_fixture) check_diagnostics_with_config(config, ra_fixture)
} }
@ -207,8 +207,8 @@ fn minicore_smoke_test() {
let source = minicore.source_code(); let source = minicore.source_code();
let mut config = DiagnosticsConfig::test_sample(); let mut config = DiagnosticsConfig::test_sample();
// This should be ignored since we conditionally remove code which creates single item use with braces // This should be ignored since we conditionally remove code which creates single item use with braces
config.disabled.insert("unused_braces".to_string()); config.disabled.insert("unused_braces".to_owned());
config.disabled.insert("unused_variables".to_string()); config.disabled.insert("unused_variables".to_owned());
check_diagnostics_with_config(config, &source); check_diagnostics_with_config(config, &source);
} }