From 7c34eb38807f86df2fb3b344a2dbdfa90b223259 Mon Sep 17 00:00:00 2001 From: Hamir Mahal Date: Thu, 30 May 2024 16:18:49 -0700 Subject: [PATCH] style: simplify string interpolation --- crates/flycheck/src/lib.rs | 7 +++---- crates/hir-ty/src/consteval/tests.rs | 6 +++--- crates/hir-ty/src/display.rs | 2 +- crates/hir-ty/src/mir/eval.rs | 4 ++-- crates/hir-ty/src/mir/eval/tests.rs | 2 +- crates/hir-ty/src/mir/lower.rs | 2 +- crates/hir/src/lib.rs | 4 ++-- crates/ide-assists/src/handlers/auto_import.rs | 4 ++-- .../ide-assists/src/handlers/bool_to_enum.rs | 4 ++-- .../src/handlers/destructure_struct_binding.rs | 2 +- .../src/handlers/generate_delegate_trait.rs | 2 +- .../src/handlers/generate_getter_or_setter.rs | 2 +- .../src/handlers/generate_mut_trait_impl.rs | 2 +- .../src/handlers/into_to_qualified_from.rs | 4 ++-- .../src/handlers/merge_nested_if.rs | 2 +- .../src/handlers/remove_parentheses.rs | 2 +- .../src/completions/postfix/format_like.rs | 4 ++-- .../src/handlers/json_is_not_rust.rs | 2 +- .../trait_impl_redundant_assoc_item.rs | 6 +++--- .../src/handlers/unresolved_method.rs | 7 +++---- crates/ide/src/interpret_function.rs | 2 +- crates/ide/src/view_memory_layout.rs | 2 +- crates/parser/src/grammar.rs | 2 +- crates/paths/src/lib.rs | 2 +- crates/proc-macro-api/src/process.rs | 3 +-- crates/project-model/src/sysroot.rs | 3 +-- crates/project-model/src/tests.rs | 2 +- crates/rust-analyzer/src/cli/analysis_stats.rs | 2 +- crates/rust-analyzer/src/cli/run_tests.rs | 4 ++-- crates/rust-analyzer/src/cli/rustc_tests.rs | 4 ++-- crates/rust-analyzer/src/tracing/hprof.rs | 2 +- crates/salsa/salsa-macros/src/query_group.rs | 18 ++++++++---------- crates/salsa/tests/cycles.rs | 2 +- crates/salsa/tests/incremental/constants.rs | 4 ++-- .../salsa/tests/incremental/implementation.rs | 8 ++++---- .../parallel/parallel_cycle_none_recover.rs | 2 +- crates/salsa/tests/parallel/race.rs | 2 +- crates/span/src/lib.rs | 2 +- crates/syntax/src/ast/make.rs | 4 ++-- crates/test-fixture/src/lib.rs | 2 +- crates/test-utils/src/fixture.rs | 2 +- lib/lsp-server/src/lib.rs | 3 +-- xtask/src/metrics.rs | 2 +- 43 files changed, 71 insertions(+), 78 deletions(-) diff --git a/crates/flycheck/src/lib.rs b/crates/flycheck/src/lib.rs index 6d5ca8321e..434e0e4d70 100644 --- a/crates/flycheck/src/lib.rs +++ b/crates/flycheck/src/lib.rs @@ -288,7 +288,7 @@ impl FlycheckActor { Some(c) => c, None => continue, }; - let formatted_command = format!("{:?}", command); + let formatted_command = format!("{command:?}"); tracing::debug!(?command, "will restart flycheck"); let (sender, receiver) = unbounded(); @@ -301,8 +301,7 @@ impl FlycheckActor { } Err(error) => { self.report_progress(Progress::DidFailToRestart(format!( - "Failed to run the following command: {} error={}", - formatted_command, error + "Failed to run the following command: {formatted_command} error={error}" ))); } } @@ -313,7 +312,7 @@ impl FlycheckActor { // Watcher finished let command_handle = self.command_handle.take().unwrap(); self.command_receiver.take(); - let formatted_handle = format!("{:?}", command_handle); + let formatted_handle = format!("{command_handle:?}"); let res = command_handle.join(); if let Err(error) = &res { diff --git a/crates/hir-ty/src/consteval/tests.rs b/crates/hir-ty/src/consteval/tests.rs index d1ffd5046c..1b4584a18d 100644 --- a/crates/hir-ty/src/consteval/tests.rs +++ b/crates/hir-ty/src/consteval/tests.rs @@ -73,7 +73,7 @@ fn check_answer(ra_fixture: &str, check: impl FnOnce(&[u8], &MemoryMap)) { Ok(t) => t, Err(e) => { let err = pretty_print_err(e, db); - panic!("Error in evaluating goal: {}", err); + panic!("Error in evaluating goal: {err}"); } }; match &r.data(Interner).value { @@ -81,7 +81,7 @@ fn check_answer(ra_fixture: &str, check: impl FnOnce(&[u8], &MemoryMap)) { ConstScalar::Bytes(b, mm) => { check(b, mm); } - x => panic!("Expected number but found {:?}", x), + x => panic!("Expected number but found {x:?}"), }, _ => panic!("result of const eval wasn't a concrete const"), } @@ -89,7 +89,7 @@ fn check_answer(ra_fixture: &str, check: impl FnOnce(&[u8], &MemoryMap)) { fn pretty_print_err(e: ConstEvalError, db: TestDB) -> String { let mut err = String::new(); - let span_formatter = |file, range| format!("{:?} {:?}", file, range); + let span_formatter = |file, range| format!("{file:?} {range:?}"); match e { ConstEvalError::MirLowerError(e) => e.pretty_print(&mut err, &db, span_formatter), ConstEvalError::MirEvalError(e) => e.pretty_print(&mut err, &db, span_formatter), diff --git a/crates/hir-ty/src/display.rs b/crates/hir-ty/src/display.rs index 5a9621bb69..0027eb56a8 100644 --- a/crates/hir-ty/src/display.rs +++ b/crates/hir-ty/src/display.rs @@ -670,7 +670,7 @@ fn render_const_scalar( TyKind::FnDef(..) => ty.hir_fmt(f), TyKind::Function(_) | TyKind::Raw(_, _) => { let it = u128::from_le_bytes(pad16(b, false)); - write!(f, "{:#X} as ", it)?; + write!(f, "{it:#X} as ")?; ty.hir_fmt(f) } TyKind::Array(ty, len) => { diff --git a/crates/hir-ty/src/mir/eval.rs b/crates/hir-ty/src/mir/eval.rs index 2de1aa30c9..4ee96a66a3 100644 --- a/crates/hir-ty/src/mir/eval.rs +++ b/crates/hir-ty/src/mir/eval.rs @@ -363,7 +363,7 @@ impl MirEvalError { )?; } Either::Right(closure) => { - writeln!(f, "In {:?}", closure)?; + writeln!(f, "In {closure:?}")?; } } let source_map = db.body_with_source_map(*def).1; @@ -424,7 +424,7 @@ impl MirEvalError { | MirEvalError::StackOverflow | MirEvalError::CoerceUnsizedError(_) | MirEvalError::InternalError(_) - | MirEvalError::InvalidVTableId(_) => writeln!(f, "{:?}", err)?, + | MirEvalError::InvalidVTableId(_) => writeln!(f, "{err:?}")?, } Ok(()) } diff --git a/crates/hir-ty/src/mir/eval/tests.rs b/crates/hir-ty/src/mir/eval/tests.rs index 4abbda56cb..c3b35cd553 100644 --- a/crates/hir-ty/src/mir/eval/tests.rs +++ b/crates/hir-ty/src/mir/eval/tests.rs @@ -77,7 +77,7 @@ fn check_panic(ra_fixture: &str, expected_panic: &str) { let (db, file_ids) = TestDB::with_many_files(ra_fixture); let file_id = *file_ids.last().unwrap(); let e = eval_main(&db, file_id).unwrap_err(); - assert_eq!(e.is_panic().unwrap_or_else(|| panic!("unexpected error: {:?}", e)), expected_panic); + assert_eq!(e.is_panic().unwrap_or_else(|| panic!("unexpected error: {e:?}")), expected_panic); } #[test] diff --git a/crates/hir-ty/src/mir/lower.rs b/crates/hir-ty/src/mir/lower.rs index 151f65cfbb..95b16ca8bc 100644 --- a/crates/hir-ty/src/mir/lower.rs +++ b/crates/hir-ty/src/mir/lower.rs @@ -213,7 +213,7 @@ impl MirLowerError { | MirLowerError::LangItemNotFound(_) | MirLowerError::MutatingRvalue | MirLowerError::UnresolvedLabel - | MirLowerError::UnresolvedUpvar(_) => writeln!(f, "{:?}", self)?, + | MirLowerError::UnresolvedUpvar(_) => writeln!(f, "{self:?}")?, } Ok(()) } diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 777be711a5..d28c45edd7 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -2414,9 +2414,9 @@ impl Const { let value_signed = i128::from_le_bytes(mir::pad16(b, matches!(s, Scalar::Int(_)))); if value >= 10 { - return Ok(format!("{} ({:#X})", value_signed, value)); + return Ok(format!("{value_signed} ({value:#X})")); } else { - return Ok(format!("{}", value_signed)); + return Ok(format!("{value_signed}")); } } } diff --git a/crates/ide-assists/src/handlers/auto_import.rs b/crates/ide-assists/src/handlers/auto_import.rs index 3bd003a267..650b4279ea 100644 --- a/crates/ide-assists/src/handlers/auto_import.rs +++ b/crates/ide-assists/src/handlers/auto_import.rs @@ -140,7 +140,7 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option< acc.add_group( &group_label, assist_id, - format!("Import `{}`", import_name), + format!("Import `{import_name}`"), range, |builder| { let scope = match scope.clone() { @@ -165,7 +165,7 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option< acc.add_group( &group_label, assist_id, - format!("Import `{} as _`", import_name), + format!("Import `{import_name} as _`"), range, |builder| { let scope = match scope.clone() { diff --git a/crates/ide-assists/src/handlers/bool_to_enum.rs b/crates/ide-assists/src/handlers/bool_to_enum.rs index 71436e6580..c95e24693d 100644 --- a/crates/ide-assists/src/handlers/bool_to_enum.rs +++ b/crates/ide-assists/src/handlers/bool_to_enum.rs @@ -228,7 +228,7 @@ fn replace_usages( edit.replace( prefix_expr.syntax().text_range(), - format!("{} == Bool::False", inner_expr), + format!("{inner_expr} == Bool::False"), ); } else if let Some((record_field, initializer)) = name .as_name_ref() @@ -275,7 +275,7 @@ fn replace_usages( } else if let Some(receiver) = find_method_call_expr_usage(&name) { edit.replace( receiver.syntax().text_range(), - format!("({} == Bool::True)", receiver), + format!("({receiver} == Bool::True)"), ); } else if name.syntax().ancestors().find_map(ast::UseTree::cast).is_none() { // for any other usage in an expression, replace it with a check that it is the true variant diff --git a/crates/ide-assists/src/handlers/destructure_struct_binding.rs b/crates/ide-assists/src/handlers/destructure_struct_binding.rs index 9adbdd220c..7618871552 100644 --- a/crates/ide-assists/src/handlers/destructure_struct_binding.rs +++ b/crates/ide-assists/src/handlers/destructure_struct_binding.rs @@ -242,7 +242,7 @@ fn generate_field_names(ctx: &AssistContext<'_>, data: &StructEditData) -> Vec<( .iter() .enumerate() .map(|(index, _)| { - let new_name = new_field_name((format!("_{}", index)).into(), &data.names_in_scope); + let new_name = new_field_name((format!("_{index}")).into(), &data.names_in_scope); (index.to_string().into(), new_name) }) .collect(), diff --git a/crates/ide-assists/src/handlers/generate_delegate_trait.rs b/crates/ide-assists/src/handlers/generate_delegate_trait.rs index 748acb46ef..19521b8a4b 100644 --- a/crates/ide-assists/src/handlers/generate_delegate_trait.rs +++ b/crates/ide-assists/src/handlers/generate_delegate_trait.rs @@ -758,7 +758,7 @@ fn ty_assoc_item(item: syntax::ast::TypeAlias, qual_path_ty: Path) -> Option ast::Path { - make::path_from_text(&format!("{}::{}", qual_path_ty, path_expr_seg)) + make::path_from_text(&format!("{qual_path_ty}::{path_expr_seg}")) } #[cfg(test)] diff --git a/crates/ide-assists/src/handlers/generate_getter_or_setter.rs b/crates/ide-assists/src/handlers/generate_getter_or_setter.rs index e90a032f1c..60214aaaf6 100644 --- a/crates/ide-assists/src/handlers/generate_getter_or_setter.rs +++ b/crates/ide-assists/src/handlers/generate_getter_or_setter.rs @@ -47,7 +47,7 @@ pub(crate) fn generate_setter(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opt } // Prepend set_ to fn names. - fn_names.iter_mut().for_each(|name| *name = format!("set_{}", name)); + fn_names.iter_mut().for_each(|name| *name = format!("set_{name}")); // Return early if we've found an existing fn let impl_def = find_struct_impl(ctx, &ast::Adt::Struct(strukt.clone()), &fn_names)?; diff --git a/crates/ide-assists/src/handlers/generate_mut_trait_impl.rs b/crates/ide-assists/src/handlers/generate_mut_trait_impl.rs index 91eaa96b6c..6aa561ad7f 100644 --- a/crates/ide-assists/src/handlers/generate_mut_trait_impl.rs +++ b/crates/ide-assists/src/handlers/generate_mut_trait_impl.rs @@ -105,7 +105,7 @@ pub(crate) fn generate_mut_trait_impl(acc: &mut Assists, ctx: &AssistContext<'_> "Generate `IndexMut` impl from this `Index` trait", target, |edit| { - edit.insert(target.start(), format!("$0{}\n\n", impl_def)); + edit.insert(target.start(), format!("$0{impl_def}\n\n")); }, ) } diff --git a/crates/ide-assists/src/handlers/into_to_qualified_from.rs b/crates/ide-assists/src/handlers/into_to_qualified_from.rs index dee74afcbe..e405af5533 100644 --- a/crates/ide-assists/src/handlers/into_to_qualified_from.rs +++ b/crates/ide-assists/src/handlers/into_to_qualified_from.rs @@ -67,9 +67,9 @@ pub(crate) fn into_to_qualified_from(acc: &mut Assists, ctx: &AssistContext<'_>) edit.replace( method_call.syntax().text_range(), if sc.chars().all(|c| c.is_alphanumeric() || c == ':') { - format!("{}::from({})", sc, receiver) + format!("{sc}::from({receiver})") } else { - format!("<{}>::from({})", sc, receiver) + format!("<{sc}>::from({receiver})") }, ); }, diff --git a/crates/ide-assists/src/handlers/merge_nested_if.rs b/crates/ide-assists/src/handlers/merge_nested_if.rs index 2f3136f027..7a0037fa20 100644 --- a/crates/ide-assists/src/handlers/merge_nested_if.rs +++ b/crates/ide-assists/src/handlers/merge_nested_if.rs @@ -86,7 +86,7 @@ pub(crate) fn merge_nested_if(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opt nested_if_cond.syntax().text().to_string() }; - let replace_cond = format!("{} && {}", cond_text, nested_if_cond_text); + let replace_cond = format!("{cond_text} && {nested_if_cond_text}"); edit.replace(cond_range, replace_cond); edit.replace(then_branch_range, nested_if_then_branch.syntax().text()); diff --git a/crates/ide-assists/src/handlers/remove_parentheses.rs b/crates/ide-assists/src/handlers/remove_parentheses.rs index 99c55e9ff7..799d36be93 100644 --- a/crates/ide-assists/src/handlers/remove_parentheses.rs +++ b/crates/ide-assists/src/handlers/remove_parentheses.rs @@ -48,7 +48,7 @@ pub(crate) fn remove_parentheses(acc: &mut Assists, ctx: &AssistContext<'_>) -> } None => false, }; - let expr = if need_to_add_ws { format!(" {}", expr) } else { expr.to_string() }; + let expr = if need_to_add_ws { format!(" {expr}") } else { expr.to_string() }; builder.replace(parens.syntax().text_range(), expr) }, diff --git a/crates/ide-completion/src/completions/postfix/format_like.rs b/crates/ide-completion/src/completions/postfix/format_like.rs index fd50fd4e8c..2755329bb3 100644 --- a/crates/ide-completion/src/completions/postfix/format_like.rs +++ b/crates/ide-completion/src/completions/postfix/format_like.rs @@ -65,7 +65,7 @@ pub(crate) fn add_format_like_completions( let exprs = with_placeholders(exprs); for (label, macro_name) in KINDS { let snippet = if exprs.is_empty() { - format!(r#"{}({})"#, macro_name, out) + format!(r#"{macro_name}({out})"#) } else { format!(r#"{}({}, {})"#, macro_name, out, exprs.join(", ")) }; @@ -108,7 +108,7 @@ mod tests { for (kind, input, output) in test_vector { let (parsed_string, _exprs) = parse_format_exprs(input).unwrap(); - let snippet = format!(r#"{}("{}")"#, kind, parsed_string); + let snippet = format!(r#"{kind}("{parsed_string}")"#); assert_eq!(&snippet, output); } } diff --git a/crates/ide-diagnostics/src/handlers/json_is_not_rust.rs b/crates/ide-diagnostics/src/handlers/json_is_not_rust.rs index 132b93df10..2b8779044f 100644 --- a/crates/ide-diagnostics/src/handlers/json_is_not_rust.rs +++ b/crates/ide-diagnostics/src/handlers/json_is_not_rust.rs @@ -37,7 +37,7 @@ impl State { self.names.insert(name.clone(), 1); 1 }; - make::name(&format!("{}{}", name, count)) + make::name(&format!("{name}{count}")) } fn serde_derive(&self) -> String { diff --git a/crates/ide-diagnostics/src/handlers/trait_impl_redundant_assoc_item.rs b/crates/ide-diagnostics/src/handlers/trait_impl_redundant_assoc_item.rs index 00710ef507..be1e6ed572 100644 --- a/crates/ide-diagnostics/src/handlers/trait_impl_redundant_assoc_item.rs +++ b/crates/ide-diagnostics/src/handlers/trait_impl_redundant_assoc_item.rs @@ -27,7 +27,7 @@ pub(crate) fn trait_impl_redundant_assoc_item( hir::AssocItem::Function(id) => { let function = id; ( - format!("`fn {}`", redundant_assoc_item_name), + format!("`fn {redundant_assoc_item_name}`"), function .source(db) .map(|it| it.syntax().value.text_range()) @@ -38,7 +38,7 @@ pub(crate) fn trait_impl_redundant_assoc_item( hir::AssocItem::Const(id) => { let constant = id; ( - format!("`const {}`", redundant_assoc_item_name), + format!("`const {redundant_assoc_item_name}`"), constant .source(db) .map(|it| it.syntax().value.text_range()) @@ -49,7 +49,7 @@ pub(crate) fn trait_impl_redundant_assoc_item( hir::AssocItem::TypeAlias(id) => { let type_alias = id; ( - format!("`type {}`", redundant_assoc_item_name), + format!("`type {redundant_assoc_item_name}`"), type_alias .source(db) .map(|it| it.syntax().value.text_range()) diff --git a/crates/ide-diagnostics/src/handlers/unresolved_method.rs b/crates/ide-diagnostics/src/handlers/unresolved_method.rs index 0614fdc551..4f5ad685a4 100644 --- a/crates/ide-diagnostics/src/handlers/unresolved_method.rs +++ b/crates/ide-diagnostics/src/handlers/unresolved_method.rs @@ -162,11 +162,11 @@ fn assoc_func_fix(ctx: &DiagnosticsContext<'_>, d: &hir::UnresolvedMethodCall) - if !need_to_take_receiver_as_first_arg && !generic_parameters.is_empty() { let generic_parameters = generic_parameters.join(", "); receiver_type_adt_name = - format!("{}::<{}>", receiver_type_adt_name, generic_parameters); + format!("{receiver_type_adt_name}::<{generic_parameters}>"); } let method_name = call.name_ref()?; - let assoc_func_call = format!("{}::{}()", receiver_type_adt_name, method_name); + let assoc_func_call = format!("{receiver_type_adt_name}::{method_name}()"); let assoc_func_call = make::expr_path(make::path_from_text(&assoc_func_call)); @@ -184,8 +184,7 @@ fn assoc_func_fix(ctx: &DiagnosticsContext<'_>, d: &hir::UnresolvedMethodCall) - Some(Assist { id: AssistId("method_call_to_assoc_func_call_fix", AssistKind::QuickFix), label: Label::new(format!( - "Use associated func call instead: `{}`", - assoc_func_call_expr_string + "Use associated func call instead: `{assoc_func_call_expr_string}`" )), group: None, target: range, diff --git a/crates/ide/src/interpret_function.rs b/crates/ide/src/interpret_function.rs index df444a3f4d..7bd2da9f88 100644 --- a/crates/ide/src/interpret_function.rs +++ b/crates/ide/src/interpret_function.rs @@ -43,7 +43,7 @@ fn find_and_interpret(db: &RootDatabase, position: FilePosition) -> Option"); match db.line_index(file_id).try_line_col(text_range.start()) { Some(line_col) => format!("file://{path}#{}:{}", line_col.line + 1, line_col.col), - None => format!("file://{path} range {:?}", text_range), + None => format!("file://{path} range {text_range:?}"), } }; Some(def.eval(db, span_formatter)) diff --git a/crates/ide/src/view_memory_layout.rs b/crates/ide/src/view_memory_layout.rs index a229bc87c8..826447d058 100644 --- a/crates/ide/src/view_memory_layout.rs +++ b/crates/ide/src/view_memory_layout.rs @@ -40,7 +40,7 @@ impl fmt::Display for RecursiveMemoryLayout { "{}: {} (size: {}, align: {}, field offset: {})\n", node.item_name, node.typename, node.size, node.alignment, node.offset ); - write!(fmt, "{}", out)?; + write!(fmt, "{out}")?; if node.children_start != -1 { for j in nodes[idx].children_start ..(nodes[idx].children_start + nodes[idx].children_len as i64) diff --git a/crates/parser/src/grammar.rs b/crates/parser/src/grammar.rs index 4e5837312f..b342e35488 100644 --- a/crates/parser/src/grammar.rs +++ b/crates/parser/src/grammar.rs @@ -418,7 +418,7 @@ fn delimited( } if !p.eat(delim) { if p.at_ts(first_set) { - p.error(format!("expected {:?}", delim)); + p.error(format!("expected {delim:?}")); } else { break; } diff --git a/crates/paths/src/lib.rs b/crates/paths/src/lib.rs index 2d3653401d..4c79d67d5b 100644 --- a/crates/paths/src/lib.rs +++ b/crates/paths/src/lib.rs @@ -106,7 +106,7 @@ impl AbsPathBuf { /// Panics if `path` is not absolute. pub fn assert(path: Utf8PathBuf) -> AbsPathBuf { AbsPathBuf::try_from(path) - .unwrap_or_else(|path| panic!("expected absolute path, got {}", path)) + .unwrap_or_else(|path| panic!("expected absolute path, got {path}")) } /// Wrap the given absolute path in `AbsPathBuf` diff --git a/crates/proc-macro-api/src/process.rs b/crates/proc-macro-api/src/process.rs index dce086d429..718a96dc80 100644 --- a/crates/proc-macro-api/src/process.rs +++ b/crates/proc-macro-api/src/process.rs @@ -50,8 +50,7 @@ impl ProcMacroProcessSrv { Ok(v) if v > CURRENT_API_VERSION => Err(io::Error::new( io::ErrorKind::Other, format!( - "proc-macro server's api version ({}) is newer than rust-analyzer's ({})", - v, CURRENT_API_VERSION + "proc-macro server's api version ({v}) is newer than rust-analyzer's ({CURRENT_API_VERSION})" ), )), Ok(v) => { diff --git a/crates/project-model/src/sysroot.rs b/crates/project-model/src/sysroot.rs index 653e7157bc..1eeec4cede 100644 --- a/crates/project-model/src/sysroot.rs +++ b/crates/project-model/src/sysroot.rs @@ -219,8 +219,7 @@ impl Sysroot { ", try running `rustup component add rust-src` to possibly fix this" }; sysroot.error = Some(format!( - "sysroot at `{}` is missing a `core` library{var_note}", - src_root, + "sysroot at `{src_root}` is missing a `core` library{var_note}", )); } } diff --git a/crates/project-model/src/tests.rs b/crates/project-model/src/tests.rs index a6730863d6..2762de5997 100644 --- a/crates/project-model/src/tests.rs +++ b/crates/project-model/src/tests.rs @@ -126,7 +126,7 @@ fn replace_fake_sys_root(s: &mut String) { let fake_sysroot_path = get_test_path("fake-sysroot"); let fake_sysroot_path = if cfg!(windows) { let normalized_path = fake_sysroot_path.as_str().replace('\\', r#"\\"#); - format!(r#"{}\\"#, normalized_path) + format!(r#"{normalized_path}\\"#) } else { format!("{}/", fake_sysroot_path.as_str()) }; diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs index bded41932c..932f2e70b3 100644 --- a/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/crates/rust-analyzer/src/cli/analysis_stats.rs @@ -479,7 +479,7 @@ impl flags::AnalysisStats { .or_insert(1); } else { acc.syntax_errors += 1; - bar.println(format!("Syntax error: \n{}", err)); + bar.println(format!("Syntax error: \n{err}")); } } } diff --git a/crates/rust-analyzer/src/cli/run_tests.rs b/crates/rust-analyzer/src/cli/run_tests.rs index a2d0dcc599..10cb2d5ad6 100644 --- a/crates/rust-analyzer/src/cli/run_tests.rs +++ b/crates/rust-analyzer/src/cli/run_tests.rs @@ -49,7 +49,7 @@ impl flags::RunTests { let mut sw_all = StopWatch::start(); for test in tests { let full_name = full_name_of_item(db, test.module(db), test.name(db)); - println!("test {}", full_name); + println!("test {full_name}"); if test.is_ignore(db) { println!("ignored"); ignore_count += 1; @@ -62,7 +62,7 @@ impl flags::RunTests { } else { fail_count += 1; } - println!("{}", result); + println!("{result}"); eprintln!("{:<20} {}", format!("test {}", full_name), sw_one.elapsed()); } println!("{pass_count} passed, {fail_count} failed, {ignore_count} ignored"); diff --git a/crates/rust-analyzer/src/cli/rustc_tests.rs b/crates/rust-analyzer/src/cli/rustc_tests.rs index e9a4db7a2b..31565878d8 100644 --- a/crates/rust-analyzer/src/cli/rustc_tests.rs +++ b/crates/rust-analyzer/src/cli/rustc_tests.rs @@ -220,8 +220,8 @@ impl Tester { self.pass_count += 1; } else { println!("{p:?} FAIL"); - println!("actual (r-a) = {:?}", actual); - println!("expected (rustc) = {:?}", expected); + println!("actual (r-a) = {actual:?}"); + println!("expected (rustc) = {expected:?}"); self.fail_count += 1; } } diff --git a/crates/rust-analyzer/src/tracing/hprof.rs b/crates/rust-analyzer/src/tracing/hprof.rs index 73f94671f2..978dcd67fa 100644 --- a/crates/rust-analyzer/src/tracing/hprof.rs +++ b/crates/rust-analyzer/src/tracing/hprof.rs @@ -199,7 +199,7 @@ impl Node { let _ = write!(out, " ({} calls)", self.count); } - eprintln!("{}", out); + eprintln!("{out}"); for child in &self.children { child.go(level + 1, filter) diff --git a/crates/salsa/salsa-macros/src/query_group.rs b/crates/salsa/salsa-macros/src/query_group.rs index 659797d6d4..c04b306916 100644 --- a/crates/salsa/salsa-macros/src/query_group.rs +++ b/crates/salsa/salsa-macros/src/query_group.rs @@ -20,7 +20,7 @@ pub(crate) fn query_group(args: TokenStream, input: TokenStream) -> TokenStream let input_span = input.span(); let (trait_attrs, salsa_attrs) = filter_attrs(input.attrs); if !salsa_attrs.is_empty() { - return Error::new(input_span, format!("unsupported attributes: {:?}", salsa_attrs)) + return Error::new(input_span, format!("unsupported attributes: {salsa_attrs:?}")) .to_compile_error() .into(); } @@ -78,7 +78,7 @@ pub(crate) fn query_group(args: TokenStream, input: TokenStream) -> TokenStream num_storages += 1; } _ => { - return Error::new(span, format!("unknown salsa attribute `{}`", name)) + return Error::new(span, format!("unknown salsa attribute `{name}`")) .to_compile_error() .into(); } @@ -111,7 +111,7 @@ pub(crate) fn query_group(args: TokenStream, input: TokenStream) -> TokenStream _ => { return Error::new( sig_span, - format!("first argument of query `{}` must be `&self`", query_name), + format!("first argument of query `{query_name}` must be `&self`"), ) .to_compile_error() .into(); @@ -130,7 +130,7 @@ pub(crate) fn query_group(args: TokenStream, input: TokenStream) -> TokenStream arg => { return Error::new( arg.span(), - format!("unsupported argument `{:?}` of `{}`", arg, query_name,), + format!("unsupported argument `{arg:?}` of `{query_name}`",), ) .to_compile_error() .into(); @@ -144,7 +144,7 @@ pub(crate) fn query_group(args: TokenStream, input: TokenStream) -> TokenStream ref ret => { return Error::new( ret.span(), - format!("unsupported return type `{:?}` of `{}`", ret, query_name), + format!("unsupported return type `{ret:?}` of `{query_name}`"), ) .to_compile_error() .into(); @@ -169,7 +169,7 @@ pub(crate) fn query_group(args: TokenStream, input: TokenStream) -> TokenStream let lookup_keys = vec![(parse_quote! { key }, value.clone())]; Some(Query { query_type: lookup_query_type, - query_name: format!("{}", lookup_fn_name), + query_name: format!("{lookup_fn_name}"), fn_name: lookup_fn_name, receiver: self_receiver.clone(), attrs: vec![], // FIXME -- some automatically generated docs on this method? @@ -274,8 +274,7 @@ pub(crate) fn query_group(args: TokenStream, input: TokenStream) -> TokenStream *Note:* Setting values will trigger cancellation of any ongoing queries; this method blocks until those queries have been cancelled. - ", - fn_name = fn_name + " ); let set_constant_fn_docs = format!( @@ -290,8 +289,7 @@ pub(crate) fn query_group(args: TokenStream, input: TokenStream) -> TokenStream *Note:* Setting values will trigger cancellation of any ongoing queries; this method blocks until those queries have been cancelled. - ", - fn_name = fn_name + " ); query_fn_declarations.extend(quote! { diff --git a/crates/salsa/tests/cycles.rs b/crates/salsa/tests/cycles.rs index ea5d15a250..e9bddfc630 100644 --- a/crates/salsa/tests/cycles.rs +++ b/crates/salsa/tests/cycles.rs @@ -162,7 +162,7 @@ fn extract_cycle(f: impl FnOnce() + UnwindSafe) -> salsa::Cycle { return cycle.clone(); } } - panic!("unexpected value: {:?}", v) + panic!("unexpected value: {v:?}") } #[test] diff --git a/crates/salsa/tests/incremental/constants.rs b/crates/salsa/tests/incremental/constants.rs index ea0eb81978..32bfbc4564 100644 --- a/crates/salsa/tests/incremental/constants.rs +++ b/crates/salsa/tests/incremental/constants.rs @@ -13,12 +13,12 @@ pub(crate) trait ConstantsDatabase: TestContext { } fn add(db: &dyn ConstantsDatabase, key1: char, key2: char) -> usize { - db.log().add(format!("add({}, {})", key1, key2)); + db.log().add(format!("add({key1}, {key2})")); db.input(key1) + db.input(key2) } fn add3(db: &dyn ConstantsDatabase, key1: char, key2: char, key3: char) -> usize { - db.log().add(format!("add3({}, {}, {})", key1, key2, key3)); + db.log().add(format!("add3({key1}, {key2}, {key3})")); db.add(key1, key2) + db.input(key3) } diff --git a/crates/salsa/tests/incremental/implementation.rs b/crates/salsa/tests/incremental/implementation.rs index 19752bba00..8434913441 100644 --- a/crates/salsa/tests/incremental/implementation.rs +++ b/crates/salsa/tests/incremental/implementation.rs @@ -26,7 +26,7 @@ pub(crate) struct TestContextImpl { impl TestContextImpl { #[track_caller] pub(crate) fn assert_log(&self, expected_log: &[&str]) { - let expected_text = &format!("{:#?}", expected_log); + let expected_text = &format!("{expected_log:#?}"); let actual_text = &format!("{:#?}", self.log().take()); if expected_text == actual_text { @@ -36,9 +36,9 @@ impl TestContextImpl { #[allow(clippy::print_stdout)] for diff in dissimilar::diff(expected_text, actual_text) { match diff { - dissimilar::Chunk::Delete(l) => println!("-{}", l), - dissimilar::Chunk::Equal(l) => println!(" {}", l), - dissimilar::Chunk::Insert(r) => println!("+{}", r), + dissimilar::Chunk::Delete(l) => println!("-{l}"), + dissimilar::Chunk::Equal(l) => println!(" {l}"), + dissimilar::Chunk::Insert(r) => println!("+{r}"), } } diff --git a/crates/salsa/tests/parallel/parallel_cycle_none_recover.rs b/crates/salsa/tests/parallel/parallel_cycle_none_recover.rs index 2930c4e379..3c73852eaf 100644 --- a/crates/salsa/tests/parallel/parallel_cycle_none_recover.rs +++ b/crates/salsa/tests/parallel/parallel_cycle_none_recover.rs @@ -33,7 +33,7 @@ fn parallel_cycle_none_recover() { "#]] .assert_debug_eq(&c.unexpected_participants(&db)); } else { - panic!("b failed in an unexpected way: {:?}", err_b); + panic!("b failed in an unexpected way: {err_b:?}"); } // We expect A to propagate a panic, which causes us to use the sentinel diff --git a/crates/salsa/tests/parallel/race.rs b/crates/salsa/tests/parallel/race.rs index e875de998f..c53d4b464e 100644 --- a/crates/salsa/tests/parallel/race.rs +++ b/crates/salsa/tests/parallel/race.rs @@ -28,7 +28,7 @@ fn in_par_get_set_race() { // cancellation, it'll unwind. let result1 = thread1.join().unwrap(); if let Ok(value1) = result1 { - assert!(value1 == 111 || value1 == 1011, "illegal result {}", value1); + assert!(value1 == 111 || value1 == 1011, "illegal result {value1}"); } // thread2 can not observe a cancellation because it performs a diff --git a/crates/span/src/lib.rs b/crates/span/src/lib.rs index 8ca7bc2d38..74693a270b 100644 --- a/crates/span/src/lib.rs +++ b/crates/span/src/lib.rs @@ -218,7 +218,7 @@ impl From for HirFileId { fn from(MacroFileId { macro_call_id: MacroCallId(id) }: MacroFileId) -> Self { _ = Self::ASSERT_MAX_FILE_ID_IS_SAME; let id = id.as_u32(); - assert!(id <= Self::MAX_HIR_FILE_ID, "MacroCallId index {} is too large", id); + assert!(id <= Self::MAX_HIR_FILE_ID, "MacroCallId index {id} is too large"); HirFileId(id | Self::MACRO_FILE_TAG_MASK) } } diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs index 186f1b01da..92a53c0f9e 100644 --- a/crates/syntax/src/ast/make.rs +++ b/crates/syntax/src/ast/make.rs @@ -172,7 +172,7 @@ pub fn ty_alias( assignment: Option<(ast::Type, Option)>, ) -> ast::TypeAlias { let mut s = String::new(); - s.push_str(&format!("type {}", ident)); + s.push_str(&format!("type {ident}")); if let Some(list) = generic_param_list { s.push_str(&list.to_string()); @@ -297,7 +297,7 @@ pub fn impl_trait( }; let where_clause = merge_where_clause(ty_where_clause, trait_where_clause) - .map_or_else(|| " ".to_owned(), |wc| format!("\n{}\n", wc)); + .map_or_else(|| " ".to_owned(), |wc| format!("\n{wc}\n")); let body = match body { Some(bd) => bd.iter().map(|elem| elem.to_string()).join(""), diff --git a/crates/test-fixture/src/lib.rs b/crates/test-fixture/src/lib.rs index be9961120d..e65186d377 100644 --- a/crates/test-fixture/src/lib.rs +++ b/crates/test-fixture/src/lib.rs @@ -196,7 +196,7 @@ impl ChangeFixture { origin, ); let prev = crates.insert(crate_name.clone(), crate_id); - assert!(prev.is_none(), "multiple crates with same name: {}", crate_name); + assert!(prev.is_none(), "multiple crates with same name: {crate_name}"); for dep in meta.deps { let prelude = match &meta.extern_prelude { Some(v) => v.contains(&dep), diff --git a/crates/test-utils/src/fixture.rs b/crates/test-utils/src/fixture.rs index aafe4fb5b1..9871fd2cf0 100644 --- a/crates/test-utils/src/fixture.rs +++ b/crates/test-utils/src/fixture.rs @@ -450,7 +450,7 @@ impl MiniCore { } if !active_regions.is_empty() { - panic!("unclosed regions: {:?} Add an `endregion` comment", active_regions); + panic!("unclosed regions: {active_regions:?} Add an `endregion` comment"); } for flag in &self.valid_flags { diff --git a/lib/lsp-server/src/lib.rs b/lib/lsp-server/src/lib.rs index 5dc052b587..4069e6f2c0 100644 --- a/lib/lsp-server/src/lib.rs +++ b/lib/lsp-server/src/lib.rs @@ -433,8 +433,7 @@ mod tests { initialize_start_test(TestCase { test_messages: vec![notification_msg.clone()], expected_resp: Err(ProtocolError::new(format!( - "expected initialize request, got {:?}", - notification_msg + "expected initialize request, got {notification_msg:?}" ))), }); } diff --git a/xtask/src/metrics.rs b/xtask/src/metrics.rs index 285abb9efc..9a7785dd43 100644 --- a/xtask/src/metrics.rs +++ b/xtask/src/metrics.rs @@ -64,7 +64,7 @@ impl flags::Metrics { }; let mut file = - fs::File::options().write(true).create(true).open(format!("target/{}.json", name))?; + fs::File::options().write(true).create(true).open(format!("target/{name}.json"))?; writeln!(file, "{}", metrics.json())?; eprintln!("{metrics:#?}"); Ok(())