Skip to content

Commit dc60dc0

Browse files
Remove redundant blk_id parameter
1 parent e239328 commit dc60dc0

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,7 +1627,6 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
16271627
fcx,
16281628
blk_id,
16291629
expression,
1630-
Some(blk_id),
16311630
);
16321631
if !fcx.tcx.features().unsized_locals {
16331632
unsized_return = self.is_return_ty_definitely_unsized(fcx);
@@ -1638,16 +1637,15 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
16381637
intravisit::walk_block(&mut visitor, loop_blk);
16391638
}
16401639
}
1641-
ObligationCauseCode::ReturnValue(id) => {
1640+
ObligationCauseCode::ReturnValue(return_expr_id) => {
16421641
err = self.report_return_mismatched_types(
16431642
cause,
16441643
expected,
16451644
found,
16461645
coercion_error,
16471646
fcx,
1648-
id,
1647+
return_expr_id,
16491648
expression,
1650-
None,
16511649
);
16521650
if !fcx.tcx.features().unsized_locals {
16531651
unsized_return = self.is_return_ty_definitely_unsized(fcx);
@@ -1938,13 +1936,14 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
19381936
found: Ty<'tcx>,
19391937
ty_err: TypeError<'tcx>,
19401938
fcx: &FnCtxt<'a, 'tcx>,
1941-
id: hir::HirId,
1939+
block_or_return_id: hir::HirId,
19421940
expression: Option<&'tcx hir::Expr<'tcx>>,
1943-
blk_id: Option<hir::HirId>,
19441941
) -> Diag<'a> {
19451942
let mut err = fcx.err_ctxt().report_mismatched_types(cause, expected, found, ty_err);
19461943

1947-
let parent_id = fcx.tcx.parent_hir_id(id);
1944+
let due_to_block = matches!(fcx.tcx.hir_node(block_or_return_id), hir::Node::Block(..));
1945+
1946+
let parent_id = fcx.tcx.parent_hir_id(block_or_return_id);
19481947
let parent = fcx.tcx.hir_node(parent_id);
19491948
if let Some(expr) = expression
19501949
&& let hir::Node::Expr(hir::Expr {
@@ -1959,11 +1958,16 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
19591958
// label pointing out the cause for the type coercion will be wrong
19601959
// as prior return coercions would not be relevant (#57664).
19611960
if let Some(expr) = expression
1962-
&& let Some(blk_id) = blk_id
1961+
&& due_to_block
19631962
{
19641963
fcx.suggest_missing_semicolon(&mut err, expr, expected, false);
1965-
let pointing_at_return_type =
1966-
fcx.suggest_mismatched_types_on_tail(&mut err, expr, expected, found, blk_id);
1964+
let pointing_at_return_type = fcx.suggest_mismatched_types_on_tail(
1965+
&mut err,
1966+
expr,
1967+
expected,
1968+
found,
1969+
block_or_return_id,
1970+
);
19671971
if let Some(cond_expr) = fcx.tcx.hir().get_if_cause(expr.hir_id)
19681972
&& expected.is_unit()
19691973
&& !pointing_at_return_type
@@ -1987,23 +1991,17 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
19871991
}
19881992
};
19891993

1990-
if let Some((fn_id, fn_decl, can_suggest)) = fcx.get_fn_decl(parent_id) {
1991-
if blk_id.is_none() {
1992-
fcx.suggest_missing_return_type(
1993-
&mut err,
1994-
fn_decl,
1995-
expected,
1996-
found,
1997-
can_suggest,
1998-
fn_id,
1999-
);
2000-
}
1994+
if let Some((fn_id, fn_decl, can_suggest)) = fcx.get_fn_decl(parent_id)
1995+
&& !due_to_block
1996+
{
1997+
fcx.suggest_missing_return_type(&mut err, fn_decl, expected, found, can_suggest, fn_id);
20011998
}
20021999

2003-
let mut parent_id = fcx.tcx.hir().get_parent_item(id).def_id;
2000+
let mut parent_id = fcx.tcx.hir().get_parent_item(block_or_return_id).def_id;
20042001
let mut parent_item = fcx.tcx.hir_node_by_def_id(parent_id);
20052002
// When suggesting return, we need to account for closures and async blocks, not just items.
2006-
for (_, node) in fcx.tcx.hir().parent_iter(id) {
2003+
// FIXME: fix get_fn_decl to be async block aware, use get_fn_decl results above
2004+
for (_, node) in fcx.tcx.hir().parent_iter(block_or_return_id) {
20072005
match node {
20082006
hir::Node::Expr(&hir::Expr {
20092007
kind: hir::ExprKind::Closure(hir::Closure { def_id, .. }),
@@ -2018,9 +2016,18 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
20182016
}
20192017
}
20202018

2021-
if let (Some(expr), Some(_), Some(fn_decl)) = (expression, blk_id, parent_item.fn_decl()) {
2019+
if let Some(expr) = expression
2020+
&& let Some(fn_decl) = parent_item.fn_decl()
2021+
&& due_to_block
2022+
{
20222023
fcx.suggest_missing_break_or_return_expr(
2023-
&mut err, expr, fn_decl, expected, found, id, parent_id,
2024+
&mut err,
2025+
expr,
2026+
fn_decl,
2027+
expected,
2028+
found,
2029+
block_or_return_id,
2030+
parent_id,
20242031
);
20252032
}
20262033

0 commit comments

Comments
 (0)