diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-04-23 20:17:51 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-23 20:17:51 +0200 |
| commit | afb6c4681ab1701e03e03669ec41e8e7c8a495c2 (patch) | |
| tree | 46fee95d33387224dbe3cebcd0f8e69ea2331a9a /tests/ui/impl-trait/precise-capturing | |
| parent | 918304b190dea160fd2737cc1b840046064b303c (diff) | |
| parent | 2ef15523c15758ae00aa192de7077fd36fa61315 (diff) | |
| download | rust-afb6c4681ab1701e03e03669ec41e8e7c8a495c2.tar.gz rust-afb6c4681ab1701e03e03669ec41e8e7c8a495c2.zip | |
Rollup merge of #124169 - compiler-errors:parser-fatal, r=oli-obk
Don't fatal when calling `expect_one_of` when recovering arg in `parse_seq` In `parse_seq`, when parsing a sequence of token-separated items, if we don't see a separator, we try to parse another item eagerly in order to give a good diagnostic and recover from a missing separator: https://github.com/rust-lang/rust/blob/d1a0fa5ed3ffe52d72f761d3c95cbeb0a9cdfe66/compiler/rustc_parse/src/parser/mod.rs#L900-L901 If parsing the item itself calls `expect_one_of`, then we will fatal because of #58903: https://github.com/rust-lang/rust/blob/d1a0fa5ed3ffe52d72f761d3c95cbeb0a9cdfe66/compiler/rustc_parse/src/parser/mod.rs#L513-L516 For `precise_capturing` feature I implemented, we do end up calling `expected_one_of`: https://github.com/rust-lang/rust/blob/d1a0fa5ed3ffe52d72f761d3c95cbeb0a9cdfe66/compiler/rustc_parse/src/parser/ty.rs#L712-L714 This leads the compiler to fatal *before* having emitted the first error, leading to absolutely no useful information for the user about what happened in the parser. This PR makes it so that we stop doing that. Fixes #124195
Diffstat (limited to 'tests/ui/impl-trait/precise-capturing')
| -rw-r--r-- | tests/ui/impl-trait/precise-capturing/unexpected-token.rs | 9 | ||||
| -rw-r--r-- | tests/ui/impl-trait/precise-capturing/unexpected-token.stderr | 16 |
2 files changed, 25 insertions, 0 deletions
diff --git a/tests/ui/impl-trait/precise-capturing/unexpected-token.rs b/tests/ui/impl-trait/precise-capturing/unexpected-token.rs new file mode 100644 index 00000000000..39c8c0def6b --- /dev/null +++ b/tests/ui/impl-trait/precise-capturing/unexpected-token.rs @@ -0,0 +1,9 @@ +// We used to fatal error without any useful diagnostic when we had an unexpected +// token due to a strange interaction between the sequence parsing code and the +// param/lifetime parsing code. + +fn hello() -> impl use<'a {}> Sized {} +//~^ ERROR expected one of `,` or `>`, found `{` +//~| ERROR expected item, found `>` + +fn main() {} diff --git a/tests/ui/impl-trait/precise-capturing/unexpected-token.stderr b/tests/ui/impl-trait/precise-capturing/unexpected-token.stderr new file mode 100644 index 00000000000..989c479b248 --- /dev/null +++ b/tests/ui/impl-trait/precise-capturing/unexpected-token.stderr @@ -0,0 +1,16 @@ +error: expected one of `,` or `>`, found `{` + --> $DIR/unexpected-token.rs:5:27 + | +LL | fn hello() -> impl use<'a {}> Sized {} + | ^ expected one of `,` or `>` + +error: expected item, found `>` + --> $DIR/unexpected-token.rs:5:29 + | +LL | fn hello() -> impl use<'a {}> Sized {} + | ^ expected item + | + = note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html> + +error: aborting due to 2 previous errors + |
