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

Make diff conflict marker error higher priority than unclosed delimeter #116252

Closed
joshka opened this issue Sep 28, 2023 · 6 comments · Fixed by #116712
Closed

Make diff conflict marker error higher priority than unclosed delimeter #116252

joshka opened this issue Sep 28, 2023 · 6 comments · Fixed by #116712
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST C-bug Category: This is a bug. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@joshka
Copy link
Contributor

joshka commented Sep 28, 2023

I tried this code:

mod tests {
    #[test]
<<<<<<< HEAD
    fn test1() {
=======
    fn test2() {
>>>>>>> 7a4f13c blah blah blah
    }
}

I expected to see this happen: explanation
error: encountered diff marker

Instead, this happened: explanation
error: this file contains an unclosed delimiter

Meta

rustc --version --verbose:

rustc 1.72.1 (d5c2e9c34 2023-09-13)
binary: rustc
commit-hash: d5c2e9c342b358556da91d61ed4133f6f50fc0c3
commit-date: 2023-09-13
host: aarch64-apple-darwin
release: 1.72.1
LLVM version: 16.0.5
@joshka joshka added the C-bug Category: This is a bug. label Sep 28, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 28, 2023
@Rageking8
Copy link
Contributor

@rustbot label +T-compiler +A-diagnostics

@rustbot rustbot added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 29, 2023
@fmease
Copy link
Member

fmease commented Sep 29, 2023

Right, this is happens because the unclosed delimiter error is emitted in the lexer (rustc_parse::lexer not rustc_lexer) before the parser (which is responsible for detecting diff markers) gets the chance to parse anything.

@fmease fmease added A-parser Area: The parsing of Rust source code to an AST D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Sep 29, 2023
@joshka
Copy link
Contributor Author

joshka commented Sep 30, 2023

Right, this is happens because the unclosed delimiter error is emitted in the lexer (rustc_parse::lexer not rustc_lexer) before the parser (which is responsible for detecting diff markers) gets the chance to parse anything.

Reading between the line that sounds like it fits in the difficult to implement with only a small amount of value basket. Does this sound right?

@workingjubilee
Copy link
Member

correct, you would have to be able to traverse the previous diagnostic errors already to-be-emitted and then swallow the previous one, I think. I don't know if our diagnostic architecture even allows that?

@estebank
Copy link
Contributor

estebank commented Oct 4, 2023

We have done similar things by storing some related unemitted DiagnosticBuilders and ferry them around from one stage to the next and only emit them try to find them later through some key (like a Span) and if present we remove it/delay_as_bug, but this is very ad-hoc at the moment.

@workingjubilee workingjubilee added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. and removed E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. labels Oct 5, 2023
@fmease
Copy link
Member

fmease commented Oct 6, 2023

So this regressed in #108297 which made unclosed delimiters a hard error. Before, the diff conflict marker error was emitted just fine:

stderr
error: this file contains an unclosed delimiter
 --> diff_marker.rs:9:3
  |
1 | mod tests {
  |           - unclosed delimiter
...
4 |     fn test1() {
  |                - this delimiter might not be properly closed...
...
9 | }
  | - ^
  | |
  | ...as it matches this but it has different indentation

error: encountered diff marker
 --> diff_marker.rs:3:1
  |
3 | <<<<<<< HEAD
  | ^^^^^^^ after this is the code before the merge
4 |     fn test1() {
5 | =======
  | -------
6 |     fn test2() {
7 | >>>>>>> 7a4f13c blah blah blah
  | ^^^^^^^ above this are the incoming code changes
  |
  = help: if you're having merge conflicts after pulling new code, the top section is the code you already had and the bottom section is the remote code
  = help: if you're in the middle of a rebase, the top section is the code being rebased onto and the bottom section is the code coming from the current commit being rebased
  = note: for an explanation on these markers from the `git` documentation, visit <https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts>

error: aborting due to 2 previous errors

Without being an expert in this field, this should in theory be fixable by moving the conflict marker detection to the tokentree parser in rustc_parse::lexer, right? This would also greatly simplify the rust parser which at the moment is sprinkled with checks at specific places only. I might not see the full picture though. I faintly remember something similar being discussed when estebank implemented the current approach. To me that sounds better than using stashed diagnostics for this (which would need to be stashed in the tokentree parser anyway?).

estebank added a commit to estebank/rust that referenced this issue Oct 13, 2023
@estebank estebank self-assigned this Oct 13, 2023
estebank added a commit to estebank/rust that referenced this issue Oct 27, 2023
estebank added a commit to estebank/rust that referenced this issue Oct 27, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 31, 2023
When encountering unclosed delimiters during lexing, check for diff markers

Fix rust-lang#116252.
@bors bors closed this as completed in 50ca5ef Oct 31, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 31, 2023
Rollup merge of rust-lang#116712 - estebank:issue-116252, r=petrochenkov

When encountering unclosed delimiters during lexing, check for diff markers

Fix rust-lang#116252.
kjetilkjeka pushed a commit to kjetilkjeka/rust that referenced this issue Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST C-bug Category: This is a bug. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants