-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 #124777 - veera-sivarajan:bugfix-124495-identify-gen-…
…block, r=compiler-errors Fix Error Messages for `break` Inside Coroutines Fixes #124495 Previously, `break` inside `gen` blocks and functions were incorrectly identified to be enclosed by a closure. This PR fixes it by displaying an appropriate error message for async blocks, async closures, async functions, gen blocks, gen closures, gen functions, async gen blocks, async gen closures and async gen functions. Note: gen closure and async gen closure are not supported by the compiler yet but I have added an error message here assuming that they might be implemented in the future. ~~Also, fixes grammar in a few places by replacing `inside of a $coroutine` with `inside a $coroutine`.~~
- Loading branch information
Showing
7 changed files
with
135 additions
and
24 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
8 changes: 4 additions & 4 deletions
8
tests/ui/async-await/async-block-control-flow-static-semantics.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
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,26 @@ | ||
//@ edition: 2024 | ||
//@ compile-flags: -Z unstable-options | ||
|
||
#![feature(gen_blocks)] | ||
#![feature(async_closure)] | ||
|
||
async fn async_fn() { | ||
break; //~ ERROR `break` inside `async` function | ||
} | ||
|
||
gen fn gen_fn() { | ||
break; //~ ERROR `break` inside `gen` function | ||
} | ||
|
||
async gen fn async_gen_fn() { | ||
break; //~ ERROR `break` inside `async gen` function | ||
} | ||
|
||
fn main() { | ||
let _ = async { break; }; //~ ERROR `break` inside `async` block | ||
let _ = async || { break; }; //~ ERROR `break` inside `async` closure | ||
|
||
let _ = gen { break; }; //~ ERROR `break` inside `gen` block | ||
|
||
let _ = async gen { break; }; //~ ERROR `break` inside `async gen` block | ||
} |
69 changes: 69 additions & 0 deletions
69
tests/ui/coroutine/break-inside-coroutine-issue-124495.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,69 @@ | ||
error[E0267]: `break` inside `async` function | ||
--> $DIR/break-inside-coroutine-issue-124495.rs:8:5 | ||
| | ||
LL | async fn async_fn() { | ||
| _____________________- | ||
LL | | break; | ||
| | ^^^^^ cannot `break` inside `async` function | ||
LL | | } | ||
| |_- enclosing `async` function | ||
|
||
error[E0267]: `break` inside `gen` function | ||
--> $DIR/break-inside-coroutine-issue-124495.rs:12:5 | ||
| | ||
LL | gen fn gen_fn() { | ||
| _________________- | ||
LL | | break; | ||
| | ^^^^^ cannot `break` inside `gen` function | ||
LL | | } | ||
| |_- enclosing `gen` function | ||
|
||
error[E0267]: `break` inside `async gen` function | ||
--> $DIR/break-inside-coroutine-issue-124495.rs:16:5 | ||
| | ||
LL | async gen fn async_gen_fn() { | ||
| _____________________________- | ||
LL | | break; | ||
| | ^^^^^ cannot `break` inside `async gen` function | ||
LL | | } | ||
| |_- enclosing `async gen` function | ||
|
||
error[E0267]: `break` inside `async` block | ||
--> $DIR/break-inside-coroutine-issue-124495.rs:20:21 | ||
| | ||
LL | let _ = async { break; }; | ||
| --------^^^^^--- | ||
| | | | ||
| | cannot `break` inside `async` block | ||
| enclosing `async` block | ||
|
||
error[E0267]: `break` inside `async` closure | ||
--> $DIR/break-inside-coroutine-issue-124495.rs:21:24 | ||
| | ||
LL | let _ = async || { break; }; | ||
| --^^^^^--- | ||
| | | | ||
| | cannot `break` inside `async` closure | ||
| enclosing `async` closure | ||
|
||
error[E0267]: `break` inside `gen` block | ||
--> $DIR/break-inside-coroutine-issue-124495.rs:23:19 | ||
| | ||
LL | let _ = gen { break; }; | ||
| ------^^^^^--- | ||
| | | | ||
| | cannot `break` inside `gen` block | ||
| enclosing `gen` block | ||
|
||
error[E0267]: `break` inside `async gen` block | ||
--> $DIR/break-inside-coroutine-issue-124495.rs:25:25 | ||
| | ||
LL | let _ = async gen { break; }; | ||
| ------------^^^^^--- | ||
| | | | ||
| | cannot `break` inside `async gen` block | ||
| enclosing `async gen` block | ||
|
||
error: aborting due to 7 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0267`. |