Skip to content

Rollup of 10 pull requests #106250

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

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d310292
cargo-miri: use rustc to determine the output filename
RalfJung Dec 27, 2022
ca1e861
Auto merge of #2741 - RalfJung:filenames, r=RalfJung
bors Dec 27, 2022
7bdb5da
handle unknown targets more gracefully
RalfJung Dec 27, 2022
fbdf926
Auto merge of #2742 - RalfJung:targets, r=RalfJung
bors Dec 28, 2022
041ad1f
simplify path joining code a bit
RalfJung Dec 28, 2022
fba3d79
Auto merge of #2743 - RalfJung:path-join, r=RalfJung
bors Dec 28, 2022
874cefa
Powershell: Use `WaitForExit` instead of `-Wait`
ChrisDenton Dec 28, 2022
c3eb202
Migrate scraped examples higlight CSS to variables
GuillaumeGomez Dec 28, 2022
aa20f88
Add GUI test for scraped examples colors
GuillaumeGomez Dec 28, 2022
4fa5192
print sysroot build failure error
RalfJung Dec 28, 2022
fbd6a69
bump dependencies
RalfJung Dec 28, 2022
40d65f0
test using a JSON target file
RalfJung Dec 28, 2022
dfe1898
no need to do a no_std build for wasi
RalfJung Dec 28, 2022
be3ed4f
Auto merge of #2744 - RalfJung:json, r=RalfJung
bors Dec 28, 2022
9221e43
rustdoc: remove unnecessary `.tooltip::after { text-align: center }`
notriddle Dec 28, 2022
9067e44
Rename `Rptr` to `Ref` in AST and HIR
Noratrieb Dec 28, 2022
120d4fd
Remove CraftSpider from review rotation
ehuss Dec 28, 2022
01d7841
Make trait/impl where clause mismatch on region error a bit more acti…
compiler-errors Dec 28, 2022
992ba80
Add test for bad suggestion
compiler-errors Dec 28, 2022
6e794dc
Address review comments
compiler-errors Dec 28, 2022
36e2910
Account for multiple multiline spans with empty padding
estebank Dec 27, 2022
083eb93
On unsized locals with explicit types suggest `&`
estebank Dec 28, 2022
96501bd
Powershell: Create a `Start-Process` wrapper
ChrisDenton Dec 28, 2022
3487fe3
update lockfile
RalfJung Dec 28, 2022
375f025
Detect diff markers in the parser
estebank Dec 29, 2022
38fd5a9
Account for ADT bodies and struct expressions
estebank Dec 29, 2022
698ebe3
Tweak wording
estebank Dec 29, 2022
62c8e31
Add support for diff3 format
estebank Dec 29, 2022
0f86c76
Rollup merge of #106190 - estebank:multiline-start-tweak, r=jackh726
matthiaskrgr Dec 29, 2022
f9fab1f
Rollup merge of #106208 - compiler-errors:compare-item-region-err, r=…
matthiaskrgr Dec 29, 2022
801093f
Rollup merge of #106216 - ChrisDenton:ps-go-faster, r=jyn514
matthiaskrgr Dec 29, 2022
8875ac9
Rollup merge of #106217 - notriddle:notriddle/tooltip-center, r=Guill…
matthiaskrgr Dec 29, 2022
fc5ee6b
Rollup merge of #106218 - GuillaumeGomez:migrate-css-var-scraped-exam…
matthiaskrgr Dec 29, 2022
499055c
Rollup merge of #106221 - Nilstrieb:rptr-more-like-ref-actually, r=co…
matthiaskrgr Dec 29, 2022
77766d5
Rollup merge of #106223 - estebank:suggest-let-ty-borrow, r=compiler-…
matthiaskrgr Dec 29, 2022
58d183e
Rollup merge of #106225 - ehuss:ehuss-patch-1, r=GuillaumeGomez
matthiaskrgr Dec 29, 2022
94dde96
Rollup merge of #106229 - RalfJung:miri, r=RalfJung
matthiaskrgr Dec 29, 2022
160544c
Rollup merge of #106242 - estebank:diff-markers, r=jyn514
matthiaskrgr Dec 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 71 additions & 1 deletion compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ use rustc_ast::{
use rustc_ast_pretty::pprust;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{
fluent, Applicability, DiagnosticBuilder, DiagnosticMessage, Handler, MultiSpan, PResult,
fluent, Applicability, DiagnosticBuilder, DiagnosticMessage, FatalError, Handler, MultiSpan,
PResult,
};
use rustc_errors::{pluralize, Diagnostic, ErrorGuaranteed, IntoDiagnostic};
use rustc_session::errors::ExprParenthesesNeeded;
Expand Down Expand Up @@ -2556,6 +2557,75 @@ impl<'a> Parser<'a> {
Ok(())
}

pub fn is_diff_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) {
let lo = self.token.span;
for _ in 0..4 {
self.bump();
}
return Some(lo.to(self.prev_token.span));
}
None
}

pub fn recover_diff_marker(&mut self) {
let Some(start) = self.diff_marker(&TokenKind::BinOp(token::Shl), &TokenKind::Lt) else {
return;
};
let mut spans = Vec::with_capacity(3);
spans.push(start);
let mut middlediff3 = None;
let mut middle = None;
let mut end = None;
loop {
if self.token.kind == TokenKind::Eof {
break;
}
if let Some(span) = self.diff_marker(&TokenKind::OrOr, &TokenKind::BinOp(token::Or)) {
middlediff3 = Some(span);
}
if let Some(span) = self.diff_marker(&TokenKind::EqEq, &TokenKind::Eq) {
middle = Some(span);
}
if let Some(span) = self.diff_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");
if let Some(middle) = middlediff3 {
err.span_label(middle, "");
}
if let Some(middle) = middle {
err.span_label(middle, "");
}
if let Some(end) = end {
err.span_label(end, "above this are the incoming code changes");
}
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",
);
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",
);
err.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>",
);
err.emit();
FatalError.raise()
}

/// Parse and throw away a parenthesized comma separated
/// sequence of patterns until `)` is reached.
fn skip_pat_list(&mut self) -> PResult<'a, ()> {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3039,6 +3039,7 @@ impl<'a> Parser<'a> {
/// Parses `ident (COLON expr)?`.
fn parse_expr_field(&mut self) -> PResult<'a, ExprField> {
let attrs = self.parse_outer_attributes()?;
self.recover_diff_marker();
self.collect_tokens_trailing_token(attrs, ForceCollect::No, |this, attrs| {
let lo = this.token.span;

Expand Down
42 changes: 38 additions & 4 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ impl<'a> Parser<'a> {
fn_parse_mode: FnParseMode,
force_collect: ForceCollect,
) -> PResult<'a, Option<Item>> {
self.recover_diff_marker();
let attrs = self.parse_outer_attributes()?;
self.recover_diff_marker();
self.parse_item_common(attrs, true, false, fn_parse_mode, force_collect)
}

Expand Down Expand Up @@ -704,6 +706,7 @@ impl<'a> Parser<'a> {
if self.recover_doc_comment_before_brace() {
continue;
}
self.recover_diff_marker();
match parse_item(self) {
Ok(None) => {
let mut is_unnecessary_semicolon = !items.is_empty()
Expand Down Expand Up @@ -1039,8 +1042,11 @@ impl<'a> Parser<'a> {
/// USE_TREE_LIST = Ø | (USE_TREE `,`)* USE_TREE [`,`]
/// ```
fn parse_use_tree_list(&mut self) -> PResult<'a, Vec<(UseTree, ast::NodeId)>> {
self.parse_delim_comma_seq(Delimiter::Brace, |p| Ok((p.parse_use_tree()?, DUMMY_NODE_ID)))
.map(|(r, _)| r)
self.parse_delim_comma_seq(Delimiter::Brace, |p| {
p.recover_diff_marker();
Ok((p.parse_use_tree()?, DUMMY_NODE_ID))
})
.map(|(r, _)| r)
}

fn parse_rename(&mut self) -> PResult<'a, Option<Ident>> {
Expand Down Expand Up @@ -1379,7 +1385,9 @@ impl<'a> Parser<'a> {
}

fn parse_enum_variant(&mut self) -> PResult<'a, Option<Variant>> {
self.recover_diff_marker();
let variant_attrs = self.parse_outer_attributes()?;
self.recover_diff_marker();
self.collect_tokens_trailing_token(
variant_attrs,
ForceCollect::No,
Expand Down Expand Up @@ -1573,9 +1581,32 @@ impl<'a> Parser<'a> {
self.parse_paren_comma_seq(|p| {
let attrs = p.parse_outer_attributes()?;
p.collect_tokens_trailing_token(attrs, ForceCollect::No, |p, attrs| {
let mut snapshot = None;
if p.is_diff_marker(&TokenKind::BinOp(token::Shl), &TokenKind::Lt) {
// Account for `<<<<<<<` diff markers. We can't proactively error here because
// that can be a valid type start, so we snapshot and reparse only we've
// encountered another parse error.
snapshot = Some(p.create_snapshot_for_diagnostic());
}
let lo = p.token.span;
let vis = p.parse_visibility(FollowedByType::Yes)?;
let ty = p.parse_ty()?;
let vis = match p.parse_visibility(FollowedByType::Yes) {
Ok(vis) => vis,
Err(err) => {
if let Some(ref mut snapshot) = snapshot {
snapshot.recover_diff_marker();
}
return Err(err);
}
};
let ty = match p.parse_ty() {
Ok(ty) => ty,
Err(err) => {
if let Some(ref mut snapshot) = snapshot {
snapshot.recover_diff_marker();
}
return Err(err);
}
};

Ok((
FieldDef {
Expand All @@ -1596,7 +1627,9 @@ impl<'a> Parser<'a> {

/// Parses an element of a struct declaration.
fn parse_field_def(&mut self, adt_ty: &str) -> PResult<'a, FieldDef> {
self.recover_diff_marker();
let attrs = self.parse_outer_attributes()?;
self.recover_diff_marker();
self.collect_tokens_trailing_token(attrs, ForceCollect::No, |this, attrs| {
let lo = this.token.span;
let vis = this.parse_visibility(FollowedByType::No)?;
Expand Down Expand Up @@ -2427,6 +2460,7 @@ impl<'a> Parser<'a> {
let mut first_param = true;
// Parse the arguments, starting out with `self` being allowed...
let (mut params, _) = self.parse_paren_comma_seq(|p| {
p.recover_diff_marker();
let param = p.parse_param_general(req_name, first_param).or_else(|mut e| {
e.emit();
let lo = p.prev_token.span;
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_parse/src/parser/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,13 +531,23 @@ impl<'a> Parser<'a> {
recover: AttemptLocalParseRecovery,
) -> PResult<'a, P<Block>> {
let mut stmts = vec![];
let mut snapshot = None;
while !self.eat(&token::CloseDelim(Delimiter::Brace)) {
if self.token == token::Eof {
break;
}
if self.is_diff_marker(&TokenKind::BinOp(token::Shl), &TokenKind::Lt) {
// Account for `<<<<<<<` diff markers. We can't proactively error here because
// that can be a valid path start, so we snapshot and reparse only we've
// encountered another parse error.
snapshot = Some(self.create_snapshot_for_diagnostic());
}
let stmt = match self.parse_full_stmt(recover) {
Err(mut err) if recover.yes() => {
self.maybe_annotate_with_ascription(&mut err, false);
if let Some(ref mut snapshot) = snapshot {
snapshot.recover_diff_marker();
}
err.emit();
self.recover_stmt_(SemiColonMode::Ignore, BlockMode::Ignore);
Some(self.mk_stmt_err(self.token.span))
Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/parser/diff-markers/enum-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
enum E {
Foo {
<<<<<<< HEAD //~ ERROR encountered diff marker
x: u8,
|||||||
z: (),
=======
y: i8,
>>>>>>> branch
}
}
21 changes: 21 additions & 0 deletions src/test/ui/parser/diff-markers/enum-2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
error: encountered diff marker
--> $DIR/enum-2.rs:3:1
|
LL | <<<<<<< HEAD
| ^^^^^^^ after this is the code before the merge
LL | x: u8,
LL | |||||||
| -------
LL | z: (),
LL | =======
| -------
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>

error: aborting due to previous error

7 changes: 7 additions & 0 deletions src/test/ui/parser/diff-markers/enum.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enum E {
<<<<<<< HEAD //~ ERROR encountered diff marker
Foo(u8),
=======
Bar(i8),
>>>>>>> branch
}
18 changes: 18 additions & 0 deletions src/test/ui/parser/diff-markers/enum.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error: encountered diff marker
--> $DIR/enum.rs:2:1
|
LL | <<<<<<< HEAD
| ^^^^^^^ after this is the code before the merge
LL | Foo(u8),
LL | =======
| -------
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>

error: aborting due to previous error

16 changes: 16 additions & 0 deletions src/test/ui/parser/diff-markers/fn-arg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
trait T {
fn foo(
<<<<<<< HEAD //~ ERROR encountered diff marker
x: u8,
=======
x: i8,
>>>>>>> branch
) {}
}

struct S;
impl T for S {}

fn main() {
S::foo(42);
}
18 changes: 18 additions & 0 deletions src/test/ui/parser/diff-markers/fn-arg.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error: encountered diff marker
--> $DIR/fn-arg.rs:3:1
|
LL | <<<<<<< HEAD
| ^^^^^^^ after this is the code before the merge
LL | x: u8,
LL | =======
| -------
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>

error: aborting due to previous error

10 changes: 10 additions & 0 deletions src/test/ui/parser/diff-markers/item-with-attr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#[attribute]
<<<<<<< HEAD //~ ERROR encountered diff marker
fn foo() {}
=======
fn bar() {}
>>>>>>> branch

fn main() {
foo();
}
18 changes: 18 additions & 0 deletions src/test/ui/parser/diff-markers/item-with-attr.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error: encountered diff marker
--> $DIR/item-with-attr.rs:2:1
|
LL | <<<<<<< HEAD
| ^^^^^^^ after this is the code before the merge
LL | fn foo() {}
LL | =======
| -------
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>

error: aborting due to previous error

9 changes: 9 additions & 0 deletions src/test/ui/parser/diff-markers/item.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<<<<<<< HEAD //~ ERROR encountered diff marker
fn foo() {}
=======
fn bar() {}
>>>>>>> branch

fn main() {
foo();
}
18 changes: 18 additions & 0 deletions src/test/ui/parser/diff-markers/item.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error: encountered diff marker
--> $DIR/item.rs:1:1
|
LL | <<<<<<< HEAD
| ^^^^^^^ after this is the code before the merge
LL | fn foo() {}
LL | =======
| -------
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>

error: aborting due to previous error

15 changes: 15 additions & 0 deletions src/test/ui/parser/diff-markers/statement.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
trait T {
fn foo() {}
fn bar() {}
}

struct S;
impl T for S {}

fn main() {
<<<<<<< HEAD //~ ERROR encountered diff marker
S::foo();
=======
S::bar();
>>>>>>> branch
}
Loading