Skip to content

Improve error output of “Detect diff markers in the parser” #113826

Closed
@rben01

Description

@rben01

Copied from my comment in #106242:

I'd love this functionality but I'm not a huge fan of the error messages themselves.

error: encountered diff marker
  --> $DIR/enum-2.rs:3:1
   |
LL | <<<<<<< HEAD
   | ^^^^^^^ after this is the code before the merge
LL |         x: u8,
LL | |||||||
   | -------
LL |         z: (),
LL | =======
   | -------
LL |         y: i8,
LL | >>>>>>> branch
   | ^^^^^^^ 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 previous error

First, I believe these markers are called conflict markers, not diff markers. (IIUC diff markers are e.g., +++ file.rs.)

Second, I think the intermediate markers | and = should also be explained.

Third, I find the help: tips a bit verbose — especially considering that they'll likely line wrap in most terminals — and perhaps redundant given the content of the ^^^^^^^ notes. It might be better to stick the help: info in rustc --explain E#### instead of showing every time this error is encountered. Not sure where I stand on the note: tip; it's also a bit long, and its presence might lead people away from rustc --explain, which is probably undesirable. (The git documentation also has a lot of extraneous info that most users wouldn't need to solve this error; they just need to know which is old and which is new, <<<<<<< or >>>>>>>.)

Finally, I think the words “above” and “after” are a bit ambiguous; there's nearly an entire file above and below the outer conflict markers. (What's important is what's between conflict markers.) Furthermore they aren't quite accurate when there's a ||||||| section, since that section is below the <<<<<<< but not part of “our” code.

I think the following error message would be overall clearer and more accurate:

error: git conflict markers in source code
  --> $DIR/enum-2.rs:3:1
   |
LL | <<<<<<< HEAD
   | ^^^^^^^ between this marker and `|||||||` is the code that we're merging into
   |
LL | ||||||| 4fa0b83
   | ^^^^^^^ between this marker and `=======` is the base code (what the two refs diverged from)
   |
LL | =======
   | ^^^^^^^ between this marker and `>>>>>>>` is the incoming code
   |
LL | >>>>>>> branch
   | ^^^^^^^ this marker concludes the conflict region
   |
   = help: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
   = help: to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers

error: aborting due to previous error

or, if not using diff3,

error: git conflict markers in source code
  --> $DIR/enum-2.rs:3:1
   |
LL | <<<<<<< HEAD
   | ^^^^^^^ between this marker and `=======` is the code that we're merging into
   |
LL | =======
   | ^^^^^^^ between this marker and `>>>>>>>` is the incoming code
   |
LL | >>>>>>> branch
   | ^^^^^^^ this marker concludes the conflict region
   |
   = help: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
   = help: to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers

error: aborting due to previous error

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-papercutDiagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions