From aa41c9873762af552369822da5361c5bdfe438cb Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 3 Aug 2023 04:33:07 +0000 Subject: [PATCH] Make Option<&dyn FnMut> into impl FnOnce --- compiler/rustc_hir_typeck/src/_match.rs | 6 ++---- compiler/rustc_hir_typeck/src/coercion.rs | 12 +++++------- compiler/rustc_hir_typeck/src/expr.rs | 6 +++--- compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs | 6 +++--- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/_match.rs b/compiler/rustc_hir_typeck/src/_match.rs index f32327ad21b..c2d987a95cf 100644 --- a/compiler/rustc_hir_typeck/src/_match.rs +++ b/compiler/rustc_hir_typeck/src/_match.rs @@ -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( 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 diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 4fdfc51bc86..fa6bad84376 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -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(..)); diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 401eff3d5c8..80d7cc57edb 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -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 diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 302b5fd8d9c..94c54197294 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -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(