diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2023-03-01 23:40:19 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-01 23:40:19 +0530 |
| commit | 27fa7b5e6d2eaeba5daf6354df9de0d03cdf795c (patch) | |
| tree | 5ed9ee91dfd808cf79037ba5f994114eda7af339 /tests/rustdoc-js-std/parser-errors.js | |
| parent | 38461f8b8aa3979f5008005c049cd84c4e216ace (diff) | |
| parent | 0758c05c9792700dbc482eda8cd464c39d5ebed5 (diff) | |
| download | rust-27fa7b5e6d2eaeba5daf6354df9de0d03cdf795c.tar.gz rust-27fa7b5e6d2eaeba5daf6354df9de0d03cdf795c.zip | |
Rollup merge of #108427 - y21:for-else-diagnostic, r=compiler-errors
Recover from for-else and while-else
This recovers from attempts at writing for-else or while-else loops, which might help users coming from e.g. Python.
```rs
for _ in 0..0 {
// ...
} else {
// ...
}
```
Combined with trying to store it in a let binding, the current diagnostic can be a bit confusing. It mentions let-else and suggests wrapping the loop in parentheses, which the user probably doesn't want. let-else doesn't make sense for `for` and `while` loops, as they are of type `()` (which already is an irrefutable pattern and doesn't need let-else).
<details>
<summary>Current diagnostic</summary>
```rs
error: right curly brace `}` before `else` in a `let...else` statement not allowed
--> src/main.rs:4:5
|
4 | } else {
| ^
|
help: wrap the expression in parentheses
|
2 ~ let _x = (for _ in 0..0 {
3 |
4 ~ }) else {
|
```
</details>
Some questions:
- Can the wording for the error message be improved? Would "for...else loops are not allowed" fit better?
- Should we be more "conservative" in case we want to support this in the future (i.e. say "for...else loops are **currently** not allowed/supported")?
- Is there a better way than storing a `&'static str` for the loop type? It is used for substituting the placeholder in the locale file (since it can emit either `for...else` or `while...else`). Maybe there is an enum I could use that I couldn't find
Diffstat (limited to 'tests/rustdoc-js-std/parser-errors.js')
0 files changed, 0 insertions, 0 deletions
