Skip to content

Commit 3c78a4c

Browse files
Consolidate two arms doing the same thing
1 parent 8305903 commit 3c78a4c

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
@@ -1959,39 +1959,36 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
19591959
// Verify that this is a tail expression of a function, otherwise the
19601960
// label pointing out the cause for the type coercion will be wrong
19611961
// as prior return coercions would not be relevant (#57664).
1962-
let fn_decl = if let (Some(expr), Some(blk_id)) = (expression, blk_id) {
1962+
if let Some(expr) = expression
1963+
&& let Some(blk_id) = blk_id
1964+
{
19631965
fcx.suggest_missing_semicolon(&mut err, expr, expected, false);
19641966
let pointing_at_return_type =
19651967
fcx.suggest_mismatched_types_on_tail(&mut err, expr, expected, found, blk_id);
1966-
if let (Some(cond_expr), true, false) = (
1967-
fcx.tcx.hir().get_if_cause(expr.hir_id),
1968-
expected.is_unit(),
1969-
pointing_at_return_type,
1970-
)
1968+
if let Some(cond_expr) = fcx.tcx.hir().get_if_cause(expr.hir_id)
1969+
&& expected.is_unit()
1970+
&& !pointing_at_return_type
19711971
// If the block is from an external macro or try (`?`) desugaring, then
19721972
// do not suggest adding a semicolon, because there's nowhere to put it.
19731973
// See issues #81943 and #87051.
19741974
&& matches!(
19751975
cond_expr.span.desugaring_kind(),
19761976
None | Some(DesugaringKind::WhileLoop)
1977-
) && !in_external_macro(fcx.tcx.sess, cond_expr.span)
1978-
&& !matches!(
1979-
cond_expr.kind,
1980-
hir::ExprKind::Match(.., hir::MatchSource::TryDesugar(_))
1981-
)
1977+
)
1978+
&& !in_external_macro(fcx.tcx.sess, cond_expr.span)
1979+
&& !matches!(
1980+
cond_expr.kind,
1981+
hir::ExprKind::Match(.., hir::MatchSource::TryDesugar(_))
1982+
)
19821983
{
19831984
err.span_label(cond_expr.span, "expected this to be `()`");
19841985
if expr.can_have_side_effects() {
19851986
fcx.suggest_semicolon_at_end(cond_expr.span, &mut err);
19861987
}
19871988
}
1988-
fcx.get_node_fn_decl(parent)
1989-
.map(|(fn_id, fn_decl, _, is_main)| (fn_id, fn_decl, is_main))
1990-
} else {
1991-
fcx.get_fn_decl(parent_id)
19921989
};
19931990

1994-
if let Some((fn_id, fn_decl, can_suggest)) = fn_decl {
1991+
if let Some((fn_id, fn_decl, can_suggest)) = fcx.get_fn_decl(parent_id) {
19951992
if blk_id.is_none() {
19961993
fcx.suggest_missing_return_type(
19971994
&mut err,

0 commit comments

Comments
 (0)