Skip to content

Commit 7c52927

Browse files
Consolidate two arms doing the same thing
1 parent 9f4230c commit 7c52927

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,39 +1962,36 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
19621962
// Verify that this is a tail expression of a function, otherwise the
19631963
// label pointing out the cause for the type coercion will be wrong
19641964
// as prior return coercions would not be relevant (#57664).
1965-
let fn_decl = if let (Some(expr), Some(blk_id)) = (expression, blk_id) {
1965+
if let Some(expr) = expression
1966+
&& let Some(blk_id) = blk_id
1967+
{
19661968
fcx.suggest_missing_semicolon(&mut err, expr, expected, false);
19671969
let pointing_at_return_type =
19681970
fcx.suggest_mismatched_types_on_tail(&mut err, expr, expected, found, blk_id);
1969-
if let (Some(cond_expr), true, false) = (
1970-
fcx.tcx.hir().get_if_cause(expr.hir_id),
1971-
expected.is_unit(),
1972-
pointing_at_return_type,
1973-
)
1971+
if let Some(cond_expr) = fcx.tcx.hir().get_if_cause(expr.hir_id)
1972+
&& expected.is_unit()
1973+
&& !pointing_at_return_type
19741974
// If the block is from an external macro or try (`?`) desugaring, then
19751975
// do not suggest adding a semicolon, because there's nowhere to put it.
19761976
// See issues #81943 and #87051.
19771977
&& matches!(
19781978
cond_expr.span.desugaring_kind(),
19791979
None | Some(DesugaringKind::WhileLoop)
1980-
) && !in_external_macro(fcx.tcx.sess, cond_expr.span)
1981-
&& !matches!(
1982-
cond_expr.kind,
1983-
hir::ExprKind::Match(.., hir::MatchSource::TryDesugar(_))
1984-
)
1980+
)
1981+
&& !in_external_macro(fcx.tcx.sess, cond_expr.span)
1982+
&& !matches!(
1983+
cond_expr.kind,
1984+
hir::ExprKind::Match(.., hir::MatchSource::TryDesugar(_))
1985+
)
19851986
{
19861987
err.span_label(cond_expr.span, "expected this to be `()`");
19871988
if expr.can_have_side_effects() {
19881989
fcx.suggest_semicolon_at_end(cond_expr.span, &mut err);
19891990
}
19901991
}
1991-
fcx.get_node_fn_decl(parent)
1992-
.map(|(fn_id, fn_decl, _, is_main)| (fn_id, fn_decl, is_main))
1993-
} else {
1994-
fcx.get_fn_decl(parent_id)
19951992
};
19961993

1997-
if let Some((fn_id, fn_decl, can_suggest)) = fn_decl {
1994+
if let Some((fn_id, fn_decl, can_suggest)) = fcx.get_fn_decl(parent_id) {
19981995
if blk_id.is_none() {
19991996
fcx.suggest_missing_return_type(
20001997
&mut err,

0 commit comments

Comments
 (0)