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#63796 - estebank:opaque_future, r=Centril
Tweak E0308 on opaque types ``` error[E0308]: if and else have incompatible types --> file.rs:21:9 | 18 | / if true { 19 | | thing_one() | | ----------- expected because of this 20 | | } else { 21 | | thing_two() | | ^^^^^^^^^^^ expected opaque type, found a different opaque type 22 | | }.await | |_____- if and else have incompatible types | = note: expected type `impl std::future::Future` (opaque type) found type `impl std::future::Future` (opaque type) = note: distinct uses of `impl Trait` result in different opaque types = help: if both futures resolve to the same type, consider `await`ing on both of them ``` r? @Centril CC rust-lang#63167
- Loading branch information
Showing
4 changed files
with
62 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// edition:2018 | ||
use core::future::Future; | ||
|
||
async fn base_thing() -> Result<(), ()> { | ||
Ok(()) | ||
} | ||
|
||
fn thing_one() -> impl Future<Output = Result<(), ()>> { | ||
base_thing() | ||
} | ||
|
||
fn thing_two() -> impl Future<Output = Result<(), ()>> { | ||
base_thing() | ||
} | ||
|
||
async fn thing() -> Result<(), ()> { | ||
if true { | ||
thing_one() | ||
} else { | ||
thing_two() //~ ERROR if and else have incompatible types | ||
}.await | ||
} | ||
|
||
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,20 @@ | ||
error[E0308]: if and else have incompatible types | ||
--> $DIR/opaque-type-error.rs:20:9 | ||
| | ||
LL | / if true { | ||
LL | | thing_one() | ||
| | ----------- expected because of this | ||
LL | | } else { | ||
LL | | thing_two() | ||
| | ^^^^^^^^^^^ expected opaque type, found a different opaque type | ||
LL | | }.await | ||
| |_____- if and else have incompatible types | ||
| | ||
= note: expected type `impl std::future::Future` (opaque type) | ||
found type `impl std::future::Future` (opaque type) | ||
= note: distinct uses of `impl Trait` result in different opaque types | ||
= help: if both `Future`s have the same `Output` type, consider `.await`ing on both of them | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |