Skip to content

Commit 5ba877c

Browse files
authored
Rollup merge of #129223 - wafarm:fix-129215, r=compiler-errors
Fix wrong argument for `get_fn_decl` Closes #129215 (seems to be introduced in #129168)
2 parents 5cb30b7 + da7dd43 commit 5ba877c

File tree

5 files changed

+49
-3
lines changed

5 files changed

+49
-3
lines changed

compiler/rustc_hir_typeck/src/coercion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1859,7 +1859,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
18591859
};
18601860

18611861
// If this is due to an explicit `return`, suggest adding a return type.
1862-
if let Some((fn_id, fn_decl, can_suggest)) = fcx.get_fn_decl(parent_id)
1862+
if let Some((fn_id, fn_decl, can_suggest)) = fcx.get_fn_decl(block_or_return_id)
18631863
&& !due_to_block
18641864
{
18651865
fcx.suggest_missing_return_type(&mut err, fn_decl, expected, found, can_suggest, fn_id);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//@ edition: 2021
2+
3+
async fn a() {
4+
//~^ ERROR `()` is not a future
5+
//~| ERROR mismatched types
6+
a() //~ ERROR `()` is not a future
7+
}
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
error[E0277]: `()` is not a future
2+
--> $DIR/recurse-ice-129215.rs:6:5
3+
|
4+
LL | a()
5+
| ^^^ `()` is not a future
6+
|
7+
= help: the trait `Future` is not implemented for `()`
8+
9+
error[E0277]: `()` is not a future
10+
--> $DIR/recurse-ice-129215.rs:3:1
11+
|
12+
LL | async fn a() {
13+
| ^^^^^^^^^^^^ `()` is not a future
14+
|
15+
= help: the trait `Future` is not implemented for `()`
16+
17+
error[E0308]: mismatched types
18+
--> $DIR/recurse-ice-129215.rs:3:14
19+
|
20+
LL | async fn a() {
21+
| ______________^
22+
LL | |
23+
LL | |
24+
LL | | a()
25+
LL | | }
26+
| |_^ expected `()`, found `async` fn body
27+
|
28+
= note: expected unit type `()`
29+
found `async` fn body `{async fn body of a()}`
30+
31+
error: aborting due to 3 previous errors
32+
33+
Some errors have detailed explanations: E0277, E0308.
34+
For more information about an error, try `rustc --explain E0277`.

tests/ui/closures/add_semicolon_non_block_closure.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ fn main() {
88
foo(|| bar())
99
//~^ ERROR mismatched types [E0308]
1010
//~| HELP consider using a semicolon here
11+
//~| HELP try adding a return type
1112
}

tests/ui/closures/add_semicolon_non_block_closure.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
error[E0308]: mismatched types
22
--> $DIR/add_semicolon_non_block_closure.rs:8:12
33
|
4-
LL | fn main() {
5-
| - expected `()` because of default return type
64
LL | foo(|| bar())
75
| ^^^^^ expected `()`, found `i32`
86
|
97
help: consider using a semicolon here
108
|
119
LL | foo(|| { bar(); })
1210
| + +++
11+
help: try adding a return type
12+
|
13+
LL | foo(|| -> i32 bar())
14+
| ++++++
1315

1416
error: aborting due to 1 previous error
1517

0 commit comments

Comments
 (0)