-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #92381 - ThePuzzlemaker:issue-92308, r=estebank
Suggest `return`ing tail expressions in async functions This PR fixes #92308. Previously, the suggestion to `return` tail expressions (introduced in #81769) did not apply to `async` functions, as the suggestion checked whether the types were equal disregarding `impl Future<Output = T>` syntax sugar for `async` functions. This PR changes that in order to fix a potential papercut. I'm not sure if this is the "right" way to do this, so if there is a better way then please let me know. I amended an existing test introduced in #81769 to add a regression test for this, if you think I should make a separate test I will.
- Loading branch information
Showing
3 changed files
with
54 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,32 @@ | ||
// > Suggest `return`ing tail expressions that match return type | ||
// > | ||
// > Some newcomers are confused by the behavior of tail expressions, | ||
// > interpreting that "leaving out the `;` makes it the return value". | ||
// > To help them go in the right direction, suggest using `return` instead | ||
// > when applicable. | ||
// (original commit description for this test) | ||
// | ||
// This test was amended to also serve as a regression test for #92308, where | ||
// this suggestion would not trigger with async functions. | ||
// | ||
// edition:2018 | ||
|
||
fn main() { | ||
let _ = foo(true); | ||
} | ||
|
||
fn foo(x: bool) -> Result<f64, i32> { | ||
if x { | ||
Err(42) //~ ERROR mismatched types | ||
//| HELP you might have meant to return this value | ||
} | ||
Ok(42.0) | ||
} | ||
|
||
async fn bar(x: bool) -> Result<f64, i32> { | ||
if x { | ||
Err(42) //~ ERROR mismatched types | ||
//| HELP you might have meant to return this value | ||
} | ||
Ok(42.0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters