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_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 { 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 { 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_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 PerNS> { /// Returns an iterator over the items which are `Some`. pub fn present_items(self) -> impl Iterator { - 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_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index 2b372392575..9ad40db73ce 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -1357,8 +1357,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_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index 4f223afcc27..bca3023664a 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) 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) { 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_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 { 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))) } } 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 a9bfbb51573..a3ea1700634 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 f08208a1214..5932cb9e775 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs +++ b/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs @@ -731,7 +731,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/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/check_consts/ops.rs b/compiler/rustc_mir/src/transform/check_consts/ops.rs index 8de11fda7d7..ddca22aebd2 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/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_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_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_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_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index ee9057a3bab..14f8a8bff71 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 876edbd1f6d..e881a855bbc 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 5f53a19b3f9..a708631af0a 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -620,8 +620,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 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_session/src/config.rs b/compiler/rustc_session/src/config.rs index e7cb3188393..ebf4b2b01c5 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1867,7 +1867,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 0805d2f0e14..ec23a0769af 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, 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_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(..) 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 712fea84a8b..b6ee51cfc1a 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( 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 diff --git a/compiler/rustc_typeck/src/check/method/prelude2021.rs b/compiler/rustc_typeck/src/check/method/prelude2021.rs index 6eb8af98640..9e3292d7821 100644 --- a/compiler/rustc_typeck/src/check/method/prelude2021.rs +++ b/compiler/rustc_typeck/src/check/method/prelude2021.rs @@ -357,7 +357,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) = 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::>() .join(", "); let output = sig.output(); diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index cd74006530b..0291236abdf 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 &[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 { 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 }