Skip to content

Commit f33e85b

Browse files
committed
Improve conflict marker recovery
1 parent d8fde50 commit f33e85b

15 files changed

+96
-83
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

+27-14
Original file line numberDiff line numberDiff line change
@@ -2999,8 +2999,11 @@ impl<'a> Parser<'a> {
29992999
};
30003000
let mut spans = Vec::with_capacity(3);
30013001
spans.push(start);
3002+
// |||||||
30023003
let mut middlediff3 = None;
3004+
// =======
30033005
let mut middle = None;
3006+
// >>>>>>>
30043007
let mut end = None;
30053008
loop {
30063009
if self.token.kind == TokenKind::Eof {
@@ -3021,29 +3024,39 @@ impl<'a> Parser<'a> {
30213024
}
30223025
self.bump();
30233026
}
3027+
30243028
let mut err = self.dcx().struct_span_err(spans, "encountered diff marker");
3025-
err.span_label(start, "after this is the code before the merge");
3026-
if let Some(middle) = middlediff3 {
3027-
err.span_label(middle, "");
3028-
}
3029+
match middlediff3 {
3030+
// We're using diff3
3031+
Some(middlediff3) => {
3032+
err.span_label(
3033+
start,
3034+
"between this marker and `|||||||` is the code that we're merging into",
3035+
);
3036+
err.span_label(middlediff3, "between this marker and `=======` is the base code (what the two refs diverged from)");
3037+
}
3038+
None => {
3039+
err.span_label(
3040+
start,
3041+
"between this marker and `=======` is the code that we're merging into",
3042+
);
3043+
}
3044+
};
3045+
30293046
if let Some(middle) = middle {
3030-
err.span_label(middle, "");
3047+
err.span_label(middle, "between this marker and `>>>>>>>` is the incoming code");
30313048
}
30323049
if let Some(end) = end {
3033-
err.span_label(end, "above this are the incoming code changes");
3050+
err.span_label(end, "this marker concludes the conflict region");
30343051
}
3035-
err.help(
3036-
"if you're having merge conflicts after pulling new code, the top section is the code \
3037-
you already had and the bottom section is the remote code",
3038-
);
3039-
err.help(
3040-
"if you're in the middle of a rebase, the top section is the code being rebased onto \
3041-
and the bottom section is the code coming from the current commit being rebased",
3042-
);
3052+
err.help("conflict markers indicate that a merge was started but could not be completed due to merge conflicts");
3053+
err.help("to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers");
3054+
30433055
err.note(
30443056
"for an explanation on these markers from the `git` documentation, visit \
30453057
<https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts>",
30463058
);
3059+
30473060
Err(err)
30483061
}
30493062

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)