Make Option<&dyn FnMut> into impl FnOnce

This commit is contained in:
Michael Goulet 2023-08-03 04:33:07 +00:00
parent a63bb24593
commit aa41c98737
4 changed files with 13 additions and 17 deletions

View File

@ -136,9 +136,7 @@ pub fn check_match(
&cause,
Some(&arm.body),
arm_ty,
Some(&mut |err| {
self.suggest_removing_semicolon_for_coerce(err, expr, arm_ty, prior_arm)
}),
|err| self.suggest_removing_semicolon_for_coerce(err, expr, arm_ty, prior_arm),
false,
);
@ -269,7 +267,7 @@ pub(super) fn if_fallback_coercion<T>(
coercion.coerce_forced_unit(
self,
&cause,
&mut |err| {
|err| {
if let Some((span, msg)) = &ret_reason {
err.span_label(*span, msg.clone());
} else if let ExprKind::Block(block, _) = &then_expr.kind

View File

@ -1418,7 +1418,7 @@ pub fn coerce<'a>(
expression: &'tcx hir::Expr<'tcx>,
expression_ty: Ty<'tcx>,
) {
self.coerce_inner(fcx, cause, Some(expression), expression_ty, None, false)
self.coerce_inner(fcx, cause, Some(expression), expression_ty, |_| {}, false)
}
/// Indicates that one of the inputs is a "forced unit". This
@ -1437,7 +1437,7 @@ pub fn coerce_forced_unit<'a>(
&mut self,
fcx: &FnCtxt<'a, 'tcx>,
cause: &ObligationCause<'tcx>,
augment_error: &mut dyn FnMut(&mut Diagnostic),
augment_error: impl FnOnce(&mut Diagnostic),
label_unit_as_expected: bool,
) {
self.coerce_inner(
@ -1445,7 +1445,7 @@ pub fn coerce_forced_unit<'a>(
cause,
None,
Ty::new_unit(fcx.tcx),
Some(augment_error),
augment_error,
label_unit_as_expected,
)
}
@ -1460,7 +1460,7 @@ pub(crate) fn coerce_inner<'a>(
cause: &ObligationCause<'tcx>,
expression: Option<&'tcx hir::Expr<'tcx>>,
mut expression_ty: Ty<'tcx>,
augment_error: Option<&mut dyn FnMut(&mut Diagnostic)>,
augment_error: impl FnOnce(&mut Diagnostic),
label_expression_as_expected: bool,
) {
// Incorporate whatever type inference information we have
@ -1639,9 +1639,7 @@ pub(crate) fn coerce_inner<'a>(
}
}
if let Some(augment_error) = augment_error {
augment_error(&mut err);
}
augment_error(&mut err);
let is_insufficiently_polymorphic =
matches!(coercion_error, TypeError::RegionsInsufficientlyPolymorphic(..));

View File

@ -652,7 +652,7 @@ fn check_expr_break(
coerce.coerce_forced_unit(
self,
&cause,
&mut |mut err| {
|mut err| {
self.suggest_mismatched_types_on_tail(
&mut err, expr, ty, e_ty, target_id,
);
@ -748,7 +748,7 @@ fn check_expr_return(
coercion.coerce_forced_unit(
self,
&cause,
&mut |db| {
|db| {
let span = fn_decl.output.span();
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
db.span_label(
@ -760,7 +760,7 @@ fn check_expr_return(
true,
);
} else {
coercion.coerce_forced_unit(self, &cause, &mut |_| (), true);
coercion.coerce_forced_unit(self, &cause, |_| (), true);
}
}
self.tcx.types.never

View File

@ -1587,9 +1587,9 @@ pub(in super::super) fn check_block_with_expected(
&cause,
Some(tail_expr),
tail_expr_ty,
Some(&mut |diag: &mut Diagnostic| {
|diag| {
self.suggest_block_to_brackets(diag, blk, tail_expr_ty, ty_for_diagnostic);
}),
},
false,
);
} else {
@ -1626,7 +1626,7 @@ pub(in super::super) fn check_block_with_expected(
coerce.coerce_forced_unit(
self,
&self.misc(sp),
&mut |err| {
|err| {
if let Some(expected_ty) = expected.only_has_type(self) {
if blk.stmts.is_empty() && blk.expr.is_none() {
self.suggest_boxing_when_appropriate(