-
Couldn't load subscription status.
- Fork 13.9k
Improve error output when encountering git conflict markers #115413
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2705,13 +2705,13 @@ impl<'a> Parser<'a> { | |
| Ok(()) | ||
| } | ||
|
|
||
| pub fn is_diff_marker(&mut self, long_kind: &TokenKind, short_kind: &TokenKind) -> bool { | ||
| pub fn is_conflict_marker(&mut self, long_kind: &TokenKind, short_kind: &TokenKind) -> bool { | ||
| (0..3).all(|i| self.look_ahead(i, |tok| tok == long_kind)) | ||
| && self.look_ahead(3, |tok| tok == short_kind) | ||
| } | ||
|
|
||
| fn diff_marker(&mut self, long_kind: &TokenKind, short_kind: &TokenKind) -> Option<Span> { | ||
| if self.is_diff_marker(long_kind, short_kind) { | ||
| fn conflict_marker(&mut self, long_kind: &TokenKind, short_kind: &TokenKind) -> Option<Span> { | ||
| if self.is_conflict_marker(long_kind, short_kind) { | ||
| let lo = self.token.span; | ||
| for _ in 0..4 { | ||
| self.bump(); | ||
|
|
@@ -2721,8 +2721,9 @@ impl<'a> Parser<'a> { | |
| None | ||
| } | ||
|
|
||
| pub fn recover_diff_marker(&mut self) { | ||
| let Some(start) = self.diff_marker(&TokenKind::BinOp(token::Shl), &TokenKind::Lt) else { | ||
| pub fn recover_conflict_marker(&mut self) { | ||
| let Some(start) = self.conflict_marker(&TokenKind::BinOp(token::Shl), &TokenKind::Lt) | ||
| else { | ||
| return; | ||
| }; | ||
| let mut spans = Vec::with_capacity(3); | ||
|
|
@@ -2734,40 +2735,52 @@ impl<'a> Parser<'a> { | |
| if self.token.kind == TokenKind::Eof { | ||
| break; | ||
| } | ||
| if let Some(span) = self.diff_marker(&TokenKind::OrOr, &TokenKind::BinOp(token::Or)) { | ||
| if let Some(span) = self.conflict_marker(&TokenKind::OrOr, &TokenKind::BinOp(token::Or)) | ||
| { | ||
| middlediff3 = Some(span); | ||
| } | ||
| if let Some(span) = self.diff_marker(&TokenKind::EqEq, &TokenKind::Eq) { | ||
| if let Some(span) = self.conflict_marker(&TokenKind::EqEq, &TokenKind::Eq) { | ||
| middle = Some(span); | ||
| } | ||
| if let Some(span) = self.diff_marker(&TokenKind::BinOp(token::Shr), &TokenKind::Gt) { | ||
| if let Some(span) = self.conflict_marker(&TokenKind::BinOp(token::Shr), &TokenKind::Gt) | ||
| { | ||
| spans.push(span); | ||
| end = Some(span); | ||
| break; | ||
| } | ||
| self.bump(); | ||
| } | ||
| let mut err = self.struct_span_err(spans, "encountered diff marker"); | ||
| err.span_label(start, "after this is the code before the merge"); | ||
| let mut err = self.struct_span_err(spans, "encountered git conflict marker"); | ||
|
|
||
| // with diff3 | ||
| if let Some(middle) = middlediff3 { | ||
| err.span_label(middle, ""); | ||
| err.span_label( | ||
| start, | ||
| "between this marker and `|||||||` is the code that we're merging into", | ||
| ); | ||
| err.span_label(middle, "between this marker and `=======` is the base code (what the two refs diverged from)"); | ||
| } else { | ||
| err.span_label( | ||
| start, | ||
| "between this marker and `=======` is the code that we're merging into", | ||
| ); | ||
| } | ||
|
|
||
| if let Some(middle) = middle { | ||
| err.span_label(middle, ""); | ||
| err.span_label(middle, "between this marker and `>>>>>>>` is the incoming code"); | ||
| } | ||
|
|
||
| if let Some(end) = end { | ||
| err.span_label(end, "above this are the incoming code changes"); | ||
| err.span_label(end, ""); | ||
| } | ||
| err.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", | ||
| "conflict markers indicate that a merge was started but could not be completed due to merge conflicts", | ||
| ); | ||
| err.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", | ||
|
Comment on lines
-2762
to
-2767
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm slightly concerned about removing these two notes, because I find them to be a significant part of what makes the error useful. Would you be open with adding them back in addition to the new ones? Maybe marking some as note (their title is a big less colorful). |
||
| "to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers", | ||
| ); | ||
| err.note( | ||
| "for an explanation on these markers from the `git` documentation, visit \ | ||
| "for more information, visit the `git` documentation \ | ||
| <https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts>", | ||
| ); | ||
| err.emit(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,21 @@ | ||
| error: encountered diff marker | ||
| error: encountered git conflict marker | ||
| --> $DIR/enum-2.rs:3:1 | ||
| | | ||
| LL | <<<<<<< HEAD | ||
| | ^^^^^^^ after this is the code before the merge | ||
| | ^^^^^^^ between this marker and `|||||||` is the code that we're merging into | ||
| LL | x: u8, | ||
| LL | ||||||| | ||
| | ------- | ||
| | ------- between this marker and `=======` is the base code (what the two refs diverged from) | ||
| LL | z: (), | ||
| LL | ======= | ||
| | ------- | ||
| | ------- between this marker and `>>>>>>>` is the incoming code | ||
| 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> | ||
| = 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 | ||
| = note: for more information, visit the `git` documentation <https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts> | ||
|
|
||
| error: aborting due to previous error | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,18 @@ | ||
| error: encountered diff marker | ||
| error: encountered git conflict marker | ||
| --> $DIR/enum.rs:2:1 | ||
| | | ||
| LL | <<<<<<< HEAD | ||
| | ^^^^^^^ after this is the code before the merge | ||
| | ^^^^^^^ between this marker and `=======` is the code that we're merging into | ||
| LL | Foo(u8), | ||
| LL | ======= | ||
| | ------- | ||
| | ------- between this marker and `>>>>>>>` is the incoming code | ||
| LL | Bar(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> | ||
| = 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 | ||
| = note: for more information, visit the `git` documentation <https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts> | ||
|
|
||
| error: aborting due to previous error | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,18 @@ | ||
| error: encountered diff marker | ||
| error: encountered git conflict marker | ||
| --> $DIR/fn-arg.rs:3:1 | ||
| | | ||
| LL | <<<<<<< HEAD | ||
| | ^^^^^^^ after this is the code before the merge | ||
| | ^^^^^^^ between this marker and `=======` is the code that we're merging into | ||
| LL | x: u8, | ||
| LL | ======= | ||
| | ------- | ||
| | ------- between this marker and `>>>>>>>` is the incoming code | ||
| LL | x: 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> | ||
| = 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 | ||
| = note: for more information, visit the `git` documentation <https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts> | ||
|
|
||
| error: aborting due to previous error | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,18 @@ | ||
| error: encountered diff marker | ||
| error: encountered git conflict marker | ||
| --> $DIR/item-with-attr.rs:2:1 | ||
| | | ||
| LL | <<<<<<< HEAD | ||
| | ^^^^^^^ after this is the code before the merge | ||
| | ^^^^^^^ between this marker and `=======` is the code that we're merging into | ||
| LL | fn foo() {} | ||
| LL | ======= | ||
| | ------- | ||
| | ------- between this marker and `>>>>>>>` is the incoming code | ||
| LL | fn bar() {} | ||
| 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> | ||
| = 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 | ||
| = note: for more information, visit the `git` documentation <https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts> | ||
|
|
||
| error: aborting due to previous error | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,18 @@ | ||
| error: encountered diff marker | ||
| error: encountered git conflict marker | ||
| --> $DIR/item.rs:1:1 | ||
| | | ||
| LL | <<<<<<< HEAD | ||
| | ^^^^^^^ after this is the code before the merge | ||
| | ^^^^^^^ between this marker and `=======` is the code that we're merging into | ||
| LL | fn foo() {} | ||
| LL | ======= | ||
| | ------- | ||
| | ------- between this marker and `>>>>>>>` is the incoming code | ||
| LL | fn bar() {} | ||
| 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> | ||
| = 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 | ||
| = note: for more information, visit the `git` documentation <https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts> | ||
|
|
||
| error: aborting due to previous error | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gitis not the only application that uses these kinds of conflict markers.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm that's true. What about the "for more information, visit the
gitdocumentation" note at the end, should that perhaps be reworded to something more along the lines of "if you're usinggitcheck out this documentation"?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me (although I feel that
git's docs are useful even if you're not usinggitspecifically).