From 3fd8cbb404666e0b979efa9a886674b4a9f58868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Wed, 21 Jul 2021 22:43:19 +0200 Subject: [PATCH] clippy::useless_format --- compiler/rustc_lint/src/types.rs | 2 +- compiler/rustc_macros/src/symbols.rs | 2 +- .../rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs | 2 +- .../src/borrow_check/diagnostics/mutability_errors.rs | 2 +- compiler/rustc_mir/src/transform/check_consts/ops.rs | 2 +- compiler/rustc_mir/src/transform/coverage/debug.rs | 4 ++-- compiler/rustc_mir/src/transform/lower_intrinsics.rs | 4 ++-- compiler/rustc_mir/src/util/pretty.rs | 2 +- compiler/rustc_passes/src/check_attr.rs | 2 +- compiler/rustc_passes/src/entry.rs | 2 +- compiler/rustc_query_system/src/query/plumbing.rs | 4 ++-- compiler/rustc_resolve/src/late/diagnostics.rs | 2 +- compiler/rustc_target/src/spec/mod.rs | 2 +- compiler/rustc_typeck/src/check/method/prelude2021.rs | 2 +- 14 files changed, 17 insertions(+), 17 deletions(-) diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index a3a87a48768dc..55961636f3216 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -906,7 +906,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { } else { return FfiUnsafe { ty, - reason: format!("box cannot be represented as a single pointer"), + reason: "box cannot be represented as a single pointer".to_string(), help: None, }; } diff --git a/compiler/rustc_macros/src/symbols.rs b/compiler/rustc_macros/src/symbols.rs index 2f063f75eb0ef..c52304e547421 100644 --- a/compiler/rustc_macros/src/symbols.rs +++ b/compiler/rustc_macros/src/symbols.rs @@ -135,7 +135,7 @@ fn symbols_with_errors(input: TokenStream) -> (TokenStream, Vec) { let mut check_dup = |span: Span, str: &str, errors: &mut Errors| { if let Some(prev_span) = keys.get(str) { errors.error(span, format!("Symbol `{}` is duplicated", str)); - errors.error(*prev_span, format!("location of previous definition")); + errors.error(*prev_span, "location of previous definition".to_string()); } else { keys.insert(str.to_string(), span); } diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs b/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs index 2e854ea5be7df..e43973b8db40c 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs +++ b/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs @@ -320,7 +320,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { .map(|n| format!("`{}`", n)) .unwrap_or_else(|| "the mutable reference".to_string()), ), - format!("&mut *"), + "&mut *".to_string(), Applicability::MachineApplicable, ); } diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs b/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs index 671d947d1b132..d3f9e49816ade 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs +++ b/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs @@ -721,7 +721,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { if suggestions.peek().is_some() { err.span_suggestions( path_segment.ident.span, - &format!("use mutable method"), + "use mutable method", suggestions, Applicability::MaybeIncorrect, ); diff --git a/compiler/rustc_mir/src/transform/check_consts/ops.rs b/compiler/rustc_mir/src/transform/check_consts/ops.rs index fd72ec4340f9f..92de8bd292c3d 100644 --- a/compiler/rustc_mir/src/transform/check_consts/ops.rs +++ b/compiler/rustc_mir/src/transform/check_consts/ops.rs @@ -255,7 +255,7 @@ impl NonConstOp for CellBorrow { ); err.span_label( span, - format!("this borrow of an interior mutable value may end up in the final value"), + "this borrow of an interior mutable value may end up in the final value", ); if let hir::ConstContext::Static(_) = ccx.const_kind() { err.help( diff --git a/compiler/rustc_mir/src/transform/coverage/debug.rs b/compiler/rustc_mir/src/transform/coverage/debug.rs index f6672335cb138..6fd7d29d77797 100644 --- a/compiler/rustc_mir/src/transform/coverage/debug.rs +++ b/compiler/rustc_mir/src/transform/coverage/debug.rs @@ -344,7 +344,7 @@ impl DebugCounters { return if counter_format.id { format!("{}#{}", block_label, id.index()) } else { - format!("{}", block_label) + block_label.to_string() }; } } @@ -369,7 +369,7 @@ impl DebugCounters { } return format!("({})", self.format_counter_kind(counter_kind)); } - return format!("{}", self.format_counter_kind(counter_kind)); + return self.format_counter_kind(counter_kind).to_string(); } } format!("#{}", operand.index().to_string()) diff --git a/compiler/rustc_mir/src/transform/lower_intrinsics.rs b/compiler/rustc_mir/src/transform/lower_intrinsics.rs index 6d7e4cdb1c6ef..aff2df31b1c96 100644 --- a/compiler/rustc_mir/src/transform/lower_intrinsics.rs +++ b/compiler/rustc_mir/src/transform/lower_intrinsics.rs @@ -147,8 +147,8 @@ fn validate_simd_shuffle(tcx: TyCtxt<'tcx>, args: &[Operand<'tcx>], span: Span) match &args[2] { Operand::Constant(_) => {} // all good _ => { - let msg = format!("last argument of `simd_shuffle` is required to be a `const` item"); - tcx.sess.span_err(span, &msg); + let msg = "last argument of `simd_shuffle` is required to be a `const` item"; + tcx.sess.span_err(span, msg); } } } diff --git a/compiler/rustc_mir/src/util/pretty.rs b/compiler/rustc_mir/src/util/pretty.rs index d0b1bc47ea800..7598a011bb677 100644 --- a/compiler/rustc_mir/src/util/pretty.rs +++ b/compiler/rustc_mir/src/util/pretty.rs @@ -479,7 +479,7 @@ impl Visitor<'tcx> for ExtraComments<'tcx> { uv.promoted ), ty::ConstKind::Value(val) => format!("Value({:?})", val), - ty::ConstKind::Error(_) => format!("Error"), + ty::ConstKind::Error(_) => "Error".to_string(), }; self.push(&format!("+ val: {}", val)); } diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 71231830e99a7..cd3e6e2f48cfd 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -855,7 +855,7 @@ impl CheckAttrVisitor<'tcx> { hir_id, meta.span(), |lint| { - lint.build(&format!("invalid `doc` attribute")).emit(); + lint.build(&"invalid `doc` attribute").emit(); }, ); is_valid = false; diff --git a/compiler/rustc_passes/src/entry.rs b/compiler/rustc_passes/src/entry.rs index 550f4f148fd24..0b5dcd1a087dd 100644 --- a/compiler/rustc_passes/src/entry.rs +++ b/compiler/rustc_passes/src/entry.rs @@ -229,7 +229,7 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) { if let Some(main_def) = tcx.resolutions(()).main_def { if main_def.opt_fn_def_id().is_none() { // There is something at `crate::main`, but it is not a function definition. - err.span_label(main_def.span, &format!("non-function item at `crate::main` is found")); + err.span_label(main_def.span, "non-function item at `crate::main` is found"); } } diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index c227c2aaff549..a0c2b3d82abce 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -618,8 +618,8 @@ fn incremental_verify_ich( }; tcx.sess().struct_err(&format!("internal compiler error: encountered incremental compilation error with {:?}", dep_node)) .help(&format!("This is a known issue with the compiler. Run {} to allow your project to compile", run_cmd)) - .note(&format!("Please follow the instructions below to create a bug report with the provided information")) - .note(&format!("See for more information")) + .note(&"Please follow the instructions below to create a bug report with the provided information") + .note(&"See for more information") .emit(); panic!("Found unstable fingerprints for {:?}: {:?}", dep_node, result); } diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 76979ab50b9e6..e3ab858541af4 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -1061,7 +1061,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { } err.span_suggestion( span, - &format!("use this syntax instead"), + &"use this syntax instead", format!("{path_str}"), Applicability::MaybeIncorrect, ); diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index ad84e07edfba6..7f349ef10d348 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -2018,7 +2018,7 @@ impl Target { if base.is_builtin { // This can cause unfortunate ICEs later down the line. - return Err(format!("may not set is_builtin for targets not built-in")); + return Err("may not set is_builtin for targets not built-in".to_string()); } // Each field should have been read using `Json::remove_key` so any keys remaining are unused. let remaining_keys = obj.as_object().ok_or("Expected JSON object for target")?.keys(); diff --git a/compiler/rustc_typeck/src/check/method/prelude2021.rs b/compiler/rustc_typeck/src/check/method/prelude2021.rs index f13e23914f7ab..f4644f7514d2a 100644 --- a/compiler/rustc_typeck/src/check/method/prelude2021.rs +++ b/compiler/rustc_typeck/src/check/method/prelude2021.rs @@ -342,7 +342,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let Ok(expr_text) = self.sess().source_map().span_to_snippet(expr.span) { (expr_text, true) } else { - (format!("(..)"), false) + ("(..)".to_string(), false) }; let adjusted_text = if let Some(probe::AutorefOrPtrAdjustment::ToConstPtr) =