Skip to content
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

Rollup of 9 pull requests #88584

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
af1b65c
Path remapping: Make behavior of diagnostics output dependent on pres…
michaelwoerister Aug 26, 2021
8436fe1
Add test for showing remapped path in diagnostics
cbeuw Aug 20, 2021
c296c89
Fix remap-path-prefix UI test case.
michaelwoerister Aug 27, 2021
c6d800d
Point at unclosed delimiters as part of the primary MultiSpan
estebank Aug 27, 2021
d7da82a
expand: Treat more macro calls as statement macro calls
petrochenkov Aug 26, 2021
b99038f
use `unwrap_unchecked` where possible
ibraheemdev Aug 30, 2021
99a3d64
Remove single use variables
ptrojahn Aug 31, 2021
ffc43b8
add safety annotation to `LinkedList::detach_all_nodes`
ibraheemdev Aug 31, 2021
7189c85
Improve closure dummy capture suggestion in macros.
m-ou-se Aug 31, 2021
7d18052
Add test for closure migration where body is a block fragment.
m-ou-se Aug 31, 2021
59b245e
fix(rustc_lint): better detect when parens are necessary
notriddle Aug 31, 2021
6c9e708
`fmt::Formatter::pad`: don't call chars().count() more than one time
klensy Sep 1, 2021
f5f489b
fix clippy lints
klensy Sep 1, 2021
a5fd955
add regression test for issue 83190
lqd Sep 1, 2021
d9047db
Rollup merge of #88363 - michaelwoerister:remapped-diagnostics, r=est…
GuillaumeGomez Sep 2, 2021
2693e12
Rollup merge of #88386 - estebank:unmatched-delims, r=jackh726
GuillaumeGomez Sep 2, 2021
2f22cad
Rollup merge of #88428 - petrochenkov:stmtid, r=Aaron1011
GuillaumeGomez Sep 2, 2021
c892775
Rollup merge of #88505 - ibraheemdev:use-unwrap-unchecked, r=kennytm
GuillaumeGomez Sep 2, 2021
1d1e931
Rollup merge of #88532 - ptrojahn:single_use, r=davidtwco
GuillaumeGomez Sep 2, 2021
b341e56
Rollup merge of #88543 - m-ou-se:closure-migration-macro-block-fragme…
GuillaumeGomez Sep 2, 2021
60eb925
Rollup merge of #88547 - notriddle:notriddle/is-expr-delims-necessary…
GuillaumeGomez Sep 2, 2021
a90fff6
Rollup merge of #88560 - klensy:formatter-pad-shrink, r=m-ou-se
GuillaumeGomez Sep 2, 2021
7e3855b
Rollup merge of #88565 - lqd:issue-83190, r=spastorino
GuillaumeGomez Sep 2, 2021
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
Prev Previous commit
Next Next commit
Point at unclosed delimiters as part of the primary MultiSpan
Both the place where the parser encounters a needed closed delimiter and
the unclosed opening delimiter are important, so they should get the
same level of highlighting in the output.
  • Loading branch information
estebank committed Aug 27, 2021
commit c6d800d85439d0a95a2943905d0fd3842fa4dd20
12 changes: 11 additions & 1 deletion compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1432,12 +1432,22 @@ impl<'a> Parser<'a> {
// the most sense, which is immediately after the last token:
//
// {foo(bar {}}
// - ^
// ^ ^
// | |
// | help: `)` may belong here
// |
// unclosed delimiter
if let Some(sp) = unmatched.unclosed_span {
let mut primary_span: Vec<Span> =
err.span.primary_spans().iter().cloned().collect();
primary_span.push(sp);
let mut primary_span: MultiSpan = primary_span.into();
for span_label in err.span.span_labels() {
if let Some(label) = span_label.label {
primary_span.push_span_label(span_label.span, label);
}
}
err.set_span(primary_span);
err.span_label(sp, "unclosed delimiter");
}
// Backticks should be removed to apply suggestions.
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use rustc_data_structures::sync::Lrc;
use rustc_errors::PResult;
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, FatalError};
use rustc_session::parse::ParseSess;
use rustc_span::source_map::{Span, DUMMY_SP};
use rustc_span::source_map::{MultiSpan, Span, DUMMY_SP};
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use tracing::debug;

Expand Down Expand Up @@ -1335,8 +1335,13 @@ crate fn make_unclosed_delims_error(
// `None` here means an `Eof` was found. We already emit those errors elsewhere, we add them to
// `unmatched_braces` only for error recovery in the `Parser`.
let found_delim = unmatched.found_delim?;
let span: MultiSpan = if let Some(sp) = unmatched.unclosed_span {
vec![unmatched.found_span, sp].into()
} else {
unmatched.found_span.into()
};
let mut err = sess.span_diagnostic.struct_span_err(
unmatched.found_span,
span,
&format!(
"mismatched closing delimiter: `{}`",
pprust::token_kind_to_string(&token::CloseDelim(found_delim)),
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/parser/issue-10636-1.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: mismatched closing delimiter: `)`
--> $DIR/issue-10636-1.rs:4:1
--> $DIR/issue-10636-1.rs:1:12
|
LL | struct Obj {
| - unclosed delimiter
| ^ unclosed delimiter
...
LL | )
| ^ mismatched closing delimiter
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/parser/issue-10636-2.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: expected one of `)`, `,`, `.`, `?`, or an operator, found `;`
--> $DIR/issue-10636-2.rs:5:25
--> $DIR/issue-10636-2.rs:5:15
|
LL | option.map(|some| 42;
| - ^ help: `)` may belong here
| ^ ^ help: `)` may belong here
| |
| unclosed delimiter

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/parser/issue-58856-1.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: expected one of `)`, `,`, or `:`, found `>`
--> $DIR/issue-58856-1.rs:3:14
--> $DIR/issue-58856-1.rs:3:9
|
LL | fn b(self>
| - ^ help: `)` may belong here
| ^ ^ help: `)` may belong here
| |
| unclosed delimiter

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/parser/issue-58856-2.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: expected one of `)` or `,`, found `->`
--> $DIR/issue-58856-2.rs:6:26
--> $DIR/issue-58856-2.rs:6:19
|
LL | fn how_are_you(&self -> Empty {
| - -^^
| ^ -^^
| | |
| | help: `)` may belong here
| unclosed delimiter
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/parser/issue-60075.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ LL | }
| - item list ends here

error: mismatched closing delimiter: `)`
--> $DIR/issue-60075.rs:6:10
--> $DIR/issue-60075.rs:4:31
|
LL | fn qux() -> Option<usize> {
| - unclosed delimiter
| ^ unclosed delimiter
LL | let _ = if true {
LL | });
| ^ mismatched closing delimiter
Expand Down
12 changes: 6 additions & 6 deletions src/test/ui/parser/issue-62973.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ LL |
| ^

error: expected one of `,` or `}`, found `{`
--> $DIR/issue-62973.rs:6:25
--> $DIR/issue-62973.rs:6:8
|
LL | fn p() { match s { v, E { [) {) }
| - - -^ expected one of `,` or `}`
| ^ - -^ expected one of `,` or `}`
| | | |
| | | help: `}` may belong here
| | while parsing this struct
Expand Down Expand Up @@ -56,18 +56,18 @@ LL |
| ^ expected one of `.`, `?`, `{`, or an operator

error: mismatched closing delimiter: `)`
--> $DIR/issue-62973.rs:6:28
--> $DIR/issue-62973.rs:6:27
|
LL | fn p() { match s { v, E { [) {) }
| -^ mismatched closing delimiter
| ^^ mismatched closing delimiter
| |
| unclosed delimiter

error: mismatched closing delimiter: `)`
--> $DIR/issue-62973.rs:6:31
--> $DIR/issue-62973.rs:6:30
|
LL | fn p() { match s { v, E { [) {) }
| -^ mismatched closing delimiter
| ^^ mismatched closing delimiter
| |
| unclosed delimiter

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/parser/issue-63116.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ LL | impl W <s(f;Y(;]
| ^ expected one of 7 possible tokens

error: mismatched closing delimiter: `]`
--> $DIR/issue-63116.rs:3:16
--> $DIR/issue-63116.rs:3:14
|
LL | impl W <s(f;Y(;]
| - ^ mismatched closing delimiter
| ^ ^ mismatched closing delimiter
| |
| unclosed delimiter

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/parser/issue-66357-unexpected-unreachable.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ LL | fn f() { |[](* }
| ^ expected one of `,` or `:`

error: expected one of `&`, `(`, `)`, `-`, `...`, `..=`, `..`, `[`, `_`, `box`, `mut`, `ref`, `|`, identifier, or path, found `*`
--> $DIR/issue-66357-unexpected-unreachable.rs:12:14
--> $DIR/issue-66357-unexpected-unreachable.rs:12:13
|
LL | fn f() { |[](* }
| -^ help: `)` may belong here
| ^^ help: `)` may belong here
| |
| unclosed delimiter

Expand Down
Original file line number Diff line number Diff line change
@@ -1,107 +1,107 @@
error: mismatched closing delimiter: `]`
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:5:42
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:5:27
|
LL | V = [PhantomData; { [ () ].len() ].len() as isize,
| - - ^ mismatched closing delimiter
| - ^ ^ mismatched closing delimiter
| | |
| | unclosed delimiter
| closing delimiter possibly meant for this

error: mismatched closing delimiter: `]`
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:15:36
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:15:24
|
LL | V = [Vec::new; { [].len() ].len() as isize,
| - - ^ mismatched closing delimiter
| - ^ ^ mismatched closing delimiter
| | |
| | unclosed delimiter
| closing delimiter possibly meant for this

error: mismatched closing delimiter: `]`
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:26:36
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:26:24
|
LL | V = [Vec::new; { [0].len() ].len() as isize,
| - - ^ mismatched closing delimiter
| - ^ ^ mismatched closing delimiter
| | |
| | unclosed delimiter
| closing delimiter possibly meant for this

error: mismatched closing delimiter: `]`
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:5:42
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:5:27
|
LL | V = [PhantomData; { [ () ].len() ].len() as isize,
| - - ^ mismatched closing delimiter
| - ^ ^ mismatched closing delimiter
| | |
| | unclosed delimiter
| closing delimiter possibly meant for this

error: mismatched closing delimiter: `]`
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:15:36
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:15:24
|
LL | V = [Vec::new; { [].len() ].len() as isize,
| - - ^ mismatched closing delimiter
| - ^ ^ mismatched closing delimiter
| | |
| | unclosed delimiter
| closing delimiter possibly meant for this

error: mismatched closing delimiter: `]`
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:26:36
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:26:24
|
LL | V = [Vec::new; { [0].len() ].len() as isize,
| - - ^ mismatched closing delimiter
| - ^ ^ mismatched closing delimiter
| | |
| | unclosed delimiter
| closing delimiter possibly meant for this

error: mismatched closing delimiter: `]`
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:5:42
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:5:27
|
LL | V = [PhantomData; { [ () ].len() ].len() as isize,
| - - ^ mismatched closing delimiter
| - ^ ^ mismatched closing delimiter
| | |
| | unclosed delimiter
| closing delimiter possibly meant for this

error: mismatched closing delimiter: `]`
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:15:36
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:15:24
|
LL | V = [Vec::new; { [].len() ].len() as isize,
| - - ^ mismatched closing delimiter
| - ^ ^ mismatched closing delimiter
| | |
| | unclosed delimiter
| closing delimiter possibly meant for this

error: mismatched closing delimiter: `]`
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:26:36
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:26:24
|
LL | V = [Vec::new; { [0].len() ].len() as isize,
| - - ^ mismatched closing delimiter
| - ^ ^ mismatched closing delimiter
| | |
| | unclosed delimiter
| closing delimiter possibly meant for this

error: mismatched closing delimiter: `]`
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:5:42
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:5:27
|
LL | V = [PhantomData; { [ () ].len() ].len() as isize,
| - - ^ mismatched closing delimiter
| - ^ ^ mismatched closing delimiter
| | |
| | unclosed delimiter
| closing delimiter possibly meant for this

error: mismatched closing delimiter: `]`
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:15:36
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:15:24
|
LL | V = [Vec::new; { [].len() ].len() as isize,
| - - ^ mismatched closing delimiter
| - ^ ^ mismatched closing delimiter
| | |
| | unclosed delimiter
| closing delimiter possibly meant for this

error: mismatched closing delimiter: `]`
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:26:36
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:26:24
|
LL | V = [Vec::new; { [0].len() ].len() as isize,
| - - ^ mismatched closing delimiter
| - ^ ^ mismatched closing delimiter
| | |
| | unclosed delimiter
| closing delimiter possibly meant for this
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/parser/macro-mismatched-delim-brace-paren.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: mismatched closing delimiter: `)`
--> $DIR/macro-mismatched-delim-brace-paren.rs:6:5
--> $DIR/macro-mismatched-delim-brace-paren.rs:4:10
|
LL | foo! {
| - unclosed delimiter
| ^ unclosed delimiter
LL | bar, "baz", 1, 2.0
LL | )
| ^ mismatched closing delimiter
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/parser/macro-mismatched-delim-paren-brace.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ LL | }
| ^ unexpected closing delimiter

error: mismatched closing delimiter: `}`
--> $DIR/macro-mismatched-delim-paren-brace.rs:4:5
--> $DIR/macro-mismatched-delim-paren-brace.rs:2:10
|
LL | foo! (
| - unclosed delimiter
| ^ unclosed delimiter
LL | bar, "baz", 1, 2.0
LL | }
| ^ mismatched closing delimiter
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/parser/parser-recovery-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ LL | let x = y.;
| ^

error: mismatched closing delimiter: `)`
--> $DIR/parser-recovery-2.rs:6:5
--> $DIR/parser-recovery-2.rs:4:14
|
LL | fn bar() {
| - unclosed delimiter
| ^ unclosed delimiter
LL | let x = foo();
LL | )
| ^ mismatched closing delimiter
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/parser/unclosed-delimiter-in-dep.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error: mismatched closing delimiter: `}`
--> $DIR/unclosed_delim_mod.rs:7:1
--> $DIR/unclosed_delim_mod.rs:5:7
|
LL | pub fn new() -> Result<Value, ()> {
| - closing delimiter possibly meant for this
LL | Ok(Value {
| - unclosed delimiter
| ^ unclosed delimiter
LL | }
LL | }
| ^ mismatched closing delimiter
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/parser/unclosed_delim_mod.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error: mismatched closing delimiter: `}`
--> $DIR/unclosed_delim_mod.rs:7:1
--> $DIR/unclosed_delim_mod.rs:5:7
|
LL | pub fn new() -> Result<Value, ()> {
| - closing delimiter possibly meant for this
LL | Ok(Value {
| - unclosed delimiter
| ^ unclosed delimiter
LL | }
LL | }
| ^ mismatched closing delimiter
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/parser/use-unclosed-brace.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ LL | fn main() {}
| ^

error: expected one of `,`, `::`, `as`, or `}`, found `;`
--> $DIR/use-unclosed-brace.rs:4:19
--> $DIR/use-unclosed-brace.rs:4:10
|
LL | use foo::{bar, baz;
| - ^
| ^ ^
| | |
| | expected one of `,`, `::`, `as`, or `}`
| | help: `}` may belong here
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/resolve/token-error-correct-2.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: mismatched closing delimiter: `)`
--> $DIR/token-error-correct-2.rs:6:5
--> $DIR/token-error-correct-2.rs:4:12
|
LL | if foo {
| - unclosed delimiter
| ^ unclosed delimiter
LL |
LL | )
| ^ mismatched closing delimiter
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/resolve/token-error-correct-3.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: expected one of `)`, `,`, `.`, `?`, or an operator, found `;`
--> $DIR/token-error-correct-3.rs:13:35
--> $DIR/token-error-correct-3.rs:13:21
|
LL | callback(path.as_ref();
| - ^ help: `)` may belong here
| ^ ^ help: `)` may belong here
| |
| unclosed delimiter

Expand Down
Loading