From 1c129f7b975af43362877054c4cd24d70929a030 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= <matthias.krueger@famsik.de>
Date: Sat, 17 Jul 2021 01:38:08 +0200
Subject: [PATCH 1/9] use vec![] macro to create Vector with first item inside
 instead of pushing to an empty vec![]

slightly reduces code bloat
---
 compiler/rustc_ast_pretty/src/pprust/state.rs                | 3 +--
 compiler/rustc_hir_pretty/src/lib.rs                         | 4 ++--
 compiler/rustc_mir/src/transform/coverage/graph.rs           | 4 ++--
 .../src/traits/error_reporting/on_unimplemented.rs           | 5 ++---
 4 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs
index 8b7b306a54d..b910431b1dd 100644
--- a/compiler/rustc_ast_pretty/src/pprust/state.rs
+++ b/compiler/rustc_ast_pretty/src/pprust/state.rs
@@ -2189,8 +2189,7 @@ impl<'a> State<'a> {
             Options(InlineAsmOptions),
         }
 
-        let mut args = vec![];
-        args.push(AsmArg::Template(InlineAsmTemplatePiece::to_string(&asm.template)));
+        let mut args = vec![AsmArg::Template(InlineAsmTemplatePiece::to_string(&asm.template))];
         args.extend(asm.operands.iter().map(|(o, _)| AsmArg::Operand(o)));
         if !asm.options.is_empty() {
             args.push(AsmArg::Options(asm.options));
diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs
index 5c1739b1ab9..598292d1bc4 100644
--- a/compiler/rustc_hir_pretty/src/lib.rs
+++ b/compiler/rustc_hir_pretty/src/lib.rs
@@ -1356,8 +1356,8 @@ impl<'a> State<'a> {
             Options(ast::InlineAsmOptions),
         }
 
-        let mut args = vec![];
-        args.push(AsmArg::Template(ast::InlineAsmTemplatePiece::to_string(&asm.template)));
+        let mut args =
+            vec![AsmArg::Template(ast::InlineAsmTemplatePiece::to_string(&asm.template))];
         args.extend(asm.operands.iter().map(|(o, _)| AsmArg::Operand(o)));
         if !asm.options.is_empty() {
             args.push(AsmArg::Options(asm.options));
diff --git a/compiler/rustc_mir/src/transform/coverage/graph.rs b/compiler/rustc_mir/src/transform/coverage/graph.rs
index 0521f507ec7..32febcec7af 100644
--- a/compiler/rustc_mir/src/transform/coverage/graph.rs
+++ b/compiler/rustc_mir/src/transform/coverage/graph.rs
@@ -526,8 +526,8 @@ impl TraverseCoverageGraphWithLoops {
     pub fn new(basic_coverage_blocks: &CoverageGraph) -> Self {
         let start_bcb = basic_coverage_blocks.start_node();
         let backedges = find_loop_backedges(basic_coverage_blocks);
-        let mut context_stack = Vec::new();
-        context_stack.push(TraversalContext { loop_backedges: None, worklist: vec![start_bcb] });
+        let context_stack =
+            vec![TraversalContext { loop_backedges: None, worklist: vec![start_bcb] }];
         // `context_stack` starts with a `TraversalContext` for the main function context (beginning
         // with the `start` BasicCoverageBlock of the function). New worklists are pushed to the top
         // of the stack as loops are entered, and popped off of the stack when a loop's worklist is
diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs
index 0ca0245a203..3a32f1cb903 100644
--- a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs
+++ b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs
@@ -124,11 +124,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
             self.impl_similar_to(trait_ref, obligation).unwrap_or_else(|| trait_ref.def_id());
         let trait_ref = trait_ref.skip_binder();
 
-        let mut flags = vec![];
-        flags.push((
+        let mut flags = vec![(
             sym::ItemContext,
             self.describe_enclosure(obligation.cause.body_id).map(|s| s.to_owned()),
-        ));
+        )];
 
         match obligation.cause.code {
             ObligationCauseCode::BuiltinDerivedObligation(..)

From a75192bcfe2d1a4a639d703b7b3271f857bec7b7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= <matthias.krueger@famsik.de>
Date: Sat, 17 Jul 2021 09:13:08 +0200
Subject: [PATCH 2/9] don't slice slices (clippy::redundant_slicing)

---
 src/librustdoc/html/format.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs
index 08499cef33e..fe33018df28 100644
--- a/src/librustdoc/html/format.rs
+++ b/src/librustdoc/html/format.rs
@@ -488,7 +488,7 @@ crate fn href(did: DefId, cx: &Context<'_>) -> Result<(String, ItemType, Vec<Str
     let cache = &cx.cache();
     let relative_to = &cx.current;
     fn to_module_fqp(shortty: ItemType, fqp: &[String]) -> &[String] {
-        if shortty == ItemType::Module { &fqp[..] } else { &fqp[..fqp.len() - 1] }
+        if shortty == ItemType::Module { fqp } else { &fqp[..fqp.len() - 1] }
     }
 
     if !did.is_local() && !cache.access_levels.is_public(did) && !cache.document_private {
@@ -509,7 +509,7 @@ crate fn href(did: DefId, cx: &Context<'_>) -> Result<(String, ItemType, Vec<Str
                     match cache.extern_locations[&did.krate] {
                         ExternalLocation::Remote(ref s) => {
                             let s = s.trim_end_matches('/');
-                            let mut s = vec![&s[..]];
+                            let mut s = vec![s];
                             s.extend(module_fqp[..].iter().map(String::as_str));
                             s
                         }

From dc722bfd74640112c0b7b2c6d1cf348e18c18267 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= <matthias.krueger@famsik.de>
Date: Sat, 17 Jul 2021 14:18:51 +0200
Subject: [PATCH 3/9] clippy::needless_question_mark

---
 compiler/rustc_middle/src/ty/codec.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs
index 5ec665e913c..fb13614e4b3 100644
--- a/compiler/rustc_middle/src/ty/codec.rs
+++ b/compiler/rustc_middle/src/ty/codec.rs
@@ -385,7 +385,7 @@ impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for [mir::abstract_const::N
 impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for ty::List<ty::BoundVariableKind> {
     fn decode(decoder: &mut D) -> Result<&'tcx Self, D::Error> {
         let len = decoder.read_usize()?;
-        Ok(decoder.tcx().mk_bound_variable_kinds((0..len).map(|_| Decodable::decode(decoder)))?)
+        decoder.tcx().mk_bound_variable_kinds((0..len).map(|_| Decodable::decode(decoder)))
     }
 }
 

From d709e6efefee52dc74b5f05195d6db3e9bddcd71 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= <matthias.krueger@famsik.de>
Date: Sat, 17 Jul 2021 23:35:57 +0200
Subject: [PATCH 4/9] clippy::single_char_pattern

---
 compiler/rustc_codegen_llvm/src/llvm_util.rs   | 4 ++--
 compiler/rustc_expand/src/proc_macro_server.rs | 2 +-
 compiler/rustc_session/src/config.rs           | 2 +-
 compiler/rustc_session/src/options.rs          | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs
index cb9c6269b66..0ca51bd2883 100644
--- a/compiler/rustc_codegen_llvm/src/llvm_util.rs
+++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs
@@ -365,7 +365,7 @@ pub fn llvm_global_features(sess: &Session) -> Vec<String> {
 
                 features_string
             };
-            features.extend(features_string.split(",").map(String::from));
+            features.extend(features_string.split(',').map(String::from));
         }
         Some(_) | None => {}
     };
@@ -374,7 +374,7 @@ pub fn llvm_global_features(sess: &Session) -> Vec<String> {
         if s.is_empty() {
             return None;
         }
-        let feature = if s.starts_with("+") || s.starts_with("-") {
+        let feature = if s.starts_with('+') || s.starts_with('-') {
             &s[1..]
         } else {
             return Some(s.to_string());
diff --git a/compiler/rustc_expand/src/proc_macro_server.rs b/compiler/rustc_expand/src/proc_macro_server.rs
index ff135f60a82..b949d885900 100644
--- a/compiler/rustc_expand/src/proc_macro_server.rs
+++ b/compiler/rustc_expand/src/proc_macro_server.rs
@@ -834,7 +834,7 @@ fn ident_name_compatibility_hack(
                                 .flat_map(|c| c.as_os_str().to_str())
                                 .find(|c| c.starts_with("js-sys"))
                             {
-                                let mut version = c.trim_start_matches("js-sys-").split(".");
+                                let mut version = c.trim_start_matches("js-sys-").split('.');
                                 if version.next() == Some("0")
                                     && version.next() == Some("3")
                                     && version
diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs
index 2d7f5f9b321..4e834ead17d 100644
--- a/compiler/rustc_session/src/config.rs
+++ b/compiler/rustc_session/src/config.rs
@@ -1876,7 +1876,7 @@ fn parse_extern_dep_specs(
             )
         });
 
-        let locparts: Vec<_> = loc.split(":").collect();
+        let locparts: Vec<_> = loc.split(':').collect();
         let spec = match &locparts[..] {
             ["raw", ..] => {
                 // Don't want `:` split string
diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs
index 172337aca3d..65c1e001b7a 100644
--- a/compiler/rustc_session/src/options.rs
+++ b/compiler/rustc_session/src/options.rs
@@ -684,7 +684,7 @@ mod parse {
             Some(v) => v,
         };
 
-        *slot = Some(match v.trim_end_matches("s") {
+        *slot = Some(match v.trim_end_matches('s') {
             "statement" | "stmt" => MirSpanview::Statement,
             "terminator" | "term" => MirSpanview::Terminator,
             "block" | "basicblock" => MirSpanview::Block,

From aa74c75d849b63135c922c9c74324944af5bc487 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= <matthias.krueger@famsik.de>
Date: Sun, 18 Jul 2021 00:01:59 +0200
Subject: [PATCH 5/9] clippy:: append_instead_of_extend

---
 compiler/rustc_mir/src/monomorphize/partitioning/merging.rs | 2 +-
 compiler/rustc_mir/src/transform/inline.rs                  | 4 ++--
 compiler/rustc_traits/src/dropck_outlives.rs                | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/compiler/rustc_mir/src/monomorphize/partitioning/merging.rs b/compiler/rustc_mir/src/monomorphize/partitioning/merging.rs
index 5107e697263..cbe36665790 100644
--- a/compiler/rustc_mir/src/monomorphize/partitioning/merging.rs
+++ b/compiler/rustc_mir/src/monomorphize/partitioning/merging.rs
@@ -46,7 +46,7 @@ pub fn merge_codegen_units<'tcx>(
         // Record that `second_smallest` now contains all the stuff that was in
         // `smallest` before.
         let mut consumed_cgu_names = cgu_contents.remove(&smallest.name()).unwrap();
-        cgu_contents.get_mut(&second_smallest.name()).unwrap().extend(consumed_cgu_names.drain(..));
+        cgu_contents.get_mut(&second_smallest.name()).unwrap().append(&mut consumed_cgu_names);
 
         debug!(
             "CodegenUnit {} merged into CodegenUnit {}",
diff --git a/compiler/rustc_mir/src/transform/inline.rs b/compiler/rustc_mir/src/transform/inline.rs
index 7d765cec575..8e6654cb2da 100644
--- a/compiler/rustc_mir/src/transform/inline.rs
+++ b/compiler/rustc_mir/src/transform/inline.rs
@@ -614,8 +614,8 @@ impl Inliner<'tcx> {
                         .vars_and_temps_iter()
                         .map(|local| callee_body.local_decls[local].clone()),
                 );
-                caller_body.source_scopes.extend(callee_body.source_scopes.drain(..));
-                caller_body.var_debug_info.extend(callee_body.var_debug_info.drain(..));
+                caller_body.source_scopes.extend(&mut callee_body.source_scopes.drain(..));
+                caller_body.var_debug_info.append(&mut callee_body.var_debug_info);
                 caller_body.basic_blocks_mut().extend(callee_body.basic_blocks_mut().drain(..));
 
                 caller_body[callsite.block].terminator = Some(Terminator {
diff --git a/compiler/rustc_traits/src/dropck_outlives.rs b/compiler/rustc_traits/src/dropck_outlives.rs
index 4a41dfe0143..672e149b5fc 100644
--- a/compiler/rustc_traits/src/dropck_outlives.rs
+++ b/compiler/rustc_traits/src/dropck_outlives.rs
@@ -90,8 +90,8 @@ fn dropck_outlives<'tcx>(
 
                 // "outlives" represent types/regions that may be touched
                 // by a destructor.
-                result.kinds.extend(constraints.outlives.drain(..));
-                result.overflows.extend(constraints.overflows.drain(..));
+                result.kinds.append(&mut constraints.outlives);
+                result.overflows.append(&mut constraints.overflows);
 
                 // If we have even one overflow, we should stop trying to evaluate further --
                 // chances are, the subsequent overflows for this evaluation won't provide useful

From 066eb6ab5d516259a330eaab3a2254990ad33593 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= <matthias.krueger@famsik.de>
Date: Wed, 21 Jul 2021 21:46:02 +0200
Subject: [PATCH 6/9] clippy::filter_next

---
 .../src/traits/error_reporting/suggestions.rs          | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
index 9a33875d6e4..9c4db5b70ae 100644
--- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
+++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
@@ -290,13 +290,9 @@ fn suggest_restriction(
     } else {
         // Trivial case: `T` needs an extra bound: `T: Bound`.
         let (sp, suggestion) = match (
-            generics
-                .params
-                .iter()
-                .filter(|p| {
-                    !matches!(p.kind, hir::GenericParamKind::Type { synthetic: Some(_), .. })
-                })
-                .next(),
+            generics.params.iter().find(|p| {
+                !matches!(p.kind, hir::GenericParamKind::Type { synthetic: Some(_), .. })
+            }),
             super_traits,
         ) {
             (_, None) => predicate_constraint(

From 053aedce2c916294082cd8603686cbe9acbef822 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= <matthias.krueger@famsik.de>
Date: Wed, 21 Jul 2021 21:53:45 +0200
Subject: [PATCH 7/9] clippy::filter_map_identity

---
 compiler/rustc_hir/src/def.rs           | 2 +-
 compiler/rustc_parse/src/parser/item.rs | 3 +--
 compiler/rustc_typeck/src/check/mod.rs  | 2 +-
 3 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs
index de10d88c1d2..3816888db10 100644
--- a/compiler/rustc_hir/src/def.rs
+++ b/compiler/rustc_hir/src/def.rs
@@ -476,7 +476,7 @@ impl<T> PerNS<Option<T>> {
 
     /// Returns an iterator over the items which are `Some`.
     pub fn present_items(self) -> impl Iterator<Item = T> {
-        IntoIter::new([self.type_ns, self.value_ns, self.macro_ns]).filter_map(|it| it)
+        IntoIter::new([self.type_ns, self.value_ns, self.macro_ns]).flatten()
     }
 }
 
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs
index 2ce63d011f4..f77f9bc454b 100644
--- a/compiler/rustc_parse/src/parser/item.rs
+++ b/compiler/rustc_parse/src/parser/item.rs
@@ -1107,8 +1107,7 @@ impl<'a> Parser<'a> {
                 e
             })?;
 
-        let enum_definition =
-            EnumDef { variants: variants.into_iter().filter_map(|v| v).collect() };
+        let enum_definition = EnumDef { variants: variants.into_iter().flatten().collect() };
         Ok((id, ItemKind::Enum(enum_definition, generics)))
     }
 
diff --git a/compiler/rustc_typeck/src/check/mod.rs b/compiler/rustc_typeck/src/check/mod.rs
index d30b057e26f..ae6de3b7a0c 100644
--- a/compiler/rustc_typeck/src/check/mod.rs
+++ b/compiler/rustc_typeck/src/check/mod.rs
@@ -791,7 +791,7 @@ fn fn_sig_suggestion<'tcx>(
             })
         })
         .chain(std::iter::once(if sig.c_variadic { Some("...".to_string()) } else { None }))
-        .filter_map(|arg| arg)
+        .flatten()
         .collect::<Vec<String>>()
         .join(", ");
     let output = sig.output();

From d0a8a12dc60cb87325386be73aad7a398e1d30b3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= <matthias.krueger@famsik.de>
Date: Wed, 21 Jul 2021 22:00:44 +0200
Subject: [PATCH 8/9] clippy::flat_map_identity

---
 compiler/rustc_lint/src/levels.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs
index 069fa41fa88..187e54154e3 100644
--- a/compiler/rustc_lint/src/levels.rs
+++ b/compiler/rustc_lint/src/levels.rs
@@ -576,7 +576,7 @@ pub fn is_known_lint_tool(m_item: Symbol, sess: &Session, attrs: &[ast::Attribut
     // NOTE: does no error handling; error handling is done by rustc_resolve.
     sess.filter_by_name(attrs, sym::register_tool)
         .filter_map(|attr| attr.meta_item_list())
-        .flat_map(std::convert::identity)
+        .flatten()
         .filter_map(|nested_meta| nested_meta.ident())
         .map(|ident| ident.name)
         .any(|name| name == m_item)

From 3fd8cbb404666e0b979efa9a886674b4a9f58868 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= <matthias.krueger@famsik.de>
Date: Wed, 21 Jul 2021 22:43:19 +0200
Subject: [PATCH 9/9] 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 a3a87a48768..55961636f32 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 2f063f75eb0..c52304e5474 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<syn::Error>) {
     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 2e854ea5be7..e43973b8db4 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 671d947d1b1..d3f9e49816a 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 fd72ec4340f..92de8bd292c 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 f6672335cb1..6fd7d29d777 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 6d7e4cdb1c6..aff2df31b1c 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 d0b1bc47ea8..7598a011bb6 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 71231830e99..cd3e6e2f48c 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 550f4f148fd..0b5dcd1a087 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 c227c2aaff5..a0c2b3d82ab 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<CTX, K, V: Debug>(
         };
         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 <https://github.com/rust-lang/rust/issues/84970> for more information"))
+            .note(&"Please follow the instructions below to create a bug report with the provided information")
+            .note(&"See <https://github.com/rust-lang/rust/issues/84970> 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 76979ab50b9..e3ab858541a 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 ad84e07edfb..7f349ef10d3 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 f13e23914f7..f4644f7514d 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) =