Skip to content

Commit b1d0604

Browse files
Rollup merge of rust-lang#126125 - dev-ardi:conflict-markers, r=estebank
Improve conflict marker recovery <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r​? <reviewer name> --> closes rust-lang#113826 r? `@estebank` since you reviewed rust-lang#115413 cc: `@rben01` since you opened up the issue in the first place
2 parents c0e1338 + 9f63712 commit b1d0604

15 files changed

+193
-98
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

+42-16
Original file line numberDiff line numberDiff line change
@@ -2965,9 +2965,10 @@ impl<'a> Parser<'a> {
29652965

29662966
/// This checks if this is a conflict marker, depending of the parameter passed.
29672967
///
2968-
/// * `>>>>>`
2969-
/// * `=====`
2970-
/// * `<<<<<`
2968+
/// * `<<<<<<<`
2969+
/// * `|||||||`
2970+
/// * `=======`
2971+
/// * `>>>>>>>`
29712972
///
29722973
pub(super) fn is_vcs_conflict_marker(
29732974
&mut self,
@@ -2997,14 +2998,18 @@ impl<'a> Parser<'a> {
29972998
}
29982999

29993000
pub(crate) fn err_vcs_conflict_marker(&mut self) -> PResult<'a, ()> {
3001+
// <<<<<<<
30003002
let Some(start) = self.conflict_marker(&TokenKind::BinOp(token::Shl), &TokenKind::Lt)
30013003
else {
30023004
return Ok(());
30033005
};
30043006
let mut spans = Vec::with_capacity(3);
30053007
spans.push(start);
3008+
// |||||||
30063009
let mut middlediff3 = None;
3010+
// =======
30073011
let mut middle = None;
3012+
// >>>>>>>
30083013
let mut end = None;
30093014
loop {
30103015
if self.token.kind == TokenKind::Eof {
@@ -3025,29 +3030,50 @@ impl<'a> Parser<'a> {
30253030
}
30263031
self.bump();
30273032
}
3033+
30283034
let mut err = self.dcx().struct_span_err(spans, "encountered diff marker");
3029-
err.span_label(start, "after this is the code before the merge");
3030-
if let Some(middle) = middlediff3 {
3031-
err.span_label(middle, "");
3032-
}
3035+
match middlediff3 {
3036+
// We're using diff3
3037+
Some(middlediff3) => {
3038+
err.span_label(
3039+
start,
3040+
"between this marker and `|||||||` is the code that we're merging into",
3041+
);
3042+
err.span_label(middlediff3, "between this marker and `=======` is the base code (what the two refs diverged from)");
3043+
}
3044+
None => {
3045+
err.span_label(
3046+
start,
3047+
"between this marker and `=======` is the code that we're merging into",
3048+
);
3049+
}
3050+
};
3051+
30333052
if let Some(middle) = middle {
3034-
err.span_label(middle, "");
3053+
err.span_label(middle, "between this marker and `>>>>>>>` is the incoming code");
30353054
}
30363055
if let Some(end) = end {
3037-
err.span_label(end, "above this are the incoming code changes");
3056+
err.span_label(end, "this marker concludes the conflict region");
30383057
}
3039-
err.help(
3040-
"if you're having merge conflicts after pulling new code, the top section is the code \
3041-
you already had and the bottom section is the remote code",
3058+
err.note(
3059+
"conflict markers indicate that a merge was started but could not be completed due \
3060+
to merge conflicts\n\
3061+
to resolve a conflict, keep only the code you want and then delete the lines \
3062+
containing conflict markers",
30423063
);
30433064
err.help(
3044-
"if you're in the middle of a rebase, the top section is the code being rebased onto \
3045-
and the bottom section is the code coming from the current commit being rebased",
3065+
"if you're having merge conflicts after pulling new code:\n\
3066+
the top section is the code you already had and the bottom section is the remote code\n\
3067+
if you're in the middle of a rebase:\n\
3068+
the top section is the code being rebased onto and the bottom section is the code \
3069+
coming from the current commit being rebased",
30463070
);
3071+
30473072
err.note(
3048-
"for an explanation on these markers from the `git` documentation, visit \
3049-
<https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts>",
3073+
"for an explanation on these markers from the `git` documentation:\n\
3074+
visit <https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts>",
30503075
);
3076+
30513077
Err(err)
30523078
}
30533079

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

+12-7
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,25 @@ 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
18-
= 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>
16+
= note: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
17+
to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers
18+
= help: if you're having merge conflicts after pulling new code:
19+
the top section is the code you already had and the bottom section is the remote code
20+
if you're in the middle of a rebase:
21+
the top section is the code being rebased onto and the bottom section is the code coming from the current commit being rebased
22+
= note: for an explanation on these markers from the `git` documentation:
23+
visit <https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts>
1924

2025
error: aborting due to 1 previous error
2126

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

+11-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@ 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
15-
= 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>
13+
= note: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
14+
to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers
15+
= help: if you're having merge conflicts after pulling new code:
16+
the top section is the code you already had and the bottom section is the remote code
17+
if you're in the middle of a rebase:
18+
the top section is the code being rebased onto and the bottom section is the code coming from the current commit being rebased
19+
= note: for an explanation on these markers from the `git` documentation:
20+
visit <https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts>
1621

1722
error: aborting due to 1 previous error
1823

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

+11-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@ 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
15-
= 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>
13+
= note: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
14+
to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers
15+
= help: if you're having merge conflicts after pulling new code:
16+
the top section is the code you already had and the bottom section is the remote code
17+
if you're in the middle of a rebase:
18+
the top section is the code being rebased onto and the bottom section is the code coming from the current commit being rebased
19+
= note: for an explanation on these markers from the `git` documentation:
20+
visit <https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts>
1621

1722
error: aborting due to 1 previous error
1823

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

+11-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@ 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
15-
= 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>
13+
= note: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
14+
to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers
15+
= help: if you're having merge conflicts after pulling new code:
16+
the top section is the code you already had and the bottom section is the remote code
17+
if you're in the middle of a rebase:
18+
the top section is the code being rebased onto and the bottom section is the code coming from the current commit being rebased
19+
= note: for an explanation on these markers from the `git` documentation:
20+
visit <https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts>
1621

1722
error: aborting due to 1 previous error
1823

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

+11-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@ 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
15-
= 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>
13+
= note: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
14+
to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers
15+
= help: if you're having merge conflicts after pulling new code:
16+
the top section is the code you already had and the bottom section is the remote code
17+
if you're in the middle of a rebase:
18+
the top section is the code being rebased onto and the bottom section is the code coming from the current commit being rebased
19+
= note: for an explanation on these markers from the `git` documentation:
20+
visit <https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts>
1621

1722
error: aborting due to 1 previous error
1823

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

+11-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@ 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
15-
= 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>
13+
= note: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
14+
to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers
15+
= help: if you're having merge conflicts after pulling new code:
16+
the top section is the code you already had and the bottom section is the remote code
17+
if you're in the middle of a rebase:
18+
the top section is the code being rebased onto and the bottom section is the code coming from the current commit being rebased
19+
= note: for an explanation on these markers from the `git` documentation:
20+
visit <https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts>
1621

1722
error: aborting due to 1 previous error
1823

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

+11-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@ 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
15-
= 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>
13+
= note: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
14+
to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers
15+
= help: if you're having merge conflicts after pulling new code:
16+
the top section is the code you already had and the bottom section is the remote code
17+
if you're in the middle of a rebase:
18+
the top section is the code being rebased onto and the bottom section is the code coming from the current commit being rebased
19+
= note: for an explanation on these markers from the `git` documentation:
20+
visit <https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts>
1621

1722
error: aborting due to 1 previous error
1823

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

+11-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@ 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
15-
= 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>
13+
= note: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
14+
to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers
15+
= help: if you're having merge conflicts after pulling new code:
16+
the top section is the code you already had and the bottom section is the remote code
17+
if you're in the middle of a rebase:
18+
the top section is the code being rebased onto and the bottom section is the code coming from the current commit being rebased
19+
= note: for an explanation on these markers from the `git` documentation:
20+
visit <https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts>
1621

1722
error: aborting due to 1 previous error
1823

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

+11-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@ 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
15-
= 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>
13+
= note: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
14+
to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers
15+
= help: if you're having merge conflicts after pulling new code:
16+
the top section is the code you already had and the bottom section is the remote code
17+
if you're in the middle of a rebase:
18+
the top section is the code being rebased onto and the bottom section is the code coming from the current commit being rebased
19+
= note: for an explanation on these markers from the `git` documentation:
20+
visit <https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts>
1621

1722
error: aborting due to 1 previous error
1823

0 commit comments

Comments
 (0)