forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
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 rust-lang#120696 - estebank:issue-115405, r=oli-obk
Properly handle `async` block and `async fn` in `if` exprs without `else` When encountering a tail expression in the then arm of an `if` expression without an `else` arm, account for `async fn` and `async` blocks to suggest `return`ing the value and pointing at the return type of the `async fn`. We now also account for AFIT when looking for the return type to point at. Fix rust-lang#115405.
- Loading branch information
Showing
12 changed files
with
215 additions
and
47 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
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
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
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// run-rustfix | ||
// edition:2021 | ||
use std::future::Future; | ||
use std::pin::Pin; | ||
pub struct S; | ||
pub fn foo() { | ||
let _ = Box::pin(async move { | ||
if true { | ||
return Ok(S); //~ ERROR mismatched types | ||
} | ||
Err(()) | ||
}); | ||
} | ||
pub fn bar() -> Pin<Box<dyn Future<Output = Result<S, ()>> + 'static>> { | ||
Box::pin(async move { | ||
if true { | ||
return Ok(S); //~ ERROR mismatched types | ||
} | ||
Err(()) | ||
}) | ||
} | ||
fn main() {} |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// run-rustfix | ||
// edition:2021 | ||
use std::future::Future; | ||
use std::pin::Pin; | ||
pub struct S; | ||
pub fn foo() { | ||
let _ = Box::pin(async move { | ||
if true { | ||
Ok(S) //~ ERROR mismatched types | ||
} | ||
Err(()) | ||
}); | ||
} | ||
pub fn bar() -> Pin<Box<dyn Future<Output = Result<S, ()>> + 'static>> { | ||
Box::pin(async move { | ||
if true { | ||
Ok(S) //~ ERROR mismatched types | ||
} | ||
Err(()) | ||
}) | ||
} | ||
fn main() {} |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/missing-return-in-async-block.rs:9:13 | ||
| | ||
LL | / if true { | ||
LL | | Ok(S) | ||
| | ^^^^^ expected `()`, found `Result<S, _>` | ||
LL | | } | ||
| |_________- expected this to be `()` | ||
| | ||
= note: expected unit type `()` | ||
found enum `Result<S, _>` | ||
help: you might have meant to return this value | ||
| | ||
LL | return Ok(S); | ||
| ++++++ + | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/missing-return-in-async-block.rs:17:13 | ||
| | ||
LL | / if true { | ||
LL | | Ok(S) | ||
| | ^^^^^ expected `()`, found `Result<S, _>` | ||
LL | | } | ||
| |_________- expected this to be `()` | ||
| | ||
= note: expected unit type `()` | ||
found enum `Result<S, _>` | ||
help: you might have meant to return this value | ||
| | ||
LL | return Ok(S); | ||
| ++++++ + | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
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
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