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#130820 - 91khr:fix-coroutine-unit-arg, r=co…
…mpiler-errors Fix diagnostics for coroutines with () as input. This may be a more real-life example to trigger the diagnostic: ```rust #![features(try_blocks, coroutine_trait, coroutines)] use std::ops::Coroutine; struct Request; struct Response; fn get_args() -> Result<String, String> { todo!() } fn build_request(_arg: String) -> Request { todo!() } fn work() -> impl Coroutine<Option<Response>, Yield = Request> { #[coroutine] |_| { let r: Result<(), String> = try { let req = get_args()?; yield build_request(req) }; if let Err(msg) = r { eprintln!("Error: {msg}"); } } } ```
- Loading branch information
Showing
3 changed files
with
61 additions
and
37 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#![feature(coroutines, coroutine_trait, stmt_expr_attributes)] | ||
|
||
use std::ops::Coroutine; | ||
|
||
fn foo() -> impl Coroutine<u8> { | ||
//~^ ERROR type mismatch in coroutine arguments | ||
#[coroutine] | ||
|_: ()| {} | ||
} | ||
|
||
fn main() { } |
15 changes: 15 additions & 0 deletions
15
tests/ui/coroutine/arg-count-mismatch-on-unit-input.stderr
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,15 @@ | ||
error[E0631]: type mismatch in coroutine arguments | ||
--> $DIR/arg-count-mismatch-on-unit-input.rs:5:13 | ||
| | ||
LL | fn foo() -> impl Coroutine<u8> { | ||
| ^^^^^^^^^^^^^^^^^^ expected due to this | ||
... | ||
LL | |_: ()| {} | ||
| ------- found signature defined here | ||
| | ||
= note: expected coroutine signature `fn(u8) -> _` | ||
found coroutine signature `fn(()) -> _` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0631`. |