Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Error Messages for break Inside Coroutines #124777

Merged

Conversation

veera-sivarajan
Copy link
Contributor

@veera-sivarajan veera-sivarajan commented May 5, 2024

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.

@rustbot
Copy link
Collaborator

rustbot commented May 5, 2024

r? @compiler-errors

rustbot has assigned @compiler-errors.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 5, 2024
compiler/rustc_passes/messages.ftl Outdated Show resolved Hide resolved
compiler/rustc_passes/messages.ftl Outdated Show resolved Hide resolved
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 5, 2024
@veera-sivarajan veera-sivarajan force-pushed the bugfix-124495-identify-gen-block branch from 5f66961 to 9d2685e Compare May 6, 2024 20:47
@veera-sivarajan
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 6, 2024
coroutine_span,
kind: hir::CoroutineDesugaring::Async,
source: hir::CoroutineSource::Block,
} => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make this into a single match statement and do:

let source = match source {
  ...
};
let kind = match kind {
  ...
};

I also wonder if we should just get rid of the article "a"/"an" from the error message so that we don't need to put that into the fluent file... Seems kind of annoying to have to put that in there -- it's definitely not very translatable. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, same. The of followed by the article makes it wordy.

Can I remove both of and the article to make it like cannot `break` inside `async` function in all places? It's concise and flows well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that's fine, yes

@compiler-errors
Copy link
Member

@rustbot author

r=me after changing the diagnostic one last time, thanks for dealing with the back-and-forth

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 7, 2024
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`.
@veera-sivarajan veera-sivarajan force-pushed the bugfix-124495-identify-gen-block branch from 9d2685e to 21ccec0 Compare May 8, 2024 21:33
@compiler-errors
Copy link
Member

Thanks @bors r+ rollup

@bors
Copy link
Contributor

bors commented May 8, 2024

📌 Commit 21ccec0 has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 8, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request May 9, 2024
…iaskrgr

Rollup of 4 pull requests

Successful merges:

 - rust-lang#124777 (Fix Error Messages for `break` Inside Coroutines)
 - rust-lang#124837 (Migrate `run-make/rustdoc-map-file` to rmake)
 - rust-lang#124875 (Fix more ICEs in `diagnostic::on_unimplemented`)
 - rust-lang#124908 (Handle field projections like slice indexing in invalid_reference_casting)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 9b834d0 into rust-lang:master May 9, 2024
6 checks passed
@rustbot rustbot added this to the 1.80.0 milestone May 9, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 9, 2024
Rollup merge of rust-lang#124777 - veera-sivarajan:bugfix-124495-identify-gen-block, r=compiler-errors

Fix Error Messages for `break` Inside Coroutines

Fixes rust-lang#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`.~~
@veera-sivarajan veera-sivarajan deleted the bugfix-124495-identify-gen-block branch May 9, 2024 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

break inside gen blocks misidentifies gen block as a closure
4 participants