diff options
| author | Jamie <jamie@osec.io> | 2025-05-14 13:32:41 +0100 |
|---|---|---|
| committer | clubby789 <jamie@hill-daniel.co.uk> | 2025-05-14 13:32:59 +0100 |
| commit | 1267333ef102d854cf0cefef877ba0d9adb07107 (patch) | |
| tree | 5572e8ade5d0a54cfbd5ee9a7bbccf06033e921a /compiler/rustc_parse/src/parser/stmt.rs | |
| parent | bc7512ee6309ee7e8cacf87b94aa6d1f550c9d99 (diff) | |
| download | rust-1267333ef102d854cf0cefef877ba0d9adb07107.tar.gz rust-1267333ef102d854cf0cefef877ba0d9adb07107.zip | |
Improve ternary operator recovery
Diffstat (limited to 'compiler/rustc_parse/src/parser/stmt.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/stmt.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 885a65d4de7..396ded96bde 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -879,7 +879,12 @@ impl<'a> Parser<'a> { { // Just check for errors and recover; do not eat semicolon yet. - let expect_result = self.expect_one_of(&[], &[exp!(Semi), exp!(CloseBrace)]); + let expect_result = + if let Err(e) = self.maybe_recover_from_ternary_operator(Some(expr.span)) { + Err(e) + } else { + self.expect_one_of(&[], &[exp!(Semi), exp!(CloseBrace)]) + }; // Try to both emit a better diagnostic, and avoid further errors by replacing // the `expr` with `ExprKind::Err`. |
