Skip to content

Commit

Permalink
Fix wrong argument for get_fn_decl
Browse files Browse the repository at this point in the history
  • Loading branch information
wafarm committed Aug 19, 2024
1 parent d0293c6 commit da7dd43
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1859,7 +1859,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
};

// If this is due to an explicit `return`, suggest adding a return type.
if let Some((fn_id, fn_decl, can_suggest)) = fcx.get_fn_decl(parent_id)
if let Some((fn_id, fn_decl, can_suggest)) = fcx.get_fn_decl(block_or_return_id)
&& !due_to_block
{
fcx.suggest_missing_return_type(&mut err, fn_decl, expected, found, can_suggest, fn_id);
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/async-await/async-fn/recurse-ice-129215.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//@ edition: 2021

async fn a() {
//~^ ERROR `()` is not a future
//~| ERROR mismatched types
a() //~ ERROR `()` is not a future
}

fn main() {}
34 changes: 34 additions & 0 deletions tests/ui/async-await/async-fn/recurse-ice-129215.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
error[E0277]: `()` is not a future
--> $DIR/recurse-ice-129215.rs:6:5
|
LL | a()
| ^^^ `()` is not a future
|
= help: the trait `Future` is not implemented for `()`

error[E0277]: `()` is not a future
--> $DIR/recurse-ice-129215.rs:3:1
|
LL | async fn a() {
| ^^^^^^^^^^^^ `()` is not a future
|
= help: the trait `Future` is not implemented for `()`

error[E0308]: mismatched types
--> $DIR/recurse-ice-129215.rs:3:14
|
LL | async fn a() {
| ______________^
LL | |
LL | |
LL | | a()
LL | | }
| |_^ expected `()`, found `async` fn body
|
= note: expected unit type `()`
found `async` fn body `{async fn body of a()}`

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
1 change: 1 addition & 0 deletions tests/ui/closures/add_semicolon_non_block_closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ fn main() {
foo(|| bar())
//~^ ERROR mismatched types [E0308]
//~| HELP consider using a semicolon here
//~| HELP try adding a return type
}
6 changes: 4 additions & 2 deletions tests/ui/closures/add_semicolon_non_block_closure.stderr
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
error[E0308]: mismatched types
--> $DIR/add_semicolon_non_block_closure.rs:8:12
|
LL | fn main() {
| - expected `()` because of default return type
LL | foo(|| bar())
| ^^^^^ expected `()`, found `i32`
|
help: consider using a semicolon here
|
LL | foo(|| { bar(); })
| + +++
help: try adding a return type
|
LL | foo(|| -> i32 bar())
| ++++++

error: aborting due to 1 previous error

Expand Down

0 comments on commit da7dd43

Please sign in to comment.