mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 21:13:37 +00:00
ide-diagnostics: Fix warnings about clippy str_to_string
rule
This commit is contained in:
parent
eba1b13295
commit
d00f1c1b16
22 changed files with 36 additions and 36 deletions
|
@ -16,7 +16,7 @@ pub(crate) fn inactive_code(
|
|||
}
|
||||
|
||||
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 {
|
||||
let inactive_reasons = inactive.to_string();
|
||||
|
|
|
@ -9,7 +9,7 @@ pub(crate) fn incoherent_impl(ctx: &DiagnosticsContext<'_>, d: &hir::IncoherentI
|
|||
Diagnostic::new_with_syntax_node_ptr(
|
||||
ctx,
|
||||
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()),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -512,7 +512,7 @@ impl BAD_TRAIT for () {
|
|||
fn BadFunction() {}
|
||||
}
|
||||
"#,
|
||||
std::iter::once("unused_variables".to_string()),
|
||||
std::iter::once("unused_variables".to_owned()),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -42,12 +42,12 @@ impl State {
|
|||
v.push("Deserialize");
|
||||
}
|
||||
match v.as_slice() {
|
||||
[] => "".to_string(),
|
||||
[] => "".to_owned(),
|
||||
[x] => format!("#[derive({x})]\n"),
|
||||
[x, y] => format!("#[derive({x}, {y})]\n"),
|
||||
_ => {
|
||||
never!();
|
||||
"".to_string()
|
||||
"".to_owned()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ mod tests {
|
|||
#[test]
|
||||
fn diagnostic_for_simple_case() {
|
||||
let mut config = DiagnosticsConfig::test_sample();
|
||||
config.disabled.insert("syntax-error".to_string());
|
||||
config.disabled.insert("syntax-error".to_owned());
|
||||
check_diagnostics_with_config(
|
||||
config,
|
||||
r#"
|
||||
|
|
|
@ -99,7 +99,7 @@ pub macro panic {
|
|||
|
||||
// FIXME: This is a false-positive, the file is actually linked in via
|
||||
// `include!` macro
|
||||
config.disabled.insert("unlinked-file".to_string());
|
||||
config.disabled.insert("unlinked-file".to_owned());
|
||||
|
||||
check_diagnostics_with_config(
|
||||
config,
|
||||
|
@ -268,8 +268,8 @@ fn f() {
|
|||
#[test]
|
||||
fn include_does_not_break_diagnostics() {
|
||||
let mut config = DiagnosticsConfig::test_sample();
|
||||
config.disabled.insert("inactive-code".to_string());
|
||||
config.disabled.insert("unlinked-file".to_string());
|
||||
config.disabled.insert("inactive-code".to_owned());
|
||||
config.disabled.insert("unlinked-file".to_owned());
|
||||
check_diagnostics_with_config(
|
||||
config,
|
||||
r#"
|
||||
|
|
|
@ -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() {
|
||||
Some(adt) => adt.name(db).display(db.upcast()).to_string(),
|
||||
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())
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ mod tests {
|
|||
#[test]
|
||||
fn empty_body() {
|
||||
let mut config = DiagnosticsConfig::test_sample();
|
||||
config.disabled.insert("syntax-error".to_string());
|
||||
config.disabled.insert("syntax-error".to_owned());
|
||||
check_diagnostics_with_config(
|
||||
config,
|
||||
r#"
|
||||
|
|
|
@ -19,7 +19,7 @@ pub(crate) fn need_mut(ctx: &DiagnosticsContext<'_>, d: &hir::NeedMut) -> Diagno
|
|||
for source in d.local.sources(ctx.sema.db) {
|
||||
let Some(ast) = source.name() else { continue };
|
||||
// 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();
|
||||
Some(vec![fix(
|
||||
|
@ -448,7 +448,7 @@ fn main(b: bool) {
|
|||
&mut x;
|
||||
}
|
||||
"#,
|
||||
std::iter::once("remove-unnecessary-else".to_string()),
|
||||
std::iter::once("remove-unnecessary-else".to_owned()),
|
||||
);
|
||||
check_diagnostics_with_disabled(
|
||||
r#"
|
||||
|
@ -463,7 +463,7 @@ fn main(b: bool) {
|
|||
&mut x;
|
||||
}
|
||||
"#,
|
||||
std::iter::once("remove-unnecessary-else".to_string()),
|
||||
std::iter::once("remove-unnecessary-else".to_owned()),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -140,7 +140,7 @@ fn foo(x: usize) -> u8 {
|
|||
} //^^^^^^^^^ 💡 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(
|
||||
r#"
|
||||
|
|
|
@ -90,7 +90,7 @@ mod tests {
|
|||
use crate::tests::{check_diagnostics, check_diagnostics_with_disabled, check_fix};
|
||||
|
||||
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]
|
||||
|
|
|
@ -63,8 +63,8 @@ mod tests {
|
|||
#[track_caller]
|
||||
pub(crate) fn check_diagnostics(ra_fixture: &str) {
|
||||
let mut config = DiagnosticsConfig::test_sample();
|
||||
config.disabled.insert("inactive-code".to_string());
|
||||
config.disabled.insert("E0599".to_string());
|
||||
config.disabled.insert("inactive-code".to_owned());
|
||||
config.disabled.insert("E0599".to_owned());
|
||||
check_diagnostics_with_config(config, ra_fixture)
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ pub(crate) fn trait_impl_orphan(
|
|||
ctx,
|
||||
DiagnosticCode::RustcHardError("E0117"),
|
||||
"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()),
|
||||
)
|
||||
// Not yet checked for false positives
|
||||
|
|
|
@ -103,7 +103,7 @@ fn quickfix_for_redundant_assoc_item(
|
|||
|
||||
Some(vec![Assist {
|
||||
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,
|
||||
target: range,
|
||||
source_change: Some(source_change_builder.finish()),
|
||||
|
|
|
@ -120,7 +120,7 @@ fn add_missing_ok_or_some(
|
|||
|
||||
let mut builder = TextEdit::builder();
|
||||
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 =
|
||||
SourceChange::from_text_edit(expr_ptr.file_id.original_file(ctx.sema.db), builder.finish());
|
||||
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_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 source_change =
|
||||
|
@ -729,7 +729,7 @@ fn f() -> i32 {
|
|||
}
|
||||
fn g() { return; }
|
||||
"#,
|
||||
std::iter::once("needless_return".to_string()),
|
||||
std::iter::once("needless_return".to_owned()),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ pub(crate) fn unimplemented_builtin_macro(
|
|||
Diagnostic::new_with_syntax_node_ptr(
|
||||
ctx,
|
||||
DiagnosticCode::Ra("unimplemented-builtin-macro", Severity::WeakWarning),
|
||||
"unimplemented built-in macro".to_string(),
|
||||
"unimplemented built-in macro".to_owned(),
|
||||
d.node,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ fn method_fix(
|
|||
let FileRange { range, file_id } = ctx.sema.original_range_opt(expr.syntax())?;
|
||||
Some(vec![Assist {
|
||||
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,
|
||||
target: range,
|
||||
source_change: Some(SourceChange::from_text_edit(
|
||||
|
|
|
@ -101,7 +101,7 @@ fn field_fix(
|
|||
};
|
||||
Some(Assist {
|
||||
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,
|
||||
target: range,
|
||||
source_change: Some(SourceChange::from_iter([
|
||||
|
|
|
@ -16,7 +16,7 @@ pub(crate) fn unresolved_module(
|
|||
ctx,
|
||||
DiagnosticCode::RustcHardError("E0583"),
|
||||
match &*d.candidates {
|
||||
[] => "unresolved module".to_string(),
|
||||
[] => "unresolved module".to_owned(),
|
||||
[candidate] => format!("unresolved module, can't find module file: {candidate}"),
|
||||
[candidates @ .., last] => {
|
||||
format!(
|
||||
|
@ -46,7 +46,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::UnresolvedModule) -> Option<Vec<
|
|||
anchor: d.decl.file_id.original_file(ctx.sema.db),
|
||||
path: candidate.clone(),
|
||||
},
|
||||
initial_contents: "".to_string(),
|
||||
initial_contents: "".to_owned(),
|
||||
}
|
||||
.into(),
|
||||
unresolved_module.syntax().text_range(),
|
||||
|
|
|
@ -27,7 +27,7 @@ pub(crate) fn unresolved_proc_macro(
|
|||
|
||||
let not_expanded_message = match &d.macro_name {
|
||||
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 def_map = ctx.sema.db.crate_def_map(d.krate);
|
||||
|
|
|
@ -40,7 +40,7 @@ pub(crate) fn useless_braces(
|
|||
acc.push(
|
||||
Diagnostic::new(
|
||||
DiagnosticCode::RustcLint("unused_braces"),
|
||||
"Unnecessary braces in use statement".to_string(),
|
||||
"Unnecessary braces in use statement".to_owned(),
|
||||
FileRange { file_id, range: use_range },
|
||||
)
|
||||
.with_main_node(InFile::new(file_id.into(), node.clone()))
|
||||
|
@ -112,7 +112,7 @@ mod a {
|
|||
);
|
||||
|
||||
let mut config = DiagnosticsConfig::test_sample();
|
||||
config.disabled.insert("syntax-error".to_string());
|
||||
config.disabled.insert("syntax-error".to_owned());
|
||||
check_diagnostics_with_config(
|
||||
config,
|
||||
r#"
|
||||
|
|
|
@ -563,7 +563,7 @@ fn unresolved_fix(id: &'static str, label: &str, target: TextRange) -> Assist {
|
|||
assert!(!id.contains(' '));
|
||||
Assist {
|
||||
id: AssistId(id, AssistKind::QuickFix),
|
||||
label: Label::new(label.to_string()),
|
||||
label: Label::new(label.to_owned()),
|
||||
group: None,
|
||||
target,
|
||||
source_change: None,
|
||||
|
|
|
@ -108,7 +108,7 @@ pub(crate) fn check_no_fix(ra_fixture: &str) {
|
|||
#[track_caller]
|
||||
pub(crate) fn check_diagnostics(ra_fixture: &str) {
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -207,8 +207,8 @@ fn minicore_smoke_test() {
|
|||
let source = minicore.source_code();
|
||||
let mut config = DiagnosticsConfig::test_sample();
|
||||
// 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_variables".to_string());
|
||||
config.disabled.insert("unused_braces".to_owned());
|
||||
config.disabled.insert("unused_variables".to_owned());
|
||||
check_diagnostics_with_config(config, &source);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue