Skip to content

Commit fae6179

Browse files
committed
Improve conflict marker recovery
1 parent 1be24d7 commit fae6179

15 files changed

+97
-83
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

+28-14
Original file line numberDiff line numberDiff line change
@@ -2989,14 +2989,18 @@ impl<'a> Parser<'a> {
29892989
}
29902990

29912991
pub fn err_vcs_conflict_marker(&mut self) -> PResult<'a, ()> {
2992+
// <<<<<<<
29922993
let Some(start) = self.conflict_marker(&TokenKind::BinOp(token::Shl), &TokenKind::Lt)
29932994
else {
29942995
return Ok(());
29952996
};
29962997
let mut spans = Vec::with_capacity(3);
29972998
spans.push(start);
2999+
// |||||||
29983000
let mut middlediff3 = None;
3001+
// =======
29993002
let mut middle = None;
3003+
// >>>>>>>
30003004
let mut end = None;
30013005
loop {
30023006
if self.token.kind == TokenKind::Eof {
@@ -3017,29 +3021,39 @@ impl<'a> Parser<'a> {
30173021
}
30183022
self.bump();
30193023
}
3024+
30203025
let mut err = self.dcx().struct_span_err(spans, "encountered diff marker");
3021-
err.span_label(start, "after this is the code before the merge");
3022-
if let Some(middle) = middlediff3 {
3023-
err.span_label(middle, "");
3024-
}
3026+
match middlediff3 {
3027+
// We're using diff3
3028+
Some(middlediff3) => {
3029+
err.span_label(
3030+
start,
3031+
"between this marker and `|||||||` is the code that we're merging into",
3032+
);
3033+
err.span_label(middlediff3, "between this marker and `=======` is the base code (what the two refs diverged from)");
3034+
}
3035+
None => {
3036+
err.span_label(
3037+
start,
3038+
"between this marker and `=======` is the code that we're merging into",
3039+
);
3040+
}
3041+
};
3042+
30253043
if let Some(middle) = middle {
3026-
err.span_label(middle, "");
3044+
err.span_label(middle, "between this marker and `>>>>>>>` is the incoming code");
30273045
}
30283046
if let Some(end) = end {
3029-
err.span_label(end, "above this are the incoming code changes");
3047+
err.span_label(end, "this marker concludes the conflict region");
30303048
}
3031-
err.help(
3032-
"if you're having merge conflicts after pulling new code, the top section is the code \
3033-
you already had and the bottom section is the remote code",
3034-
);
3035-
err.help(
3036-
"if you're in the middle of a rebase, the top section is the code being rebased onto \
3037-
and the bottom section is the code coming from the current commit being rebased",
3038-
);
3049+
err.help("conflict markers indicate that a merge was started but could not be completed due to merge conflicts");
3050+
err.help("to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers");
3051+
30393052
err.note(
30403053
"for an explanation on these markers from the `git` documentation, visit \
30413054
<https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts>",
30423055
);
3056+
30433057
Err(err)
30443058
}
30453059

tests/ui/parser/diff-markers/enum-2.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ error: encountered diff marker
22
--> $DIR/enum-2.rs:3:1
33
|
44
LL | <<<<<<< HEAD
5-
| ^^^^^^^ after this is the code before the merge
5+
| ^^^^^^^ between this marker and `|||||||` is the code that we're merging into
66
LL | x: u8,
77
LL | |||||||
8-
| -------
8+
| ------- between this marker and `=======` is the base code (what the two refs diverged from)
99
LL | z: (),
1010
LL | =======
11-
| -------
11+
| ------- between this marker and `>>>>>>>` is the incoming code
1212
LL | y: i8,
1313
LL | >>>>>>> branch
14-
| ^^^^^^^ above this are the incoming code changes
14+
| ^^^^^^^ this marker concludes the conflict region
1515
|
16-
= 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
17-
= 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
16+
= help: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
17+
= help: to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers
1818
= 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>
1919

2020
error: aborting due to 1 previous error

tests/ui/parser/diff-markers/enum.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ error: encountered diff marker
22
--> $DIR/enum.rs:2:1
33
|
44
LL | <<<<<<< HEAD
5-
| ^^^^^^^ after this is the code before the merge
5+
| ^^^^^^^ between this marker and `=======` is the code that we're merging into
66
LL | Foo(u8),
77
LL | =======
8-
| -------
8+
| ------- between this marker and `>>>>>>>` is the incoming code
99
LL | Bar(i8),
1010
LL | >>>>>>> branch
11-
| ^^^^^^^ above this are the incoming code changes
11+
| ^^^^^^^ this marker concludes the conflict region
1212
|
13-
= 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
14-
= 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
13+
= help: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
14+
= help: to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers
1515
= 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>
1616

1717
error: aborting due to 1 previous error

tests/ui/parser/diff-markers/fn-arg.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ error: encountered diff marker
22
--> $DIR/fn-arg.rs:3:1
33
|
44
LL | <<<<<<< HEAD
5-
| ^^^^^^^ after this is the code before the merge
5+
| ^^^^^^^ between this marker and `=======` is the code that we're merging into
66
LL | x: u8,
77
LL | =======
8-
| -------
8+
| ------- between this marker and `>>>>>>>` is the incoming code
99
LL | x: i8,
1010
LL | >>>>>>> branch
11-
| ^^^^^^^ above this are the incoming code changes
11+
| ^^^^^^^ this marker concludes the conflict region
1212
|
13-
= 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
14-
= 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
13+
= help: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
14+
= help: to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers
1515
= 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>
1616

1717
error: aborting due to 1 previous error

tests/ui/parser/diff-markers/item-with-attr.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ error: encountered diff marker
22
--> $DIR/item-with-attr.rs:2:1
33
|
44
LL | <<<<<<< HEAD
5-
| ^^^^^^^ after this is the code before the merge
5+
| ^^^^^^^ between this marker and `=======` is the code that we're merging into
66
LL | fn foo() {}
77
LL | =======
8-
| -------
8+
| ------- between this marker and `>>>>>>>` is the incoming code
99
LL | fn bar() {}
1010
LL | >>>>>>> branch
11-
| ^^^^^^^ above this are the incoming code changes
11+
| ^^^^^^^ this marker concludes the conflict region
1212
|
13-
= 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
14-
= 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
13+
= help: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
14+
= help: to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers
1515
= 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>
1616

1717
error: aborting due to 1 previous error

tests/ui/parser/diff-markers/item.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ error: encountered diff marker
22
--> $DIR/item.rs:1:1
33
|
44
LL | <<<<<<< HEAD
5-
| ^^^^^^^ after this is the code before the merge
5+
| ^^^^^^^ between this marker and `=======` is the code that we're merging into
66
LL | fn foo() {}
77
LL | =======
8-
| -------
8+
| ------- between this marker and `>>>>>>>` is the incoming code
99
LL | fn bar() {}
1010
LL | >>>>>>> branch
11-
| ^^^^^^^ above this are the incoming code changes
11+
| ^^^^^^^ this marker concludes the conflict region
1212
|
13-
= 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
14-
= 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
13+
= help: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
14+
= help: to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers
1515
= 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>
1616

1717
error: aborting due to 1 previous error

tests/ui/parser/diff-markers/statement.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ error: encountered diff marker
22
--> $DIR/statement.rs:10:1
33
|
44
LL | <<<<<<< HEAD
5-
| ^^^^^^^ after this is the code before the merge
5+
| ^^^^^^^ between this marker and `=======` is the code that we're merging into
66
LL | S::foo();
77
LL | =======
8-
| -------
8+
| ------- between this marker and `>>>>>>>` is the incoming code
99
LL | S::bar();
1010
LL | >>>>>>> branch
11-
| ^^^^^^^ above this are the incoming code changes
11+
| ^^^^^^^ this marker concludes the conflict region
1212
|
13-
= 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
14-
= 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
13+
= help: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
14+
= help: to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers
1515
= 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>
1616

1717
error: aborting due to 1 previous error

tests/ui/parser/diff-markers/struct-expr.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ error: encountered diff marker
22
--> $DIR/struct-expr.rs:6:1
33
|
44
LL | <<<<<<< HEAD
5-
| ^^^^^^^ after this is the code before the merge
5+
| ^^^^^^^ between this marker and `=======` is the code that we're merging into
66
LL | x: 42,
77
LL | =======
8-
| -------
8+
| ------- between this marker and `>>>>>>>` is the incoming code
99
LL | x: 0,
1010
LL | >>>>>>> branch
11-
| ^^^^^^^ above this are the incoming code changes
11+
| ^^^^^^^ this marker concludes the conflict region
1212
|
13-
= 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
14-
= 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
13+
= help: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
14+
= help: to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers
1515
= 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>
1616

1717
error: aborting due to 1 previous error

tests/ui/parser/diff-markers/struct.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ error: encountered diff marker
22
--> $DIR/struct.rs:2:1
33
|
44
LL | <<<<<<< HEAD
5-
| ^^^^^^^ after this is the code before the merge
5+
| ^^^^^^^ between this marker and `=======` is the code that we're merging into
66
LL | x: u8,
77
LL | =======
8-
| -------
8+
| ------- between this marker and `>>>>>>>` is the incoming code
99
LL | x: i8,
1010
LL | >>>>>>> branch
11-
| ^^^^^^^ above this are the incoming code changes
11+
| ^^^^^^^ this marker concludes the conflict region
1212
|
13-
= 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
14-
= 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
13+
= help: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
14+
= help: to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers
1515
= 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>
1616

1717
error: aborting due to 1 previous error

tests/ui/parser/diff-markers/trait-item.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ error: encountered diff marker
22
--> $DIR/trait-item.rs:2:1
33
|
44
LL | <<<<<<< HEAD
5-
| ^^^^^^^ after this is the code before the merge
5+
| ^^^^^^^ between this marker and `=======` is the code that we're merging into
66
LL | fn foo() {}
77
LL | =======
8-
| -------
8+
| ------- between this marker and `>>>>>>>` is the incoming code
99
LL | fn bar() {}
1010
LL | >>>>>>> branch
11-
| ^^^^^^^ above this are the incoming code changes
11+
| ^^^^^^^ this marker concludes the conflict region
1212
|
13-
= 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
14-
= 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
13+
= help: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
14+
= help: to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers
1515
= 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>
1616

1717
error: aborting due to 1 previous error

tests/ui/parser/diff-markers/tuple-struct.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ error: encountered diff marker
22
--> $DIR/tuple-struct.rs:2:1
33
|
44
LL | <<<<<<< HEAD
5-
| ^^^^^^^ after this is the code before the merge
5+
| ^^^^^^^ between this marker and `=======` is the code that we're merging into
66
LL | u8,
77
LL | =======
8-
| -------
8+
| ------- between this marker and `>>>>>>>` is the incoming code
99
LL | i8,
1010
LL | >>>>>>> branch
11-
| ^^^^^^^ above this are the incoming code changes
11+
| ^^^^^^^ this marker concludes the conflict region
1212
|
13-
= 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
14-
= 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
13+
= help: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
14+
= help: to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers
1515
= 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>
1616

1717
error: aborting due to 1 previous error

tests/ui/parser/diff-markers/unclosed-delims-in-macro.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ error: encountered diff marker
22
--> $DIR/unclosed-delims-in-macro.rs:2:1
33
|
44
LL | <<<<<<< HEAD
5-
| ^^^^^^^ after this is the code before the merge
5+
| ^^^^^^^ between this marker and `=======` is the code that we're merging into
66
...
77
LL | =======
8-
| -------
8+
| ------- between this marker and `>>>>>>>` is the incoming code
99
LL | () { //
1010
LL | >>>>>>> 7a4f13c blah blah blah
11-
| ^^^^^^^ above this are the incoming code changes
11+
| ^^^^^^^ this marker concludes the conflict region
1212
|
13-
= 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
14-
= 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
13+
= help: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
14+
= help: to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers
1515
= 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>
1616

1717
error: aborting due to 1 previous error

tests/ui/parser/diff-markers/unclosed-delims.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ mod tests {
22
#[test]
33
<<<<<<< HEAD
44
//~^ ERROR encountered diff marker
5-
//~| NOTE after this is the code before the merge
6-
//~| NOTE for an explanation on these markers
5+
//~| NOTE between this marker and `=======` is the code that we're merging into
6+
////~| NOTE for an explanation on these markers
77
fn test1() {
88
=======
99
//~^ NOTE
1010
fn test2() {
1111
>>>>>>> 7a4f13c blah blah blah
12-
//~^ NOTE above this are the incoming code changes
12+
//~^ NOTE this marker concludes the conflict region
1313
}
1414
}

tests/ui/parser/diff-markers/unclosed-delims.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ error: encountered diff marker
22
--> $DIR/unclosed-delims.rs:3:1
33
|
44
LL | <<<<<<< HEAD
5-
| ^^^^^^^ after this is the code before the merge
5+
| ^^^^^^^ between this marker and `=======` is the code that we're merging into
66
...
77
LL | =======
8-
| -------
8+
| ------- between this marker and `>>>>>>>` is the incoming code
99
...
1010
LL | >>>>>>> 7a4f13c blah blah blah
11-
| ^^^^^^^ above this are the incoming code changes
11+
| ^^^^^^^ this marker concludes the conflict region
1212
|
13-
= 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
14-
= 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
13+
= help: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
14+
= help: to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers
1515
= 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>
1616

1717
error: aborting due to 1 previous error

tests/ui/parser/diff-markers/use-statement.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ error: encountered diff marker
22
--> $DIR/use-statement.rs:2:1
33
|
44
LL | <<<<<<< HEAD
5-
| ^^^^^^^ after this is the code before the merge
5+
| ^^^^^^^ between this marker and `=======` is the code that we're merging into
66
LL | bar,
77
LL | =======
8-
| -------
8+
| ------- between this marker and `>>>>>>>` is the incoming code
99
LL | baz,
1010
LL | >>>>>>> branch
11-
| ^^^^^^^ above this are the incoming code changes
11+
| ^^^^^^^ this marker concludes the conflict region
1212
|
13-
= 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
14-
= 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
13+
= help: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
14+
= help: to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers
1515
= 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>
1616

1717
error: aborting due to 1 previous error

0 commit comments

Comments
 (0)