Skip to content

Commit d2dabee

Browse files
Remove redundant blk_id parameter
1 parent 5915850 commit d2dabee

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
@@ -1599,22 +1599,20 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15991599
fcx,
16001600
blk_id,
16011601
expression,
1602-
Some(blk_id),
16031602
);
16041603
if !fcx.tcx.features().unsized_locals {
16051604
unsized_return = self.is_return_ty_definitely_unsized(fcx);
16061605
}
16071606
}
1608-
ObligationCauseCode::ReturnValue(id) => {
1607+
ObligationCauseCode::ReturnValue(return_expr_id) => {
16091608
err = self.report_return_mismatched_types(
16101609
cause,
16111610
expected,
16121611
found,
16131612
coercion_error,
16141613
fcx,
1615-
id,
1614+
return_expr_id,
16161615
expression,
1617-
None,
16181616
);
16191617
if !fcx.tcx.features().unsized_locals {
16201618
unsized_return = self.is_return_ty_definitely_unsized(fcx);
@@ -1808,13 +1806,14 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
18081806
found: Ty<'tcx>,
18091807
ty_err: TypeError<'tcx>,
18101808
fcx: &FnCtxt<'a, 'tcx>,
1811-
id: hir::HirId,
1809+
block_or_return_id: hir::HirId,
18121810
expression: Option<&'tcx hir::Expr<'tcx>>,
1813-
blk_id: Option<hir::HirId>,
18141811
) -> Diag<'a> {
18151812
let mut err = fcx.err_ctxt().report_mismatched_types(cause, expected, found, ty_err);
18161813

1817-
let parent_id = fcx.tcx.parent_hir_id(id);
1814+
let due_to_block = matches!(fcx.tcx.hir_node(block_or_return_id), hir::Node::Block(..));
1815+
1816+
let parent_id = fcx.tcx.parent_hir_id(block_or_return_id);
18181817
let parent = fcx.tcx.hir_node(parent_id);
18191818
if let Some(expr) = expression
18201819
&& let hir::Node::Expr(hir::Expr {
@@ -1829,11 +1828,16 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
18291828
// label pointing out the cause for the type coercion will be wrong
18301829
// as prior return coercions would not be relevant (#57664).
18311830
if let Some(expr) = expression
1832-
&& let Some(blk_id) = blk_id
1831+
&& due_to_block
18331832
{
18341833
fcx.suggest_missing_semicolon(&mut err, expr, expected, false);
1835-
let pointing_at_return_type =
1836-
fcx.suggest_mismatched_types_on_tail(&mut err, expr, expected, found, blk_id);
1834+
let pointing_at_return_type = fcx.suggest_mismatched_types_on_tail(
1835+
&mut err,
1836+
expr,
1837+
expected,
1838+
found,
1839+
block_or_return_id,
1840+
);
18371841
if let Some(cond_expr) = fcx.tcx.hir().get_if_cause(expr.hir_id)
18381842
&& expected.is_unit()
18391843
&& !pointing_at_return_type
@@ -1857,23 +1861,17 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
18571861
}
18581862
};
18591863

1860-
if let Some((fn_id, fn_decl, can_suggest)) = fcx.get_fn_decl(parent_id) {
1861-
if blk_id.is_none() {
1862-
fcx.suggest_missing_return_type(
1863-
&mut err,
1864-
fn_decl,
1865-
expected,
1866-
found,
1867-
can_suggest,
1868-
fn_id,
1869-
);
1870-
}
1864+
if let Some((fn_id, fn_decl, can_suggest)) = fcx.get_fn_decl(parent_id)
1865+
&& !due_to_block
1866+
{
1867+
fcx.suggest_missing_return_type(&mut err, fn_decl, expected, found, can_suggest, fn_id);
18711868
}
18721869

1873-
let mut parent_id = fcx.tcx.hir().get_parent_item(id).def_id;
1870+
let mut parent_id = fcx.tcx.hir().get_parent_item(block_or_return_id).def_id;
18741871
let mut parent_item = fcx.tcx.hir_node_by_def_id(parent_id);
18751872
// When suggesting return, we need to account for closures and async blocks, not just items.
1876-
for (_, node) in fcx.tcx.hir().parent_iter(id) {
1873+
// FIXME: fix get_fn_decl to be async block aware, use get_fn_decl results above
1874+
for (_, node) in fcx.tcx.hir().parent_iter(block_or_return_id) {
18771875
match node {
18781876
hir::Node::Expr(&hir::Expr {
18791877
kind: hir::ExprKind::Closure(hir::Closure { def_id, .. }),
@@ -1888,9 +1886,18 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
18881886
}
18891887
}
18901888

1891-
if let (Some(expr), Some(_), Some(fn_decl)) = (expression, blk_id, parent_item.fn_decl()) {
1889+
if let Some(expr) = expression
1890+
&& let Some(fn_decl) = parent_item.fn_decl()
1891+
&& due_to_block
1892+
{
18921893
fcx.suggest_missing_break_or_return_expr(
1893-
&mut err, expr, fn_decl, expected, found, id, parent_id,
1894+
&mut err,
1895+
expr,
1896+
fn_decl,
1897+
expected,
1898+
found,
1899+
block_or_return_id,
1900+
parent_id,
18941901
);
18951902
}
18961903

0 commit comments

Comments
 (0)