Skip to content

Commit aa41c98

Browse files
Make Option<&dyn FnMut> into impl FnOnce
1 parent a63bb24 commit aa41c98

File tree

4 files changed

+13
-17
lines changed

4 files changed

+13
-17
lines changed

compiler/rustc_hir_typeck/src/_match.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
136136
&cause,
137137
Some(&arm.body),
138138
arm_ty,
139-
Some(&mut |err| {
140-
self.suggest_removing_semicolon_for_coerce(err, expr, arm_ty, prior_arm)
141-
}),
139+
|err| self.suggest_removing_semicolon_for_coerce(err, expr, arm_ty, prior_arm),
142140
false,
143141
);
144142

@@ -269,7 +267,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
269267
coercion.coerce_forced_unit(
270268
self,
271269
&cause,
272-
&mut |err| {
270+
|err| {
273271
if let Some((span, msg)) = &ret_reason {
274272
err.span_label(*span, msg.clone());
275273
} else if let ExprKind::Block(block, _) = &then_expr.kind

compiler/rustc_hir_typeck/src/coercion.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
14181418
expression: &'tcx hir::Expr<'tcx>,
14191419
expression_ty: Ty<'tcx>,
14201420
) {
1421-
self.coerce_inner(fcx, cause, Some(expression), expression_ty, None, false)
1421+
self.coerce_inner(fcx, cause, Some(expression), expression_ty, |_| {}, false)
14221422
}
14231423

14241424
/// Indicates that one of the inputs is a "forced unit". This
@@ -1437,15 +1437,15 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
14371437
&mut self,
14381438
fcx: &FnCtxt<'a, 'tcx>,
14391439
cause: &ObligationCause<'tcx>,
1440-
augment_error: &mut dyn FnMut(&mut Diagnostic),
1440+
augment_error: impl FnOnce(&mut Diagnostic),
14411441
label_unit_as_expected: bool,
14421442
) {
14431443
self.coerce_inner(
14441444
fcx,
14451445
cause,
14461446
None,
14471447
Ty::new_unit(fcx.tcx),
1448-
Some(augment_error),
1448+
augment_error,
14491449
label_unit_as_expected,
14501450
)
14511451
}
@@ -1460,7 +1460,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
14601460
cause: &ObligationCause<'tcx>,
14611461
expression: Option<&'tcx hir::Expr<'tcx>>,
14621462
mut expression_ty: Ty<'tcx>,
1463-
augment_error: Option<&mut dyn FnMut(&mut Diagnostic)>,
1463+
augment_error: impl FnOnce(&mut Diagnostic),
14641464
label_expression_as_expected: bool,
14651465
) {
14661466
// Incorporate whatever type inference information we have
@@ -1639,9 +1639,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
16391639
}
16401640
}
16411641

1642-
if let Some(augment_error) = augment_error {
1643-
augment_error(&mut err);
1644-
}
1642+
augment_error(&mut err);
16451643

16461644
let is_insufficiently_polymorphic =
16471645
matches!(coercion_error, TypeError::RegionsInsufficientlyPolymorphic(..));

compiler/rustc_hir_typeck/src/expr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
652652
coerce.coerce_forced_unit(
653653
self,
654654
&cause,
655-
&mut |mut err| {
655+
|mut err| {
656656
self.suggest_mismatched_types_on_tail(
657657
&mut err, expr, ty, e_ty, target_id,
658658
);
@@ -748,7 +748,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
748748
coercion.coerce_forced_unit(
749749
self,
750750
&cause,
751-
&mut |db| {
751+
|db| {
752752
let span = fn_decl.output.span();
753753
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
754754
db.span_label(
@@ -760,7 +760,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
760760
true,
761761
);
762762
} else {
763-
coercion.coerce_forced_unit(self, &cause, &mut |_| (), true);
763+
coercion.coerce_forced_unit(self, &cause, |_| (), true);
764764
}
765765
}
766766
self.tcx.types.never

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1587,9 +1587,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15871587
&cause,
15881588
Some(tail_expr),
15891589
tail_expr_ty,
1590-
Some(&mut |diag: &mut Diagnostic| {
1590+
|diag| {
15911591
self.suggest_block_to_brackets(diag, blk, tail_expr_ty, ty_for_diagnostic);
1592-
}),
1592+
},
15931593
false,
15941594
);
15951595
} else {
@@ -1626,7 +1626,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16261626
coerce.coerce_forced_unit(
16271627
self,
16281628
&self.misc(sp),
1629-
&mut |err| {
1629+
|err| {
16301630
if let Some(expected_ty) = expected.only_has_type(self) {
16311631
if blk.stmts.is_empty() && blk.expr.is_none() {
16321632
self.suggest_boxing_when_appropriate(

0 commit comments

Comments
 (0)