Skip to content

Commit 3b718cb

Browse files
Remove redundant blk_id parameter
1 parent abaf4db commit 3b718cb

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

compiler/rustc_hir_typeck/src/coercion.rs

+32-25
Original file line numberDiff line numberDiff line change
@@ -1630,7 +1630,6 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
16301630
fcx,
16311631
blk_id,
16321632
expression,
1633-
Some(blk_id),
16341633
);
16351634
if !fcx.tcx.features().unsized_locals {
16361635
unsized_return = self.is_return_ty_definitely_unsized(fcx);
@@ -1641,16 +1640,15 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
16411640
intravisit::walk_block(&mut visitor, loop_blk);
16421641
}
16431642
}
1644-
ObligationCauseCode::ReturnValue(id) => {
1643+
ObligationCauseCode::ReturnValue(return_expr_id) => {
16451644
err = self.report_return_mismatched_types(
16461645
cause,
16471646
expected,
16481647
found,
16491648
coercion_error,
16501649
fcx,
1651-
id,
1650+
return_expr_id,
16521651
expression,
1653-
None,
16541652
);
16551653
if !fcx.tcx.features().unsized_locals {
16561654
unsized_return = self.is_return_ty_definitely_unsized(fcx);
@@ -1941,13 +1939,14 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
19411939
found: Ty<'tcx>,
19421940
ty_err: TypeError<'tcx>,
19431941
fcx: &FnCtxt<'a, 'tcx>,
1944-
id: hir::HirId,
1942+
block_or_return_id: hir::HirId,
19451943
expression: Option<&'tcx hir::Expr<'tcx>>,
1946-
blk_id: Option<hir::HirId>,
19471944
) -> Diag<'a> {
19481945
let mut err = fcx.err_ctxt().report_mismatched_types(cause, expected, found, ty_err);
19491946

1950-
let parent_id = fcx.tcx.parent_hir_id(id);
1947+
let due_to_block = matches!(fcx.tcx.hir_node(block_or_return_id), hir::Node::Block(..));
1948+
1949+
let parent_id = fcx.tcx.parent_hir_id(block_or_return_id);
19511950
let parent = fcx.tcx.hir_node(parent_id);
19521951
if let Some(expr) = expression
19531952
&& let hir::Node::Expr(hir::Expr {
@@ -1962,11 +1961,16 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
19621961
// label pointing out the cause for the type coercion will be wrong
19631962
// as prior return coercions would not be relevant (#57664).
19641963
if let Some(expr) = expression
1965-
&& let Some(blk_id) = blk_id
1964+
&& due_to_block
19661965
{
19671966
fcx.suggest_missing_semicolon(&mut err, expr, expected, false);
1968-
let pointing_at_return_type =
1969-
fcx.suggest_mismatched_types_on_tail(&mut err, expr, expected, found, blk_id);
1967+
let pointing_at_return_type = fcx.suggest_mismatched_types_on_tail(
1968+
&mut err,
1969+
expr,
1970+
expected,
1971+
found,
1972+
block_or_return_id,
1973+
);
19701974
if let Some(cond_expr) = fcx.tcx.hir().get_if_cause(expr.hir_id)
19711975
&& expected.is_unit()
19721976
&& !pointing_at_return_type
@@ -1990,23 +1994,17 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
19901994
}
19911995
};
19921996

1993-
if let Some((fn_id, fn_decl, can_suggest)) = fcx.get_fn_decl(parent_id) {
1994-
if blk_id.is_none() {
1995-
fcx.suggest_missing_return_type(
1996-
&mut err,
1997-
fn_decl,
1998-
expected,
1999-
found,
2000-
can_suggest,
2001-
fn_id,
2002-
);
2003-
}
1997+
if let Some((fn_id, fn_decl, can_suggest)) = fcx.get_fn_decl(parent_id)
1998+
&& !due_to_block
1999+
{
2000+
fcx.suggest_missing_return_type(&mut err, fn_decl, expected, found, can_suggest, fn_id);
20042001
}
20052002

2006-
let mut parent_id = fcx.tcx.hir().get_parent_item(id).def_id;
2003+
let mut parent_id = fcx.tcx.hir().get_parent_item(block_or_return_id).def_id;
20072004
let mut parent_item = fcx.tcx.hir_node_by_def_id(parent_id);
20082005
// When suggesting return, we need to account for closures and async blocks, not just items.
2009-
for (_, node) in fcx.tcx.hir().parent_iter(id) {
2006+
// FIXME: fix get_fn_decl to be async block aware, use get_fn_decl results above
2007+
for (_, node) in fcx.tcx.hir().parent_iter(block_or_return_id) {
20102008
match node {
20112009
hir::Node::Expr(&hir::Expr {
20122010
kind: hir::ExprKind::Closure(hir::Closure { def_id, .. }),
@@ -2021,9 +2019,18 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
20212019
}
20222020
}
20232021

2024-
if let (Some(expr), Some(_), Some(fn_decl)) = (expression, blk_id, parent_item.fn_decl()) {
2022+
if let Some(expr) = expression
2023+
&& let Some(fn_decl) = parent_item.fn_decl()
2024+
&& due_to_block
2025+
{
20252026
fcx.suggest_missing_break_or_return_expr(
2026-
&mut err, expr, fn_decl, expected, found, id, parent_id,
2027+
&mut err,
2028+
expr,
2029+
fn_decl,
2030+
expected,
2031+
found,
2032+
block_or_return_id,
2033+
parent_id,
20272034
);
20282035
}
20292036

0 commit comments

Comments
 (0)