use format-args-capture and remove an unnecessary nested block
This commit is contained in:
parent
c1230e137b
commit
f2506c911b
1 changed files with 28 additions and 32 deletions
|
@ -299,52 +299,52 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
IsAssign::No => {
|
IsAssign::No => {
|
||||||
let (message, missing_trait, use_output) = match op.node {
|
let (message, missing_trait, use_output) = match op.node {
|
||||||
hir::BinOpKind::Add => (
|
hir::BinOpKind::Add => (
|
||||||
format!("cannot add `{}` to `{}`", rhs_ty, lhs_ty),
|
format!("cannot add `{rhs_ty}` to `{lhs_ty}`"),
|
||||||
Some("std::ops::Add"),
|
Some("std::ops::Add"),
|
||||||
true,
|
true,
|
||||||
),
|
),
|
||||||
hir::BinOpKind::Sub => (
|
hir::BinOpKind::Sub => (
|
||||||
format!("cannot subtract `{}` from `{}`", rhs_ty, lhs_ty),
|
format!("cannot subtract `{rhs_ty}` from `{lhs_ty}`"),
|
||||||
Some("std::ops::Sub"),
|
Some("std::ops::Sub"),
|
||||||
true,
|
true,
|
||||||
),
|
),
|
||||||
hir::BinOpKind::Mul => (
|
hir::BinOpKind::Mul => (
|
||||||
format!("cannot multiply `{}` by `{}`", lhs_ty, rhs_ty),
|
format!("cannot multiply `{lhs_ty}` by `{rhs_ty}`"),
|
||||||
Some("std::ops::Mul"),
|
Some("std::ops::Mul"),
|
||||||
true,
|
true,
|
||||||
),
|
),
|
||||||
hir::BinOpKind::Div => (
|
hir::BinOpKind::Div => (
|
||||||
format!("cannot divide `{}` by `{}`", lhs_ty, rhs_ty),
|
format!("cannot divide `{lhs_ty}` by `{rhs_ty}`"),
|
||||||
Some("std::ops::Div"),
|
Some("std::ops::Div"),
|
||||||
true,
|
true,
|
||||||
),
|
),
|
||||||
hir::BinOpKind::Rem => (
|
hir::BinOpKind::Rem => (
|
||||||
format!("cannot mod `{}` by `{}`", lhs_ty, rhs_ty),
|
format!("cannot mod `{lhs_ty}` by `{rhs_ty}`"),
|
||||||
Some("std::ops::Rem"),
|
Some("std::ops::Rem"),
|
||||||
true,
|
true,
|
||||||
),
|
),
|
||||||
hir::BinOpKind::BitAnd => (
|
hir::BinOpKind::BitAnd => (
|
||||||
format!("no implementation for `{} & {}`", lhs_ty, rhs_ty),
|
format!("no implementation for `{lhs_ty} & {rhs_ty}`"),
|
||||||
Some("std::ops::BitAnd"),
|
Some("std::ops::BitAnd"),
|
||||||
true,
|
true,
|
||||||
),
|
),
|
||||||
hir::BinOpKind::BitXor => (
|
hir::BinOpKind::BitXor => (
|
||||||
format!("no implementation for `{} ^ {}`", lhs_ty, rhs_ty),
|
format!("no implementation for `{lhs_ty} ^ {rhs_ty}`"),
|
||||||
Some("std::ops::BitXor"),
|
Some("std::ops::BitXor"),
|
||||||
true,
|
true,
|
||||||
),
|
),
|
||||||
hir::BinOpKind::BitOr => (
|
hir::BinOpKind::BitOr => (
|
||||||
format!("no implementation for `{} | {}`", lhs_ty, rhs_ty),
|
format!("no implementation for `{lhs_ty} | {rhs_ty}`"),
|
||||||
Some("std::ops::BitOr"),
|
Some("std::ops::BitOr"),
|
||||||
true,
|
true,
|
||||||
),
|
),
|
||||||
hir::BinOpKind::Shl => (
|
hir::BinOpKind::Shl => (
|
||||||
format!("no implementation for `{} << {}`", lhs_ty, rhs_ty),
|
format!("no implementation for `{lhs_ty} << {rhs_ty}`"),
|
||||||
Some("std::ops::Shl"),
|
Some("std::ops::Shl"),
|
||||||
true,
|
true,
|
||||||
),
|
),
|
||||||
hir::BinOpKind::Shr => (
|
hir::BinOpKind::Shr => (
|
||||||
format!("no implementation for `{} >> {}`", lhs_ty, rhs_ty),
|
format!("no implementation for `{lhs_ty} >> {rhs_ty}`"),
|
||||||
Some("std::ops::Shr"),
|
Some("std::ops::Shr"),
|
||||||
true,
|
true,
|
||||||
),
|
),
|
||||||
|
@ -477,8 +477,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
// When we know that a missing bound is responsible, we don't show
|
// When we know that a missing bound is responsible, we don't show
|
||||||
// this note as it is redundant.
|
// this note as it is redundant.
|
||||||
err.note(&format!(
|
err.note(&format!(
|
||||||
"the trait `{}` is not implemented for `{}`",
|
"the trait `{missing_trait}` is not implemented for `{lhs_ty}`"
|
||||||
missing_trait, lhs_ty
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -679,19 +678,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
};
|
};
|
||||||
let mut visitor = TypeParamVisitor(vec![]);
|
let mut visitor = TypeParamVisitor(vec![]);
|
||||||
visitor.visit_ty(operand_ty);
|
visitor.visit_ty(operand_ty);
|
||||||
if let [ty] = &visitor.0[..] {
|
if let [ty] = &visitor.0[..] && let ty::Param(p) = *operand_ty.kind() {
|
||||||
if let ty::Param(p) = *operand_ty.kind() {
|
suggest_constraining_param(
|
||||||
suggest_constraining_param(
|
self.tcx,
|
||||||
self.tcx,
|
self.body_id,
|
||||||
self.body_id,
|
&mut err,
|
||||||
&mut err,
|
*ty,
|
||||||
*ty,
|
operand_ty,
|
||||||
operand_ty,
|
missing_trait,
|
||||||
missing_trait,
|
p,
|
||||||
p,
|
true,
|
||||||
true,
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let sp = self.tcx.sess.source_map().start_point(ex.span);
|
let sp = self.tcx.sess.source_map().start_point(ex.span);
|
||||||
|
@ -722,10 +719,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
err.span_suggestion(
|
err.span_suggestion(
|
||||||
ex.span,
|
ex.span,
|
||||||
&format!(
|
&format!(
|
||||||
"you may have meant the maximum value of `{}`",
|
"you may have meant the maximum value of `{actual}`",
|
||||||
actual
|
|
||||||
),
|
),
|
||||||
format!("{}::MAX", actual),
|
format!("{actual}::MAX"),
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -988,7 +984,7 @@ fn suggest_constraining_param(
|
||||||
set_output: bool,
|
set_output: bool,
|
||||||
) {
|
) {
|
||||||
let hir = tcx.hir();
|
let hir = tcx.hir();
|
||||||
let msg = &format!("`{}` might need a bound for `{}`", lhs_ty, missing_trait);
|
let msg = &format!("`{lhs_ty}` might need a bound for `{missing_trait}`");
|
||||||
// Try to find the def-id and details for the parameter p. We have only the index,
|
// Try to find the def-id and details for the parameter p. We have only the index,
|
||||||
// so we have to find the enclosing function's def-id, then look through its declared
|
// so we have to find the enclosing function's def-id, then look through its declared
|
||||||
// generic parameters to get the declaration.
|
// generic parameters to get the declaration.
|
||||||
|
@ -1002,13 +998,13 @@ fn suggest_constraining_param(
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|node| node.generics())
|
.and_then(|node| node.generics())
|
||||||
{
|
{
|
||||||
let output = if set_output { format!("<Output = {}>", rhs_ty) } else { String::new() };
|
let output = if set_output { format!("<Output = {rhs_ty}>") } else { String::new() };
|
||||||
suggest_constraining_type_param(
|
suggest_constraining_type_param(
|
||||||
tcx,
|
tcx,
|
||||||
generics,
|
generics,
|
||||||
&mut err,
|
&mut err,
|
||||||
&format!("{}", lhs_ty),
|
&lhs_ty.to_string(),
|
||||||
&format!("{}{}", missing_trait, output),
|
&format!("{missing_trait}{output}"),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue