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

Don't fatal when calling expect_one_of when recovering arg in parse_seq #124169

Merged
merged 1 commit into from
Apr 23, 2024

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Apr 19, 2024

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:

// Attempt to keep parsing if it was an omitted separator.
match f(self) {

If parsing the item itself calls expect_one_of, then we will fatal because of #58903:

} else if self.token.kind != token::Eof
&& self.last_unexpected_token_span == Some(self.token.span)
{
FatalError.raise();

For precise_capturing feature I implemented, we do end up calling expected_one_of:

} else {
self_.unexpected_any()
}

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

@rustbot
Copy link
Collaborator

rustbot commented Apr 19, 2024

r? @lcnr

rustbot has assigned @lcnr.
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 Apr 19, 2024
@compiler-errors
Copy link
Member Author

r? @fmease or @oli-obk :D

@rustbot rustbot assigned fmease and unassigned lcnr Apr 23, 2024
@oli-obk
Copy link
Contributor

oli-obk commented Apr 23, 2024

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Apr 23, 2024

📌 Commit 2ef1552 has been approved by oli-obk

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-review Status: Awaiting review from the assignee but also interested parties. labels Apr 23, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 23, 2024
…i-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 rust-lang#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 rust-lang#124195
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 23, 2024
…iaskrgr

Rollup of 3 pull requests

Successful merges:

 - rust-lang#124003 (Dellvmize some intrinsics (use `u32` instead of `Self` in some integer intrinsics))
 - rust-lang#124169 (Don't fatal when calling `expect_one_of` when recovering arg in `parse_seq`)
 - rust-lang#124286 (Subtree sync for rustc_codegen_cranelift)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit afb6c46 into rust-lang:master Apr 23, 2024
12 checks passed
@rustbot rustbot added this to the 1.79.0 milestone Apr 23, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 23, 2024
Rollup merge of rust-lang#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 rust-lang#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 rust-lang#124195
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.

missing diagnostic
6 participants