From 9c4c4a7e59b27c69b7a30206c9139825bd987e5c Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Thu, 27 Jul 2023 14:15:09 -0400 Subject: [PATCH] wip --- compiler/rustc_ast_lowering/src/lib.rs | 2 +- .../src/lifetime_collector.rs | 2 +- .../src/constraint_generation.rs | 2 +- .../src/assert/context.rs | 2 +- .../rustc_codegen_cranelift/src/common.rs | 2 +- .../rustc_codegen_cranelift/src/constant.rs | 2 +- compiler/rustc_codegen_gcc/src/context.rs | 2 +- compiler/rustc_codegen_ssa/src/back/link.rs | 4 +-- .../rustc_codegen_ssa/src/codegen_attrs.rs | 4 +-- compiler/rustc_codegen_ssa/src/common.rs | 2 +- compiler/rustc_codegen_ssa/src/mir/block.rs | 8 ++--- compiler/rustc_codegen_ssa/src/mir/mod.rs | 2 +- .../rustc_const_eval/src/interpret/cast.rs | 6 ++-- .../rustc_const_eval/src/interpret/intern.rs | 2 +- .../src/interpret/operator.rs | 10 +++---- .../src/transform/check_consts/check.rs | 4 +-- .../src/transform/promote_consts.rs | 12 ++++---- compiler/rustc_errors/src/lib.rs | 4 +-- compiler/rustc_expand/src/mbe/metavar_expr.rs | 4 +-- compiler/rustc_fluent_macro/src/fluent.rs | 2 +- compiler/rustc_hir_typeck/src/demand.rs | 5 ++-- .../rustc_hir_typeck/src/method/suggest.rs | 4 +-- compiler/rustc_middle/src/middle/stability.rs | 2 +- compiler/rustc_middle/src/mir/spanview.rs | 2 +- .../rustc_mir_build/src/thir/pattern/mod.rs | 5 ++-- .../src/early_otherwise_branch.rs | 4 +-- compiler/rustc_resolve/src/diagnostics.rs | 2 +- .../src/typeid/typeid_itanium_cxx_abi.rs | 6 ++-- .../src/traits/error_reporting/suggestions.rs | 30 +++++++++++++------ 29 files changed, 74 insertions(+), 64 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 4a47de1280c63..60a054c6facf1 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -1607,7 +1607,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { "Unexpected lifetime resolution {:?} for {:?} at {:?}", res, lifetime.ident, lifetime.ident.span ); - span_bug!(lifetime.ident.span, "{}", bug_msg); + span_bug!(lifetime.ident.span, "{bug_msg}"); } }; diff --git a/compiler/rustc_ast_lowering/src/lifetime_collector.rs b/compiler/rustc_ast_lowering/src/lifetime_collector.rs index 6f75419c38765..684dbbc2f7a73 100644 --- a/compiler/rustc_ast_lowering/src/lifetime_collector.rs +++ b/compiler/rustc_ast_lowering/src/lifetime_collector.rs @@ -38,7 +38,7 @@ impl<'ast> LifetimeCollectVisitor<'ast> { "Unexpected lifetime resolution {:?} for {:?} at {:?}", res, lifetime.ident, lifetime.ident.span ); - span_bug!(lifetime.ident.span, "{}", bug_msg); + span_bug!(lifetime.ident.span, "{bug_msg}"); } } } diff --git a/compiler/rustc_borrowck/src/constraint_generation.rs b/compiler/rustc_borrowck/src/constraint_generation.rs index 1f642099f0899..7b8328f943b20 100644 --- a/compiler/rustc_borrowck/src/constraint_generation.rs +++ b/compiler/rustc_borrowck/src/constraint_generation.rs @@ -71,7 +71,7 @@ impl<'cg, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'tcx> { | TyContext::YieldTy(SourceInfo { span, .. }) | TyContext::UserTy(span) | TyContext::LocalDecl { source_info: SourceInfo { span, .. }, .. } => { - span_bug!(span, "should not be visiting outside of the CFG: {:?}", ty_context); + span_bug!(span, "should not be visiting outside of the CFG: {ty_context:?}"); } TyContext::Location(location) => { self.add_regular_live_constraint(ty, location); diff --git a/compiler/rustc_builtin_macros/src/assert/context.rs b/compiler/rustc_builtin_macros/src/assert/context.rs index bda473120ed04..d76beef26e452 100644 --- a/compiler/rustc_builtin_macros/src/assert/context.rs +++ b/compiler/rustc_builtin_macros/src/assert/context.rs @@ -159,7 +159,7 @@ impl<'cx, 'a> Context<'cx, 'a> { } else { format!( "Assertion failed: {escaped_expr_str}\nWith captures:\n{}", - &self.fmt_string + self.fmt_string ) }), suffix: None, diff --git a/compiler/rustc_codegen_cranelift/src/common.rs b/compiler/rustc_codegen_cranelift/src/common.rs index 3081dcfa2b7a3..d31dadb9a2d25 100644 --- a/compiler/rustc_codegen_cranelift/src/common.rs +++ b/compiler/rustc_codegen_cranelift/src/common.rs @@ -480,7 +480,7 @@ impl<'tcx> LayoutOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> { if let LayoutError::SizeOverflow(_) | LayoutError::ReferencesError(_) = err { self.0.sess.span_fatal(span, err.to_string()) } else { - span_bug!(span, "failed to get layout for `{}`: {}", ty, err) + span_bug!(span, "failed to get layout for `{ty}`: {err}") } } } diff --git a/compiler/rustc_codegen_cranelift/src/constant.rs b/compiler/rustc_codegen_cranelift/src/constant.rs index c31535742957c..98b784f73df94 100644 --- a/compiler/rustc_codegen_cranelift/src/constant.rs +++ b/compiler/rustc_codegen_cranelift/src/constant.rs @@ -107,7 +107,7 @@ pub(crate) fn eval_mir_constant<'tcx>( fx.tcx.sess.span_err(constant.span, "erroneous constant encountered"); } ErrorHandled::TooGeneric => { - span_bug!(constant.span, "codegen encountered polymorphic constant: {:?}", err); + span_bug!(constant.span, "codegen encountered polymorphic constant: {err:?}"); } }) .ok(); diff --git a/compiler/rustc_codegen_gcc/src/context.rs b/compiler/rustc_codegen_gcc/src/context.rs index 88dcafa7370e5..6bd563d6f9a35 100644 --- a/compiler/rustc_codegen_gcc/src/context.rs +++ b/compiler/rustc_codegen_gcc/src/context.rs @@ -479,7 +479,7 @@ impl<'gcc, 'tcx> LayoutOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> { if let LayoutError::SizeOverflow(_) | LayoutError::ReferencesError(_) = err { self.sess().emit_fatal(respan(span, err.into_diagnostic())) } else { - span_bug!(span, "failed to get layout for `{}`: {}", ty, err) + span_bug!(span, "failed to get layout for `{ty}`: {err}") } } } diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index a7ac728c59b02..2b432055b13b4 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -971,7 +971,7 @@ fn link_natively<'a>( sess.emit_err(errors::UnableToExeLinker { linker_path, error: e, - command_formatted: format!("{:?}", &cmd), + command_formatted: format!("{cmd:?}"), }); } @@ -1477,7 +1477,7 @@ fn print_native_static_libs( sess.emit_note(errors::StaticLibraryNativeArtifacts); // Prefix for greppability // Note: This must not be translated as tools are allowed to depend on this exact string. - sess.note_without_error(format!("native-static-libs: {}", &lib_args.join(" "))); + sess.note_without_error(format!("native-static-libs: {}", lib_args.join(" "))); } } } diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index f6936c80b7758..3629b5c5ff8f2 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -313,7 +313,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { sym::link_section => { if let Some(val) = attr.value_str() { if val.as_str().bytes().any(|b| b == 0) { - let msg = format!("illegal null byte in link_section value: `{}`", &val); + let msg = format!("illegal null byte in link_section value: `{val}`"); tcx.sess.span_err(attr.span, msg); } else { codegen_fn_attrs.link_section = Some(val); @@ -648,7 +648,7 @@ fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &ast::Attribute) -> Option { if *ordinal <= u16::MAX as u128 { Some(*ordinal as u16) } else { - let msg = format!("ordinal value in `link_ordinal` is too large: `{}`", &ordinal); + let msg = format!("ordinal value in `link_ordinal` is too large: `{ordinal}`"); tcx.sess .struct_span_err(attr.span, msg) .note("the value may not exceed `u16::MAX`") diff --git a/compiler/rustc_codegen_ssa/src/common.rs b/compiler/rustc_codegen_ssa/src/common.rs index 5a68075991f16..dc8a4f45f4ce2 100644 --- a/compiler/rustc_codegen_ssa/src/common.rs +++ b/compiler/rustc_codegen_ssa/src/common.rs @@ -198,7 +198,7 @@ pub fn asm_const_to_str<'tcx>( ty_and_layout: TyAndLayout<'tcx>, ) -> String { let ConstValue::Scalar(scalar) = const_value else { - span_bug!(sp, "expected Scalar for promoted asm const, but got {:#?}", const_value) + span_bug!(sp, "expected Scalar for promoted asm const, but got {const_value:#?}") }; let value = scalar.assert_bits(ty_and_layout.size); match ty_and_layout.ty.kind() { diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 4f26383ed05f0..dc16914cb9526 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -941,7 +941,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } } - span_bug!(span, "receiver has no non-zero-sized fields {:?}", op); + span_bug!(span, "receiver has no non-zero-sized fields {op:?}"); } // now that we have `*dyn Trait` or `&dyn Trait`, split it up into its @@ -983,13 +983,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } } - span_bug!(span, "receiver has no non-zero-sized fields {:?}", op); + span_bug!(span, "receiver has no non-zero-sized fields {op:?}"); } // Make sure that we've actually unwrapped the rcvr down // to a pointer or ref to `dyn* Trait`. if !op.layout.ty.builtin_deref(true).unwrap().ty.is_dyn_star() { - span_bug!(span, "can't codegen a virtual call on {:#?}", op); + span_bug!(span, "can't codegen a virtual call on {op:#?}"); } let place = op.deref(bx.cx()); let data_ptr = place.project_field(bx, 0); @@ -1005,7 +1005,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { continue; } _ => { - span_bug!(span, "can't codegen a virtual call on {:#?}", op); + span_bug!(span, "can't codegen a virtual call on {op:#?}"); } } } diff --git a/compiler/rustc_codegen_ssa/src/mir/mod.rs b/compiler/rustc_codegen_ssa/src/mir/mod.rs index 3464f910829da..07eaea3f36ff2 100644 --- a/compiler/rustc_codegen_ssa/src/mir/mod.rs +++ b/compiler/rustc_codegen_ssa/src/mir/mod.rs @@ -220,7 +220,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( // errored or at least linted ErrorHandled::Reported(_) => {} ErrorHandled::TooGeneric => { - span_bug!(const_.span, "codegen encountered polymorphic constant: {:?}", err) + span_bug!(const_.span, "codegen encountered polymorphic constant: {err:?}") } } } diff --git a/compiler/rustc_const_eval/src/interpret/cast.rs b/compiler/rustc_const_eval/src/interpret/cast.rs index 98e853dc4d9e0..52cc23e739bca 100644 --- a/compiler/rustc_const_eval/src/interpret/cast.rs +++ b/compiler/rustc_const_eval/src/interpret/cast.rs @@ -98,7 +98,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // No change to value self.write_immediate(*src, dest)?; } - _ => span_bug!(self.cur_span(), "fn to unsafe fn cast on {:?}", cast_ty), + _ => span_bug!(self.cur_span(), "fn to unsafe fn cast on {cast_ty:?}"), } } @@ -298,7 +298,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } // Casts to bool are not permitted by rustc, no need to handle them here. - _ => span_bug!(self.cur_span(), "invalid int to {:?} cast", cast_ty), + _ => span_bug!(self.cur_span(), "invalid int to {cast_ty:?} cast"), }) } @@ -331,7 +331,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // float -> f64 Float(FloatTy::F64) => Scalar::from_f64(f.convert(&mut false).value), // That's it. - _ => span_bug!(self.cur_span(), "invalid float to {:?} cast", dest_ty), + _ => span_bug!(self.cur_span(), "invalid float to {dest_ty:?} cast"), } } diff --git a/compiler/rustc_const_eval/src/interpret/intern.rs b/compiler/rustc_const_eval/src/interpret/intern.rs index 910c3ca5d0a97..6c4a717b6a009 100644 --- a/compiler/rustc_const_eval/src/interpret/intern.rs +++ b/compiler/rustc_const_eval/src/interpret/intern.rs @@ -443,7 +443,7 @@ pub fn intern_const_alloc_recursive< } else if ecx.tcx.try_get_global_alloc(alloc_id).is_none() { // We have hit an `AllocId` that is neither in local or global memory and isn't // marked as dangling by local memory. That should be impossible. - span_bug!(ecx.tcx.span, "encountered unknown alloc id {:?}", alloc_id); + span_bug!(ecx.tcx.span, "encountered unknown alloc id {alloc_id:?}"); } } Ok(()) diff --git a/compiler/rustc_const_eval/src/interpret/operator.rs b/compiler/rustc_const_eval/src/interpret/operator.rs index eb0645780673c..6a7a63e21adc6 100644 --- a/compiler/rustc_const_eval/src/interpret/operator.rs +++ b/compiler/rustc_const_eval/src/interpret/operator.rs @@ -76,7 +76,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { Le => l <= r, Gt => l > r, Ge => l >= r, - _ => span_bug!(self.cur_span(), "Invalid operation on char: {:?}", bin_op), + _ => span_bug!(self.cur_span(), "Invalid operation on char: {bin_op:?}"), }; (Scalar::from_bool(res), false, self.tcx.types.bool) } @@ -99,7 +99,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { BitAnd => l & r, BitOr => l | r, BitXor => l ^ r, - _ => span_bug!(self.cur_span(), "Invalid operation on bool: {:?}", bin_op), + _ => span_bug!(self.cur_span(), "Invalid operation on bool: {bin_op:?}"), }; (Scalar::from_bool(res), false, self.tcx.types.bool) } @@ -125,7 +125,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { Mul => ((l * r).value.into(), ty), Div => ((l / r).value.into(), ty), Rem => ((l % r).value.into(), ty), - _ => span_bug!(self.cur_span(), "invalid float op: `{:?}`", bin_op), + _ => span_bug!(self.cur_span(), "invalid float op: `{bin_op:?}`"), }; (val, false, ty) } @@ -453,7 +453,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let val = val.to_bool()?; let res = match un_op { Not => !val, - _ => span_bug!(self.cur_span(), "Invalid bool op {:?}", un_op), + _ => span_bug!(self.cur_span(), "Invalid bool op {un_op:?}"), }; Ok((Scalar::from_bool(res), false, self.tcx.types.bool)) } @@ -461,7 +461,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let res = match (un_op, fty) { (Neg, FloatTy::F32) => Scalar::from_f32(-val.to_f32()?), (Neg, FloatTy::F64) => Scalar::from_f64(-val.to_f64()?), - _ => span_bug!(self.cur_span(), "Invalid float op {:?}", un_op), + _ => span_bug!(self.cur_span(), "Invalid float op {un_op:?}"), }; Ok((res, false, layout.ty)) } diff --git a/compiler/rustc_const_eval/src/transform/check_consts/check.rs b/compiler/rustc_const_eval/src/transform/check_consts/check.rs index fae047bff9e79..74eebeebdc1cd 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/check.rs @@ -567,7 +567,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { } else if ty.is_floating_point() { self.check_op(ops::FloatingPointOp); } else { - span_bug!(self.span, "non-primitive type in `Rvalue::UnaryOp`: {:?}", ty); + span_bug!(self.span, "non-primitive type in `Rvalue::UnaryOp`: {ty:?}"); } } @@ -715,7 +715,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { return; } _ => { - span_bug!(terminator.source_info.span, "invalid callee of type {:?}", fn_ty) + span_bug!(terminator.source_info.span, "invalid callee of type {fn_ty:?}") } }; diff --git a/compiler/rustc_const_eval/src/transform/promote_consts.rs b/compiler/rustc_const_eval/src/transform/promote_consts.rs index d79c65f1d1fee..f9fcde3b37f51 100644 --- a/compiler/rustc_const_eval/src/transform/promote_consts.rs +++ b/compiler/rustc_const_eval/src/transform/promote_consts.rs @@ -249,7 +249,7 @@ impl<'tcx> Validator<'_, 'tcx> { Q::in_any_value_of_ty(&self.ccx, return_ty) } kind => { - span_bug!(terminator.source_info.span, "{:?} not promotable", kind); + span_bug!(terminator.source_info.span, "{kind:?} not promotable"); } } } @@ -290,7 +290,7 @@ impl<'tcx> Validator<'_, 'tcx> { } TerminatorKind::Yield { .. } => Err(Unpromotable), kind => { - span_bug!(terminator.source_info.span, "{:?} not promotable", kind); + span_bug!(terminator.source_info.span, "{kind:?} not promotable"); } } } @@ -738,7 +738,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { location } state => { - span_bug!(self.promoted.span, "{:?} not promotable: {:?}", temp, state); + span_bug!(self.promoted.span, "{temp:?} not promotable: {state:?}"); } }; if !self.keep_original { @@ -759,7 +759,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { let (mut rvalue, source_info) = { let statement = &mut self.source[loc.block].statements[loc.statement_index]; let StatementKind::Assign(box (_, rhs)) = &mut statement.kind else { - span_bug!(statement.source_info.span, "{:?} is not an assignment", statement); + span_bug!(statement.source_info.span, "{statement:?} is not an assignment"); }; ( @@ -787,7 +787,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { let target = match &terminator.kind { TerminatorKind::Call { target: Some(target), .. } => *target, kind => { - span_bug!(terminator.source_info.span, "{:?} not promotable", kind); + span_bug!(terminator.source_info.span, "{kind:?} not promotable"); } }; Terminator { @@ -823,7 +823,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { }; } kind => { - span_bug!(terminator.source_info.span, "{:?} not promotable", kind); + span_bug!(terminator.source_info.span, "{kind:?} not promotable"); } }; }; diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 7d660d2dbaa99..aaa84d34c6594 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -1486,13 +1486,13 @@ impl HandlerInner { self.failure(format!( "For more information about an error, try \ `rustc --explain {}`.", - &error_codes[0] + error_codes[0] )); } else { self.failure(format!( "For more information about this error, try \ `rustc --explain {}`.", - &error_codes[0] + error_codes[0] )); } } diff --git a/compiler/rustc_expand/src/mbe/metavar_expr.rs b/compiler/rustc_expand/src/mbe/metavar_expr.rs index b6382dcb89442..39e1fb1246b57 100644 --- a/compiler/rustc_expand/src/mbe/metavar_expr.rs +++ b/compiler/rustc_expand/src/mbe/metavar_expr.rs @@ -134,11 +134,11 @@ fn parse_ident<'sess>( let token_str = pprust::token_to_string(token); let mut err = sess.span_diagnostic.struct_span_err( span, - format!("expected identifier, found `{}`", &token_str) + format!("expected identifier, found `{token_str}`") ); err.span_suggestion( token.span, - format!("try removing `{}`", &token_str), + format!("try removing `{token_str}`"), "", Applicability::MaybeIncorrect, ); diff --git a/compiler/rustc_fluent_macro/src/fluent.rs b/compiler/rustc_fluent_macro/src/fluent.rs index 56e23ac277520..76ae8dd4914ca 100644 --- a/compiler/rustc_fluent_macro/src/fluent.rs +++ b/compiler/rustc_fluent_macro/src/fluent.rs @@ -243,7 +243,7 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok for Attribute { id: Identifier { name: attr_name }, .. } in attributes { let snake_name = Ident::new( - &format!("{}{}", &crate_prefix, &attr_name.replace('-', "_")), + &format!("{}{}", crate_prefix, attr_name.replace('-', "_")), resource_str.span(), ); if !previous_attrs.insert(snake_name.clone()) { diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index 5b06088c34814..ef80fe44e1007 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -1995,9 +1995,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Missing try_into implementation for `{integer}` to `{float}` err.multipart_suggestion_verbose( format!( - "{}, producing the floating point representation of the integer, \ - rounded if necessary", - &msg, + "{msg}, producing the floating point representation of the integer, \ + rounded if necessary" ), cast_suggestion, Applicability::MaybeIncorrect, // lossy conversion diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 72a04a02bf4fb..3cee73c283a8e 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -873,9 +873,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } ( match parent_pred { - None => format!("`{}`", &p), + None => format!("`{p}`"), Some(parent_pred) => match format_pred(*parent_pred) { - None => format!("`{}`", &p), + None => format!("`{p}`"), Some((parent_p, _)) => { if !suggested && !suggested_bounds.contains(pred) diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index 908ab8b613e88..0c09709715d6b 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -108,7 +108,7 @@ pub fn report_unstable( ) { let msg = match reason { Some(r) => format!("use of unstable library feature '{feature}': {r}"), - None => format!("use of unstable library feature '{}'", &feature), + None => format!("use of unstable library feature '{feature}'"), }; if is_soft { diff --git a/compiler/rustc_middle/src/mir/spanview.rs b/compiler/rustc_middle/src/mir/spanview.rs index 20a9e6889e40a..d78276e8cf769 100644 --- a/compiler/rustc_middle/src/mir/spanview.rs +++ b/compiler/rustc_middle/src/mir/spanview.rs @@ -624,7 +624,7 @@ fn tooltip<'tcx>( ) -> String { let source_map = tcx.sess.source_map(); let mut text = Vec::new(); - text.push(format!("{}: {}:", spanview_id, &source_map.span_to_embeddable_string(span))); + text.push(format!("{}: {}:", spanview_id, source_map.span_to_embeddable_string(span))); for statement in statements { let source_range = source_range_no_file(tcx, statement.source_info.span); text.push(format!( diff --git a/compiler/rustc_mir_build/src/thir/pattern/mod.rs b/compiler/rustc_mir_build/src/thir/pattern/mod.rs index c08fe54c39c4c..963f74763a1c7 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/mod.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/mod.rs @@ -231,8 +231,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { } None => { let msg = format!( - "found bad range pattern `{:?}` outside of error recovery", - (&lo, &hi), + "found bad range pattern `({lo:?}, {hi:?})` outside of error recovery" ); self.tcx.sess.delay_span_bug(pat.span, msg); PatKind::Wild @@ -267,7 +266,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { hir::PatKind::Tuple(ref pats, ddpos) => { let ty::Tuple(ref tys) = ty.kind() else { - span_bug!(pat.span, "unexpected type for tuple pattern: {:?}", ty); + span_bug!(pat.span, "unexpected type for tuple pattern: {ty:?}"); }; let subpatterns = self.lower_tuple_subpats(pats, tys.len(), ddpos); PatKind::Leaf { subpatterns } diff --git a/compiler/rustc_mir_transform/src/early_otherwise_branch.rs b/compiler/rustc_mir_transform/src/early_otherwise_branch.rs index 319fb4eaf3eca..dc14b1055b2fd 100644 --- a/compiler/rustc_mir_transform/src/early_otherwise_branch.rs +++ b/compiler/rustc_mir_transform/src/early_otherwise_branch.rs @@ -109,11 +109,11 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch { let parent = BasicBlock::from_usize(i); let Some(opt_data) = evaluate_candidate(tcx, body, parent) else { continue }; - if !tcx.consider_optimizing(|| format!("EarlyOtherwiseBranch {:?}", &opt_data)) { + if !tcx.consider_optimizing(|| format!("EarlyOtherwiseBranch {opt_data:?}")) { break; } - trace!("SUCCESS: found optimization possibility to apply: {:?}", &opt_data); + trace!("SUCCESS: found optimization possibility to apply: {opt_data:?}"); should_cleanup = true; diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index cd1a9b934cf53..dd8ce00216dc5 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -2591,7 +2591,7 @@ fn show_candidates( // from the directly following item. let additional_newline = if let FoundUse::No = found_use && let DiagnosticMode::Normal = mode { "\n" } else { "" }; candidate.0 = - format!("{add_use}{}{append}{trailing}{additional_newline}", &candidate.0); + format!("{add_use}{}{append}{trailing}{additional_newline}", candidate.0); } err.span_suggestions_with_style( diff --git a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs index d345368d552b8..025c5d9045934 100644 --- a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs +++ b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs @@ -656,7 +656,7 @@ fn encode_ty<'tcx>( s.push('E'); compress(dict, DictKey::Ty(Ty::new_imm_ref(tcx, *region, *ty0), TyQ::None), &mut s); if ty.is_mutable_ptr() { - s = format!("{}{}", "U3mut", &s); + s = format!("U3mut{s}"); compress(dict, DictKey::Ty(ty, TyQ::Mut), &mut s); } typeid.push_str(&s); @@ -667,10 +667,10 @@ fn encode_ty<'tcx>( let mut s = String::new(); s.push_str(&encode_ty(tcx, tm.ty, dict, options)); if !ty.is_mutable_ptr() { - s = format!("{}{}", "K", &s); + s = format!("K{s}"); compress(dict, DictKey::Ty(tm.ty, TyQ::Const), &mut s); }; - s = format!("{}{}", "P", &s); + s = format!("P{s}"); compress(dict, DictKey::Ty(ty, TyQ::None), &mut s); typeid.push_str(&s); } 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 5e075984238ee..22604d5fddc61 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -695,7 +695,8 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { term ); } else { - constraint.push_str(&format!("<{name} = {term}>")); + use std::fmt::Write as _; + write!(constraint, "<{name} = {term}>").unwrap(); } } @@ -1829,8 +1830,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { err.span_label( expr.span, format!( - "this expression has type `{}`, which implements `{}`", - ty, + "this expression has type `{ty}`, which implements `{}`", trait_pred.print_modifiers_and_trait_path() ) ); @@ -3051,31 +3051,43 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { err.span_note(self.tcx.def_span(def_id), msg) } ty::GeneratorWitness(bound_tys) => { - use std::fmt::Write; + use std::fmt::Write as _; // FIXME: this is kind of an unusual format for rustc, can we make it more clear? // Maybe we should just remove this note altogether? // FIXME: only print types which don't meet the trait requirement let mut msg = "required because it captures the following types: ".to_owned(); + let mut is_first = true; for ty in bound_tys.skip_binder() { - with_forced_trimmed_paths!(write!(msg, "`{ty}`, ").unwrap()); + if is_first { + is_first = false; + } else { + write!(msg, ", ").unwrap(); + } + with_forced_trimmed_paths!(write!(msg, "`{ty}`").unwrap()); } - err.note(msg.trim_end_matches(", ").to_string()) + err.note(msg) } ty::GeneratorWitnessMIR(def_id, args) => { - use std::fmt::Write; + use std::fmt::Write as _; // FIXME: this is kind of an unusual format for rustc, can we make it more clear? // Maybe we should just remove this note altogether? // FIXME: only print types which don't meet the trait requirement let mut msg = "required because it captures the following types: ".to_owned(); + let mut is_first = true; for bty in tcx.generator_hidden_types(*def_id) { let ty = bty.instantiate(tcx, args); - write!(msg, "`{ty}`, ").unwrap(); + if is_first { + is_first = false; + } else { + write!(msg, ", ").unwrap(); + } + write!(msg, "`{ty}`").unwrap(); } - err.note(msg.trim_end_matches(", ").to_string()) + err.note(msg) } ty::Generator(def_id, _, _) => { let sp = self.tcx.def_span(def_id);