diff options
| author | bors <bors@rust-lang.org> | 2022-06-15 02:58:44 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-06-15 02:58:44 +0000 |
| commit | ddb6cc85243ac4761fbc32a407b10216544fe57b (patch) | |
| tree | 6c0ca223e784365531787dc5bd13a92795aeb7fb /compiler/rustc_builtin_macros/src/assert/context.rs | |
| parent | 2d1e0750792529248ed6f11061940c7203d668c9 (diff) | |
| parent | d1ba2d25d483a65f41ca6277c160e2ea6d813e3b (diff) | |
| download | rust-ddb6cc85243ac4761fbc32a407b10216544fe57b.tar.gz rust-ddb6cc85243ac4761fbc32a407b10216544fe57b.zip | |
Auto merge of #97474 - compiler-errors:if-cond-and-block, r=oli-obk
Improve parsing errors and suggestions for bad `if` statements
1. Parses `if {}` as `if <err> {}` (block-like conditions that are missing a "then" block), and `if true && {}` as `if true && <err> {}` (unfinished binary operation), which is a more faithful recovery and leads to better typeck errors later on.
1. Points out the span of the condition if we don't see a "then" block after it, to help the user understand what is being parsed as a condition (and by elimination, what isn't).
1. Allow `if cond token else { }` to be fixed properly to `if cond { token } else { }`.
1. Fudge with the error messages a bit. This is somewhat arbitrary and I can revert my rewordings if they're useless.
----
Also this PR addresses a strange parsing regression (1.20 -> 1.21) where we chose to reject this piece of code somewhat arbitrarily, even though we should parse it fine:
```rust
fn main() {
if { if true { return } else { return }; } {}
}
```
For context, all of these other expressions parse correctly:
```rust
fn main() {
if { if true { return } else { return } } {}
if { return; } {}
if { return } {}
if { return if true { } else { }; } {}
}
```
The parser used a heuristic to determine if the "the parsed `if` condition makes sense as a condition" that did like a one-expr-deep reachability analysis. This should not be handled by the parser though.
Diffstat (limited to 'compiler/rustc_builtin_macros/src/assert/context.rs')
0 files changed, 0 insertions, 0 deletions
