Skip to content

Commit

Permalink
Rollup merge of rust-lang#129223 - wafarm:fix-129215, r=compiler-errors
Browse files Browse the repository at this point in the history
 Fix wrong argument for `get_fn_decl`

Closes rust-lang#129215 (seems to be introduced in rust-lang#129168)
  • Loading branch information
matthiaskrgr authored Aug 19, 2024
2 parents 5cb30b7 + da7dd43 commit 5ba877c
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 5ba877c

Please sign in to comment.