Skip to content

Commit 564c583

Browse files
authored
Rollup merge of #95422 - TaKO8Ki:use-format-args-capture-and-remove-unnecessary-nesting-in-rustc-typeck, r=petrochenkov
Refactor: Use `format-args-capture` and remove an unnecessary nested block
2 parents eceb173 + f2506c9 commit 564c583

File tree

1 file changed

+28
-32
lines changed
  • compiler/rustc_typeck/src/check

1 file changed

+28
-32
lines changed

compiler/rustc_typeck/src/check/op.rs

+28-32
Original file line numberDiff line numberDiff line change
@@ -299,52 +299,52 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
299299
IsAssign::No => {
300300
let (message, missing_trait, use_output) = match op.node {
301301
hir::BinOpKind::Add => (
302-
format!("cannot add `{}` to `{}`", rhs_ty, lhs_ty),
302+
format!("cannot add `{rhs_ty}` to `{lhs_ty}`"),
303303
Some("std::ops::Add"),
304304
true,
305305
),
306306
hir::BinOpKind::Sub => (
307-
format!("cannot subtract `{}` from `{}`", rhs_ty, lhs_ty),
307+
format!("cannot subtract `{rhs_ty}` from `{lhs_ty}`"),
308308
Some("std::ops::Sub"),
309309
true,
310310
),
311311
hir::BinOpKind::Mul => (
312-
format!("cannot multiply `{}` by `{}`", lhs_ty, rhs_ty),
312+
format!("cannot multiply `{lhs_ty}` by `{rhs_ty}`"),
313313
Some("std::ops::Mul"),
314314
true,
315315
),
316316
hir::BinOpKind::Div => (
317-
format!("cannot divide `{}` by `{}`", lhs_ty, rhs_ty),
317+
format!("cannot divide `{lhs_ty}` by `{rhs_ty}`"),
318318
Some("std::ops::Div"),
319319
true,
320320
),
321321
hir::BinOpKind::Rem => (
322-
format!("cannot mod `{}` by `{}`", lhs_ty, rhs_ty),
322+
format!("cannot mod `{lhs_ty}` by `{rhs_ty}`"),
323323
Some("std::ops::Rem"),
324324
true,
325325
),
326326
hir::BinOpKind::BitAnd => (
327-
format!("no implementation for `{} & {}`", lhs_ty, rhs_ty),
327+
format!("no implementation for `{lhs_ty} & {rhs_ty}`"),
328328
Some("std::ops::BitAnd"),
329329
true,
330330
),
331331
hir::BinOpKind::BitXor => (
332-
format!("no implementation for `{} ^ {}`", lhs_ty, rhs_ty),
332+
format!("no implementation for `{lhs_ty} ^ {rhs_ty}`"),
333333
Some("std::ops::BitXor"),
334334
true,
335335
),
336336
hir::BinOpKind::BitOr => (
337-
format!("no implementation for `{} | {}`", lhs_ty, rhs_ty),
337+
format!("no implementation for `{lhs_ty} | {rhs_ty}`"),
338338
Some("std::ops::BitOr"),
339339
true,
340340
),
341341
hir::BinOpKind::Shl => (
342-
format!("no implementation for `{} << {}`", lhs_ty, rhs_ty),
342+
format!("no implementation for `{lhs_ty} << {rhs_ty}`"),
343343
Some("std::ops::Shl"),
344344
true,
345345
),
346346
hir::BinOpKind::Shr => (
347-
format!("no implementation for `{} >> {}`", lhs_ty, rhs_ty),
347+
format!("no implementation for `{lhs_ty} >> {rhs_ty}`"),
348348
Some("std::ops::Shr"),
349349
true,
350350
),
@@ -477,8 +477,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
477477
// When we know that a missing bound is responsible, we don't show
478478
// this note as it is redundant.
479479
err.note(&format!(
480-
"the trait `{}` is not implemented for `{}`",
481-
missing_trait, lhs_ty
480+
"the trait `{missing_trait}` is not implemented for `{lhs_ty}`"
482481
));
483482
}
484483
} else {
@@ -679,19 +678,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
679678
};
680679
let mut visitor = TypeParamVisitor(vec![]);
681680
visitor.visit_ty(operand_ty);
682-
if let [ty] = &visitor.0[..] {
683-
if let ty::Param(p) = *operand_ty.kind() {
684-
suggest_constraining_param(
685-
self.tcx,
686-
self.body_id,
687-
&mut err,
688-
*ty,
689-
operand_ty,
690-
missing_trait,
691-
p,
692-
true,
693-
);
694-
}
681+
if let [ty] = &visitor.0[..] && let ty::Param(p) = *operand_ty.kind() {
682+
suggest_constraining_param(
683+
self.tcx,
684+
self.body_id,
685+
&mut err,
686+
*ty,
687+
operand_ty,
688+
missing_trait,
689+
p,
690+
true,
691+
);
695692
}
696693

697694
let sp = self.tcx.sess.source_map().start_point(ex.span);
@@ -722,10 +719,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
722719
err.span_suggestion(
723720
ex.span,
724721
&format!(
725-
"you may have meant the maximum value of `{}`",
726-
actual
722+
"you may have meant the maximum value of `{actual}`",
727723
),
728-
format!("{}::MAX", actual),
724+
format!("{actual}::MAX"),
729725
Applicability::MaybeIncorrect,
730726
);
731727
}
@@ -988,7 +984,7 @@ fn suggest_constraining_param(
988984
set_output: bool,
989985
) {
990986
let hir = tcx.hir();
991-
let msg = &format!("`{}` might need a bound for `{}`", lhs_ty, missing_trait);
987+
let msg = &format!("`{lhs_ty}` might need a bound for `{missing_trait}`");
992988
// Try to find the def-id and details for the parameter p. We have only the index,
993989
// so we have to find the enclosing function's def-id, then look through its declared
994990
// generic parameters to get the declaration.
@@ -1002,13 +998,13 @@ fn suggest_constraining_param(
1002998
.as_ref()
1003999
.and_then(|node| node.generics())
10041000
{
1005-
let output = if set_output { format!("<Output = {}>", rhs_ty) } else { String::new() };
1001+
let output = if set_output { format!("<Output = {rhs_ty}>") } else { String::new() };
10061002
suggest_constraining_type_param(
10071003
tcx,
10081004
generics,
10091005
&mut err,
1010-
&format!("{}", lhs_ty),
1011-
&format!("{}{}", missing_trait, output),
1006+
&lhs_ty.to_string(),
1007+
&format!("{missing_trait}{output}"),
10121008
None,
10131009
);
10141010
} else {

0 commit comments

Comments
 (0)