Skip to content

Commit ae31c83

Browse files
committed
Remove diff marker detection.
1 parent 33c245b commit ae31c83

32 files changed

+12
-632
lines changed

compiler/rustc_parse/src/lexer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub(crate) fn lex_token_trees<'psess, 'src>(
8383
.filter_map(|unmatched_delim| make_unclosed_delims_error(unmatched_delim, psess))
8484
.collect();
8585
if let Err(errs) = res {
86-
// Add unclosing delimiter or diff marker errors
86+
// Add unclosing delimiter errors.
8787
buffer.extend(errs);
8888
}
8989
Err(buffer)

compiler/rustc_parse/src/lexer/tokentrees.rs

+5-20
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
108108
// We stop at any delimiter so we can try to recover if the user
109109
// uses an incorrect delimiter.
110110
let (open_spacing, tts, res) = self.lex_token_trees(/* is_delimited */ true);
111-
if let Err(errs) = res {
112-
return Err(self.unclosed_delim_err(tts, errs));
111+
if let Err(mut errs) = res {
112+
self.unclosed_delim_err(tts, &mut errs);
113+
return Err(errs);
113114
}
114115

115116
// Expand to cover the entire delimited token tree.
@@ -247,23 +248,14 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
247248
this_spacing
248249
}
249250

250-
fn unclosed_delim_err(
251-
&mut self,
252-
tts: TokenStream,
253-
mut errs: Vec<PErr<'psess>>,
254-
) -> Vec<PErr<'psess>> {
255-
// If there are unclosed delims, see if there are diff markers and if so, point them
256-
// out instead of complaining about the unclosed delims.
251+
fn unclosed_delim_err(&mut self, tts: TokenStream, errs: &mut Vec<PErr<'psess>>) {
257252
let mut parser = Parser::new(self.psess, tts, None);
258-
let mut diff_errs = vec![];
259253
// Suggest removing a `{` we think appears in an `if`/`while` condition.
260254
// We want to suggest removing a `{` only if we think we're in an `if`/`while` condition,
261255
// but we have no way of tracking this in the lexer itself, so we piggyback on the parser.
262256
let mut in_cond = false;
263257
while parser.token != token::Eof {
264-
if let Err(diff_err) = parser.err_vcs_conflict_marker() {
265-
diff_errs.push(diff_err);
266-
} else if parser.is_keyword_ahead(0, &[kw::If, kw::While]) {
258+
if parser.is_keyword_ahead(0, &[kw::If, kw::While]) {
267259
in_cond = true;
268260
} else if matches!(
269261
parser.token.kind,
@@ -299,13 +291,6 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
299291
}
300292
parser.bump();
301293
}
302-
if !diff_errs.is_empty() {
303-
for err in errs {
304-
err.cancel();
305-
}
306-
return diff_errs;
307-
}
308-
errs
309294
}
310295

311296
fn close_delim_err(&mut self, delim: Delimiter) -> PErr<'psess> {

compiler/rustc_parse/src/parser/diagnostics.rs

+1-115
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_ast_pretty::pprust;
1616
use rustc_data_structures::fx::FxHashSet;
1717
use rustc_data_structures::sync::Lrc;
1818
use rustc_errors::{
19-
Applicability, Diag, DiagCtxtHandle, ErrorGuaranteed, FatalError, PErr, PResult, Subdiagnostic,
19+
Applicability, Diag, DiagCtxtHandle, ErrorGuaranteed, PErr, PResult, Subdiagnostic,
2020
Suggestions, pluralize,
2121
};
2222
use rustc_session::errors::ExprParenthesesNeeded;
@@ -3029,120 +3029,6 @@ impl<'a> Parser<'a> {
30293029
err
30303030
}
30313031

3032-
/// This checks if this is a conflict marker, depending of the parameter passed.
3033-
///
3034-
/// * `<<<<<<<`
3035-
/// * `|||||||`
3036-
/// * `=======`
3037-
/// * `>>>>>>>`
3038-
///
3039-
pub(super) fn is_vcs_conflict_marker(
3040-
&mut self,
3041-
long_kind: &TokenKind,
3042-
short_kind: &TokenKind,
3043-
) -> bool {
3044-
(0..3).all(|i| self.look_ahead(i, |tok| tok == long_kind))
3045-
&& self.look_ahead(3, |tok| tok == short_kind)
3046-
}
3047-
3048-
fn conflict_marker(&mut self, long_kind: &TokenKind, short_kind: &TokenKind) -> Option<Span> {
3049-
if self.is_vcs_conflict_marker(long_kind, short_kind) {
3050-
let lo = self.token.span;
3051-
for _ in 0..4 {
3052-
self.bump();
3053-
}
3054-
return Some(lo.to(self.prev_token.span));
3055-
}
3056-
None
3057-
}
3058-
3059-
pub(super) fn recover_vcs_conflict_marker(&mut self) {
3060-
if let Err(err) = self.err_vcs_conflict_marker() {
3061-
err.emit();
3062-
FatalError.raise();
3063-
}
3064-
}
3065-
3066-
pub(crate) fn err_vcs_conflict_marker(&mut self) -> PResult<'a, ()> {
3067-
// <<<<<<<
3068-
let Some(start) = self.conflict_marker(&TokenKind::BinOp(token::Shl), &TokenKind::Lt)
3069-
else {
3070-
return Ok(());
3071-
};
3072-
let mut spans = Vec::with_capacity(3);
3073-
spans.push(start);
3074-
// |||||||
3075-
let mut middlediff3 = None;
3076-
// =======
3077-
let mut middle = None;
3078-
// >>>>>>>
3079-
let mut end = None;
3080-
loop {
3081-
if self.token == TokenKind::Eof {
3082-
break;
3083-
}
3084-
if let Some(span) = self.conflict_marker(&TokenKind::OrOr, &TokenKind::BinOp(token::Or))
3085-
{
3086-
middlediff3 = Some(span);
3087-
}
3088-
if let Some(span) = self.conflict_marker(&TokenKind::EqEq, &TokenKind::Eq) {
3089-
middle = Some(span);
3090-
}
3091-
if let Some(span) = self.conflict_marker(&TokenKind::BinOp(token::Shr), &TokenKind::Gt)
3092-
{
3093-
spans.push(span);
3094-
end = Some(span);
3095-
break;
3096-
}
3097-
self.bump();
3098-
}
3099-
3100-
let mut err = self.dcx().struct_span_err(spans, "encountered diff marker");
3101-
match middlediff3 {
3102-
// We're using diff3
3103-
Some(middlediff3) => {
3104-
err.span_label(
3105-
start,
3106-
"between this marker and `|||||||` is the code that we're merging into",
3107-
);
3108-
err.span_label(middlediff3, "between this marker and `=======` is the base code (what the two refs diverged from)");
3109-
}
3110-
None => {
3111-
err.span_label(
3112-
start,
3113-
"between this marker and `=======` is the code that we're merging into",
3114-
);
3115-
}
3116-
};
3117-
3118-
if let Some(middle) = middle {
3119-
err.span_label(middle, "between this marker and `>>>>>>>` is the incoming code");
3120-
}
3121-
if let Some(end) = end {
3122-
err.span_label(end, "this marker concludes the conflict region");
3123-
}
3124-
err.note(
3125-
"conflict markers indicate that a merge was started but could not be completed due \
3126-
to merge conflicts\n\
3127-
to resolve a conflict, keep only the code you want and then delete the lines \
3128-
containing conflict markers",
3129-
);
3130-
err.help(
3131-
"if you're having merge conflicts after pulling new code:\n\
3132-
the top section is the code you already had and the bottom section is the remote code\n\
3133-
if you're in the middle of a rebase:\n\
3134-
the top section is the code being rebased onto and the bottom section is the code \
3135-
coming from the current commit being rebased",
3136-
);
3137-
3138-
err.note(
3139-
"for an explanation on these markers from the `git` documentation:\n\
3140-
visit <https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts>",
3141-
);
3142-
3143-
Err(err)
3144-
}
3145-
31463032
/// Parse and throw away a parenthesized comma separated
31473033
/// sequence of patterns until `)` is reached.
31483034
fn skip_pat_list(&mut self) -> PResult<'a, ()> {

compiler/rustc_parse/src/parser/expr.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3739,7 +3739,6 @@ impl<'a> Parser<'a> {
37393739
/// Parses `ident (COLON expr)?`.
37403740
fn parse_expr_field(&mut self) -> PResult<'a, ExprField> {
37413741
let attrs = self.parse_outer_attributes()?;
3742-
self.recover_vcs_conflict_marker();
37433742
self.collect_tokens(None, attrs, ForceCollect::No, |this, attrs| {
37443743
let lo = this.token.span;
37453744

compiler/rustc_parse/src/parser/item.rs

+4-38
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ impl<'a> Parser<'a> {
129129
fn_parse_mode: FnParseMode,
130130
force_collect: ForceCollect,
131131
) -> PResult<'a, Option<Item>> {
132-
self.recover_vcs_conflict_marker();
133132
let attrs = self.parse_outer_attributes()?;
134-
self.recover_vcs_conflict_marker();
135133
self.parse_item_common(attrs, true, false, fn_parse_mode, force_collect)
136134
}
137135

@@ -775,7 +773,6 @@ impl<'a> Parser<'a> {
775773
if self.recover_doc_comment_before_brace() {
776774
continue;
777775
}
778-
self.recover_vcs_conflict_marker();
779776
match parse_item(self) {
780777
Ok(None) => {
781778
let mut is_unnecessary_semicolon = !items.is_empty()
@@ -1121,11 +1118,8 @@ impl<'a> Parser<'a> {
11211118
/// USE_TREE_LIST = ∅ | (USE_TREE `,`)* USE_TREE [`,`]
11221119
/// ```
11231120
fn parse_use_tree_list(&mut self) -> PResult<'a, ThinVec<(UseTree, ast::NodeId)>> {
1124-
self.parse_delim_comma_seq(Delimiter::Brace, |p| {
1125-
p.recover_vcs_conflict_marker();
1126-
Ok((p.parse_use_tree()?, DUMMY_NODE_ID))
1127-
})
1128-
.map(|(r, _)| r)
1121+
self.parse_delim_comma_seq(Delimiter::Brace, |p| Ok((p.parse_use_tree()?, DUMMY_NODE_ID)))
1122+
.map(|(r, _)| r)
11291123
}
11301124

11311125
fn parse_rename(&mut self) -> PResult<'a, Option<Ident>> {
@@ -1564,9 +1558,7 @@ impl<'a> Parser<'a> {
15641558
}
15651559

15661560
fn parse_enum_variant(&mut self, span: Span) -> PResult<'a, Option<Variant>> {
1567-
self.recover_vcs_conflict_marker();
15681561
let variant_attrs = self.parse_outer_attributes()?;
1569-
self.recover_vcs_conflict_marker();
15701562
let help = "enum variants can be `Variant`, `Variant = <integer>`, \
15711563
`Variant(Type, ..., TypeN)` or `Variant { fields: Types }`";
15721564
self.collect_tokens(None, variant_attrs, ForceCollect::No, |this, variant_attrs| {
@@ -1808,34 +1800,11 @@ impl<'a> Parser<'a> {
18081800
self.parse_paren_comma_seq(|p| {
18091801
let attrs = p.parse_outer_attributes()?;
18101802
p.collect_tokens(None, attrs, ForceCollect::No, |p, attrs| {
1811-
let mut snapshot = None;
1812-
if p.is_vcs_conflict_marker(&TokenKind::BinOp(token::Shl), &TokenKind::Lt) {
1813-
// Account for `<<<<<<<` diff markers. We can't proactively error here because
1814-
// that can be a valid type start, so we snapshot and reparse only we've
1815-
// encountered another parse error.
1816-
snapshot = Some(p.create_snapshot_for_diagnostic());
1817-
}
18181803
let lo = p.token.span;
1819-
let vis = match p.parse_visibility(FollowedByType::Yes) {
1820-
Ok(vis) => vis,
1821-
Err(err) => {
1822-
if let Some(ref mut snapshot) = snapshot {
1823-
snapshot.recover_vcs_conflict_marker();
1824-
}
1825-
return Err(err);
1826-
}
1827-
};
1804+
let vis = p.parse_visibility(FollowedByType::Yes)?;
18281805
// Unsafe fields are not supported in tuple structs, as doing so would result in a
18291806
// parsing ambiguity for `struct X(unsafe fn())`.
1830-
let ty = match p.parse_ty() {
1831-
Ok(ty) => ty,
1832-
Err(err) => {
1833-
if let Some(ref mut snapshot) = snapshot {
1834-
snapshot.recover_vcs_conflict_marker();
1835-
}
1836-
return Err(err);
1837-
}
1838-
};
1807+
let ty = p.parse_ty()?;
18391808
let mut default = None;
18401809
if p.token == token::Eq {
18411810
let mut snapshot = p.create_snapshot_for_diagnostic();
@@ -1875,9 +1844,7 @@ impl<'a> Parser<'a> {
18751844

18761845
/// Parses an element of a struct declaration.
18771846
fn parse_field_def(&mut self, adt_ty: &str) -> PResult<'a, FieldDef> {
1878-
self.recover_vcs_conflict_marker();
18791847
let attrs = self.parse_outer_attributes()?;
1880-
self.recover_vcs_conflict_marker();
18811848
self.collect_tokens(None, attrs, ForceCollect::No, |this, attrs| {
18821849
let lo = this.token.span;
18831850
let vis = this.parse_visibility(FollowedByType::No)?;
@@ -2830,7 +2797,6 @@ impl<'a> Parser<'a> {
28302797
}
28312798

28322799
let (mut params, _) = self.parse_paren_comma_seq(|p| {
2833-
p.recover_vcs_conflict_marker();
28342800
let snapshot = p.create_snapshot_for_diagnostic();
28352801
let param = p.parse_param_general(req_name, first_param).or_else(|e| {
28362802
let guar = e.emit();

compiler/rustc_parse/src/parser/stmt.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::ops::Bound;
55
use ast::Label;
66
use rustc_ast as ast;
77
use rustc_ast::ptr::P;
8-
use rustc_ast::token::{self, Delimiter, TokenKind};
8+
use rustc_ast::token::{self, Delimiter};
99
use rustc_ast::util::classify::{self, TrailingBrace};
1010
use rustc_ast::{
1111
AttrStyle, AttrVec, Block, BlockCheckMode, DUMMY_NODE_ID, Expr, ExprKind, HasAttrs, Local,
@@ -678,22 +678,12 @@ impl<'a> Parser<'a> {
678678
recover: AttemptLocalParseRecovery,
679679
) -> PResult<'a, P<Block>> {
680680
let mut stmts = ThinVec::new();
681-
let mut snapshot = None;
682681
while !self.eat(&token::CloseDelim(Delimiter::Brace)) {
683682
if self.token == token::Eof {
684683
break;
685684
}
686-
if self.is_vcs_conflict_marker(&TokenKind::BinOp(token::Shl), &TokenKind::Lt) {
687-
// Account for `<<<<<<<` diff markers. We can't proactively error here because
688-
// that can be a valid path start, so we snapshot and reparse only we've
689-
// encountered another parse error.
690-
snapshot = Some(self.create_snapshot_for_diagnostic());
691-
}
692685
let stmt = match self.parse_full_stmt(recover) {
693686
Err(mut err) if recover.yes() => {
694-
if let Some(ref mut snapshot) = snapshot {
695-
snapshot.recover_vcs_conflict_marker();
696-
}
697687
if self.token == token::Colon {
698688
// if a previous and next token of the current one is
699689
// integer literal (e.g. `1:42`), it's likely a range

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

-11
This file was deleted.

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

-26
This file was deleted.

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

-7
This file was deleted.

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

-23
This file was deleted.

0 commit comments

Comments
 (0)