Skip to content

Commit 65ad5f8

Browse files
committedFeb 28, 2023
remove duplicated diagnostic for unclosed delimiter
1 parent f01d0c0 commit 65ad5f8

21 files changed

+82
-313
lines changed
 

‎compiler/rustc_parse/src/lexer/tokentrees.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl<'a> TokenTreesReader<'a> {
3434
let mut buf = Vec::new();
3535
loop {
3636
match self.token.kind {
37-
token::OpenDelim(delim) => buf.push(self.parse_token_tree_open_delim(delim)),
37+
token::OpenDelim(delim) => buf.push(self.parse_token_tree_open_delim(delim)?),
3838
token::CloseDelim(delim) => {
3939
return if is_delimited {
4040
Ok(TokenStream::new(buf))
@@ -43,10 +43,11 @@ impl<'a> TokenTreesReader<'a> {
4343
};
4444
}
4545
token::Eof => {
46-
if is_delimited {
47-
self.eof_err().emit();
48-
}
49-
return Ok(TokenStream::new(buf));
46+
return if is_delimited {
47+
Err(self.eof_err())
48+
} else {
49+
Ok(TokenStream::new(buf))
50+
};
5051
}
5152
_ => {
5253
// Get the next normal token. This might require getting multiple adjacent
@@ -98,7 +99,7 @@ impl<'a> TokenTreesReader<'a> {
9899
err
99100
}
100101

101-
fn parse_token_tree_open_delim(&mut self, open_delim: Delimiter) -> TokenTree {
102+
fn parse_token_tree_open_delim(&mut self, open_delim: Delimiter) -> PResult<'a, TokenTree> {
102103
// The span for beginning of the delimited section
103104
let pre_span = self.token.span;
104105

@@ -107,7 +108,7 @@ impl<'a> TokenTreesReader<'a> {
107108
// Parse the token trees within the delimiters.
108109
// We stop at any delimiter so we can try to recover if the user
109110
// uses an incorrect delimiter.
110-
let tts = self.parse_token_trees(/* is_delimited */ true).unwrap();
111+
let tts = self.parse_token_trees(/* is_delimited */ true)?;
111112

112113
// Expand to cover the entire delimited token tree
113114
let delim_span = DelimSpan::from_pair(pre_span, self.token.span);
@@ -190,7 +191,7 @@ impl<'a> TokenTreesReader<'a> {
190191
_ => unreachable!(),
191192
}
192193

193-
TokenTree::Delimited(delim_span, open_delim, tts)
194+
Ok(TokenTree::Delimited(delim_span, open_delim, tts))
194195
}
195196

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

‎tests/ui/lint/issue-104897.stderr

+1-21
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,5 @@ LL | fn f(){(print!(á
88
| |unclosed delimiter
99
| unclosed delimiter
1010

11-
error: this file contains an unclosed delimiter
12-
--> $DIR/issue-104897.rs:5:18
13-
|
14-
LL | fn f(){(print!(á
15-
| -- - ^
16-
| || |
17-
| || unclosed delimiter
18-
| |unclosed delimiter
19-
| unclosed delimiter
20-
21-
error: this file contains an unclosed delimiter
22-
--> $DIR/issue-104897.rs:5:18
23-
|
24-
LL | fn f(){(print!(á
25-
| -- - ^
26-
| || |
27-
| || unclosed delimiter
28-
| |unclosed delimiter
29-
| unclosed delimiter
30-
31-
error: aborting due to 3 previous errors
11+
error: aborting due to previous error
3212

‎tests/ui/lint/unused_parens_multibyte_recovery.stderr

+1-21
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,5 @@ LL | fn f(){(print!(á
88
| |unclosed delimiter
99
| unclosed delimiter
1010

11-
error: this file contains an unclosed delimiter
12-
--> $DIR/unused_parens_multibyte_recovery.rs:10:17
13-
|
14-
LL | fn f(){(print!(á
15-
| -- - ^
16-
| || |
17-
| || unclosed delimiter
18-
| |unclosed delimiter
19-
| unclosed delimiter
20-
21-
error: this file contains an unclosed delimiter
22-
--> $DIR/unused_parens_multibyte_recovery.rs:10:17
23-
|
24-
LL | fn f(){(print!(á
25-
| -- - ^
26-
| || |
27-
| || unclosed delimiter
28-
| |unclosed delimiter
29-
| unclosed delimiter
30-
31-
error: aborting due to 3 previous errors
11+
error: aborting due to previous error
3212

‎tests/ui/malformed/issue-107423-unused-delim-only-one-no-pair.stderr

+1-21
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,5 @@ LL | fn a(){{{
88
| |unclosed delimiter
99
| unclosed delimiter
1010

11-
error: this file contains an unclosed delimiter
12-
--> $DIR/issue-107423-unused-delim-only-one-no-pair.rs:7:11
13-
|
14-
LL | fn a(){{{
15-
| --- ^
16-
| |||
17-
| ||unclosed delimiter
18-
| |unclosed delimiter
19-
| unclosed delimiter
20-
21-
error: this file contains an unclosed delimiter
22-
--> $DIR/issue-107423-unused-delim-only-one-no-pair.rs:7:11
23-
|
24-
LL | fn a(){{{
25-
| --- ^
26-
| |||
27-
| ||unclosed delimiter
28-
| |unclosed delimiter
29-
| unclosed delimiter
30-
31-
error: aborting due to 3 previous errors
11+
error: aborting due to previous error
3212

‎tests/ui/parser/issue-103451.stderr

+1-11
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,5 @@ LL | x: [u8; R
88
| |
99
| unclosed delimiter
1010

11-
error: this file contains an unclosed delimiter
12-
--> $DIR/issue-103451.rs:4:15
13-
|
14-
LL | struct S {
15-
| - unclosed delimiter
16-
LL | x: [u8; R
17-
| - ^
18-
| |
19-
| unclosed delimiter
20-
21-
error: aborting due to 2 previous errors
11+
error: aborting due to previous error
2212

‎tests/ui/parser/issue-81804.stderr

+6-15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
error: this file contains an unclosed delimiter
2-
--> $DIR/issue-81804.rs:6:11
1+
error: mismatched closing delimiter: `}`
2+
--> $DIR/issue-81804.rs:6:8
33
|
44
LL | fn p([=(}
5-
| -- ^
6-
| ||
7-
| |unclosed delimiter
8-
| unclosed delimiter
5+
| ^^ mismatched closing delimiter
6+
| |
7+
| unclosed delimiter
98

109
error: this file contains an unclosed delimiter
1110
--> $DIR/issue-81804.rs:6:11
@@ -16,13 +15,5 @@ LL | fn p([=(}
1615
| |unclosed delimiter
1716
| unclosed delimiter
1817

19-
error: mismatched closing delimiter: `}`
20-
--> $DIR/issue-81804.rs:6:8
21-
|
22-
LL | fn p([=(}
23-
| ^^ mismatched closing delimiter
24-
| |
25-
| unclosed delimiter
26-
27-
error: aborting due to 3 previous errors
18+
error: aborting due to 2 previous errors
2819

‎tests/ui/parser/issue-81827.stderr

+7-17
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
error: this file contains an unclosed delimiter
2-
--> $DIR/issue-81827.rs:10:27
1+
error: mismatched closing delimiter: `]`
2+
--> $DIR/issue-81827.rs:10:23
33
|
44
LL | fn r()->i{0|{#[cfg(r(0{]0
5-
| - - - ^
6-
| | | |
7-
| | | missing open `[` for this delimiter
8-
| | unclosed delimiter
9-
| unclosed delimiter
5+
| - ^^ mismatched closing delimiter
6+
| | |
7+
| | unclosed delimiter
8+
| closing delimiter possibly meant for this
109

1110
error: this file contains an unclosed delimiter
1211
--> $DIR/issue-81827.rs:10:27
@@ -18,14 +17,5 @@ LL | fn r()->i{0|{#[cfg(r(0{]0
1817
| | unclosed delimiter
1918
| unclosed delimiter
2019

21-
error: mismatched closing delimiter: `]`
22-
--> $DIR/issue-81827.rs:10:23
23-
|
24-
LL | fn r()->i{0|{#[cfg(r(0{]0
25-
| - ^^ mismatched closing delimiter
26-
| | |
27-
| | unclosed delimiter
28-
| closing delimiter possibly meant for this
29-
30-
error: aborting due to 3 previous errors
20+
error: aborting due to 2 previous errors
3121

‎tests/ui/parser/issues/issue-62554.stderr

+1-45
Original file line numberDiff line numberDiff line change
@@ -9,49 +9,5 @@ LL | fn foo(u: u8) { if u8 macro_rules! u8 { (u6) => { fn uuuuuuuuuuu() { use s
99
| | | unclosed delimiter
1010
| unclosed delimiter unclosed delimiter
1111

12-
error: this file contains an unclosed delimiter
13-
--> $DIR/issue-62554.rs:5:89
14-
|
15-
LL | fn foo(u: u8) { if u8 macro_rules! u8 { (u6) => { fn uuuuuuuuuuu() { use s loo mod u8 {
16-
| - - - - - ^
17-
| | | | | |
18-
| | | | | unclosed delimiter
19-
| | | | unclosed delimiter
20-
| | | unclosed delimiter
21-
| unclosed delimiter unclosed delimiter
22-
23-
error: this file contains an unclosed delimiter
24-
--> $DIR/issue-62554.rs:5:89
25-
|
26-
LL | fn foo(u: u8) { if u8 macro_rules! u8 { (u6) => { fn uuuuuuuuuuu() { use s loo mod u8 {
27-
| - - - - - ^
28-
| | | | | |
29-
| | | | | unclosed delimiter
30-
| | | | unclosed delimiter
31-
| | | unclosed delimiter
32-
| unclosed delimiter unclosed delimiter
33-
34-
error: this file contains an unclosed delimiter
35-
--> $DIR/issue-62554.rs:5:89
36-
|
37-
LL | fn foo(u: u8) { if u8 macro_rules! u8 { (u6) => { fn uuuuuuuuuuu() { use s loo mod u8 {
38-
| - - - - - ^
39-
| | | | | |
40-
| | | | | unclosed delimiter
41-
| | | | unclosed delimiter
42-
| | | unclosed delimiter
43-
| unclosed delimiter unclosed delimiter
44-
45-
error: this file contains an unclosed delimiter
46-
--> $DIR/issue-62554.rs:5:89
47-
|
48-
LL | fn foo(u: u8) { if u8 macro_rules! u8 { (u6) => { fn uuuuuuuuuuu() { use s loo mod u8 {
49-
| - - - - - ^
50-
| | | | | |
51-
| | | | | unclosed delimiter
52-
| | | | unclosed delimiter
53-
| | | unclosed delimiter
54-
| unclosed delimiter unclosed delimiter
55-
56-
error: aborting due to 5 previous errors
12+
error: aborting due to previous error
5713

‎tests/ui/parser/issues/issue-62894.stderr

+1-25
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,5 @@ LL |
1010
LL | fn main() {}
1111
| ^
1212

13-
error: this file contains an unclosed delimiter
14-
--> $DIR/issue-62894.rs:6:14
15-
|
16-
LL | fn f() { assert_eq!(f(), (), assert_eq!(assert_eq!
17-
| - - - unclosed delimiter
18-
| | |
19-
| | unclosed delimiter
20-
| unclosed delimiter
21-
LL |
22-
LL | fn main() {}
23-
| ^
24-
25-
error: this file contains an unclosed delimiter
26-
--> $DIR/issue-62894.rs:6:14
27-
|
28-
LL | fn f() { assert_eq!(f(), (), assert_eq!(assert_eq!
29-
| - - - unclosed delimiter
30-
| | |
31-
| | unclosed delimiter
32-
| unclosed delimiter
33-
LL |
34-
LL | fn main() {}
35-
| ^
36-
37-
error: aborting due to 3 previous errors
13+
error: aborting due to previous error
3814

‎tests/ui/parser/issues/issue-62973.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ignore-tidy-trailing-newlines
2-
// error-pattern: aborting due to 4 previous errors
2+
// error-pattern: aborting due to 3 previous errors
33

44
fn main() {}
55

+14-27
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,3 @@
1-
error: this file contains an unclosed delimiter
2-
--> $DIR/issue-62973.rs:8:2
3-
|
4-
LL | fn p() { match s { v, E { [) {) }
5-
| - - - - missing open `(` for this delimiter
6-
| | | |
7-
| | | missing open `(` for this delimiter
8-
| | unclosed delimiter
9-
| unclosed delimiter
10-
LL |
11-
LL |
12-
| ^
13-
14-
error: this file contains an unclosed delimiter
15-
--> $DIR/issue-62973.rs:8:2
16-
|
17-
LL | fn p() { match s { v, E { [) {) }
18-
| - - - - missing open `(` for this delimiter
19-
| | | |
20-
| | | missing open `(` for this delimiter
21-
| | unclosed delimiter
22-
| unclosed delimiter
23-
LL |
24-
LL |
25-
| ^
26-
271
error: mismatched closing delimiter: `)`
282
--> $DIR/issue-62973.rs:6:27
293
|
@@ -40,5 +14,18 @@ LL | fn p() { match s { v, E { [) {) }
4014
| |
4115
| unclosed delimiter
4216

43-
error: aborting due to 4 previous errors
17+
error: this file contains an unclosed delimiter
18+
--> $DIR/issue-62973.rs:8:2
19+
|
20+
LL | fn p() { match s { v, E { [) {) }
21+
| - - - - missing open `(` for this delimiter
22+
| | | |
23+
| | | missing open `(` for this delimiter
24+
| | unclosed delimiter
25+
| unclosed delimiter
26+
LL |
27+
LL |
28+
| ^
29+
30+
error: aborting due to 3 previous errors
4431

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
error: mismatched closing delimiter: `]`
2+
--> $DIR/issue-63116.rs:3:14
3+
|
4+
LL | impl W <s(f;Y(;]
5+
| ^ ^ mismatched closing delimiter
6+
| |
7+
| unclosed delimiter
8+
19
error: this file contains an unclosed delimiter
210
--> $DIR/issue-63116.rs:3:18
311
|
@@ -7,13 +15,5 @@ LL | impl W <s(f;Y(;]
715
| | missing open `[` for this delimiter
816
| unclosed delimiter
917

10-
error: mismatched closing delimiter: `]`
11-
--> $DIR/issue-63116.rs:3:14
12-
|
13-
LL | impl W <s(f;Y(;]
14-
| ^ ^ mismatched closing delimiter
15-
| |
16-
| unclosed delimiter
17-
1818
error: aborting due to 2 previous errors
1919

‎tests/ui/parser/issues/issue-63135.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// error-pattern: this file contains an unclosed delimiter
2-
// error-pattern: aborting due to 2 previous errors
2+
// error-pattern: aborting due to previous error
33
fn i(n{...,f #

‎tests/ui/parser/issues/issue-63135.stderr

+1-10
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,5 @@ LL | fn i(n{...,f #
77
| | unclosed delimiter
88
| unclosed delimiter
99

10-
error: this file contains an unclosed delimiter
11-
--> $DIR/issue-63135.rs:3:16
12-
|
13-
LL | fn i(n{...,f #
14-
| - - ^
15-
| | |
16-
| | unclosed delimiter
17-
| unclosed delimiter
18-
19-
error: aborting due to 2 previous errors
10+
error: aborting due to previous error
2011

‎tests/ui/parser/issues/issue-67377-invalid-syntax-in-enum-discriminant.stderr

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
1-
error: this file contains an unclosed delimiter
2-
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:23:65
3-
|
4-
LL | V = [PhantomData; { [ () ].len() ].len() as isize,
5-
| - missing open `[` for this delimiter
6-
...
7-
LL | V = [Vec::new; { [].len() ].len() as isize,
8-
| - missing open `[` for this delimiter
9-
...
10-
LL | mod c {
11-
| - unclosed delimiter
12-
LL | enum Bug {
13-
LL | V = [Vec::new; { [0].len() ].len() as isize,
14-
| - missing open `[` for this delimiter
15-
...
16-
LL | fn main() {}
17-
| ^
18-
191
error: mismatched closing delimiter: `]`
202
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:5:27
213
|
@@ -43,5 +25,23 @@ LL | V = [Vec::new; { [0].len() ].len() as isize,
4325
| | unclosed delimiter
4426
| closing delimiter possibly meant for this
4527

28+
error: this file contains an unclosed delimiter
29+
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:23:65
30+
|
31+
LL | V = [PhantomData; { [ () ].len() ].len() as isize,
32+
| - missing open `[` for this delimiter
33+
...
34+
LL | V = [Vec::new; { [].len() ].len() as isize,
35+
| - missing open `[` for this delimiter
36+
...
37+
LL | mod c {
38+
| - unclosed delimiter
39+
LL | enum Bug {
40+
LL | V = [Vec::new; { [0].len() ].len() as isize,
41+
| - missing open `[` for this delimiter
42+
...
43+
LL | fn main() {}
44+
| ^
45+
4646
error: aborting due to 4 previous errors
4747

-211 Bytes
Binary file not shown.

‎tests/ui/parser/issues/issue-88770.stderr

+1-25
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,5 @@ LL | fn m(){print!("",(c for&g
1010
LL | e
1111
| ^
1212

13-
error: this file contains an unclosed delimiter
14-
--> $DIR/issue-88770.rs:8:3
15-
|
16-
LL | fn m(){print!("",(c for&g
17-
| - - - unclosed delimiter
18-
| | |
19-
| | unclosed delimiter
20-
| unclosed delimiter
21-
...
22-
LL | e
23-
| ^
24-
25-
error: this file contains an unclosed delimiter
26-
--> $DIR/issue-88770.rs:8:3
27-
|
28-
LL | fn m(){print!("",(c for&g
29-
| - - - unclosed delimiter
30-
| | |
31-
| | unclosed delimiter
32-
| unclosed delimiter
33-
...
34-
LL | e
35-
| ^
36-
37-
error: aborting due to 3 previous errors
13+
error: aborting due to previous error
3814

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// ignore-tidy-trailing-newlines
22
// error-pattern: this file contains an unclosed delimiter
3-
// error-pattern: aborting due to 2 previous errors
3+
// error-pattern: aborting due to previous error
44
fn main((ؼ

‎tests/ui/parser/missing_right_paren.stderr

+1-10
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,5 @@ LL | fn main((ؼ
77
| |unclosed delimiter
88
| unclosed delimiter
99

10-
error: this file contains an unclosed delimiter
11-
--> $DIR/missing_right_paren.rs:4:11
12-
|
13-
LL | fn main((ؼ
14-
| -- ^
15-
| ||
16-
| |unclosed delimiter
17-
| unclosed delimiter
18-
19-
error: aborting due to 2 previous errors
10+
error: aborting due to previous error
2011

‎tests/ui/type/issue-91268.stderr

+1-11
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,5 @@ LL | 0: u8(ţ
88
| |
99
| unclosed delimiter
1010

11-
error: this file contains an unclosed delimiter
12-
--> $DIR/issue-91268.rs:5:12
13-
|
14-
LL | fn main() {
15-
| - unclosed delimiter
16-
LL | 0: u8(ţ
17-
| - ^
18-
| |
19-
| unclosed delimiter
20-
21-
error: aborting due to 2 previous errors
11+
error: aborting due to previous error
2212

‎tests/ui/typeck/issue-91334.stderr

+7-17
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
error: this file contains an unclosed delimiter
2-
--> $DIR/issue-91334.rs:7:23
1+
error: mismatched closing delimiter: `)`
2+
--> $DIR/issue-91334.rs:7:19
33
|
44
LL | fn f(){||yield(((){),
5-
| - - - ^
6-
| | | |
7-
| | | missing open `(` for this delimiter
8-
| | unclosed delimiter
9-
| unclosed delimiter
5+
| - ^^ mismatched closing delimiter
6+
| | |
7+
| | unclosed delimiter
8+
| closing delimiter possibly meant for this
109

1110
error: this file contains an unclosed delimiter
1211
--> $DIR/issue-91334.rs:7:23
@@ -18,14 +17,5 @@ LL | fn f(){||yield(((){),
1817
| | unclosed delimiter
1918
| unclosed delimiter
2019

21-
error: mismatched closing delimiter: `)`
22-
--> $DIR/issue-91334.rs:7:19
23-
|
24-
LL | fn f(){||yield(((){),
25-
| - ^^ mismatched closing delimiter
26-
| | |
27-
| | unclosed delimiter
28-
| closing delimiter possibly meant for this
29-
30-
error: aborting due to 3 previous errors
20+
error: aborting due to 2 previous errors
3121

0 commit comments

Comments
 (0)
Please sign in to comment.