Skip to content

Commit a1d2557

Browse files
committed
for comment
Signed-off-by: xizheyin <[email protected]>
1 parent 0682e9e commit a1d2557

File tree

9 files changed

+48
-12
lines changed

9 files changed

+48
-12
lines changed

compiler/rustc_parse/src/lexer/diagnostics.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub(super) fn same_indentation_level(sm: &SourceMap, open_sp: Span, close_sp: Sp
3737
pub(super) fn report_missing_open_delim(
3838
err: &mut Diag<'_>,
3939
unmatched_delims: &mut Vec<UnmatchedDelim>,
40+
retain_all_mismatched: bool,
4041
) -> bool {
4142
let mut reported_missing_open = false;
4243
unmatched_delims.retain(|unmatch_brace| {
@@ -57,7 +58,10 @@ pub(super) fn report_missing_open_delim(
5758
format!("missing open `{missed_open}` for this delimiter"),
5859
);
5960
reported_missing_open = true;
60-
false
61+
62+
// If we don't retain all mismatched delimiters
63+
// we should return false to remove the unmatched delimiter
64+
retain_all_mismatched
6165
} else {
6266
true
6367
}

compiler/rustc_parse/src/lexer/tokentrees.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
8080
}
8181

8282
if let Some((delim, _)) = self.diag_info.open_delimiters.last().cloned() {
83+
report_missing_open_delim(&mut err, &mut self.diag_info.unmatched_delims, true);
84+
8385
report_suspicious_mismatch_block(
8486
&mut err,
8587
&mut self.diag_info,
@@ -248,7 +250,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
248250

249251
err.span_label(self.token.span, "unexpected closing delimiter");
250252

251-
if report_missing_open_delim(&mut err, &mut self.diag_info.unmatched_delims) {
253+
if report_missing_open_delim(&mut err, &mut self.diag_info.unmatched_delims, false) {
252254
return err;
253255
}
254256

tests/ui/parser/issues/issue-104367.stderr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ LL | d: [u32; {
1818
LL | #![cfg] {
1919
| - unclosed delimiter
2020
LL | #![w,)
21+
| - - missing open `(` for this delimiter
22+
| |
23+
| the nearest open delimiter
2124
LL |
2225
| ^
2326

tests/ui/parser/issues/issue-105209.stderr

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ error: this file contains an unclosed delimiter
1010
--> $DIR/issue-105209.rs:3:56
1111
|
1212
LL | #![c={#![c[)x
13-
| - - - unclosed delimiter
14-
| | |
13+
| - - - -- missing open `(` for this delimiter
14+
| | | | |
15+
| | | | the nearest open delimiter
16+
| | | unclosed delimiter
1517
| | unclosed delimiter
1618
| unclosed delimiter
1719
LL |

tests/ui/parser/issues/issue-62973.stderr

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ error: this file contains an unclosed delimiter
1818
--> $DIR/issue-62973.rs:10:2
1919
|
2020
LL | fn p() { match s { v, E { [) {) }
21-
| - - unclosed delimiter
22-
| |
21+
| - - -- -- missing open `(` for this delimiter
22+
| | | || |
23+
| | | || the nearest open delimiter
24+
| | | |missing open `(` for this delimiter
25+
| | | the nearest open delimiter
26+
| | unclosed delimiter
2327
| unclosed delimiter
2428
LL |
2529
LL |

tests/ui/parser/issues/issue-63116.stderr

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ error: this file contains an unclosed delimiter
1010
--> $DIR/issue-63116.rs:4:18
1111
|
1212
LL | impl W <s(f;Y(;]
13-
| - ^
14-
| |
13+
| - - -^
14+
| | | |
15+
| | | missing open `[` for this delimiter
16+
| | the nearest open delimiter
1517
| unclosed delimiter
1618

1719
error: aborting due to 2 previous errors

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,25 @@ LL | V = [Vec::new; { [0].len() ].len() as isize,
2828
error: this file contains an unclosed delimiter
2929
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:23:65
3030
|
31+
LL | V = [PhantomData; { [ () ].len() ].len() as isize,
32+
| - - missing open `[` for this delimiter
33+
| |
34+
| the nearest open delimiter
35+
...
36+
LL | V = [Vec::new; { [].len() ].len() as isize,
37+
| - - missing open `[` for this delimiter
38+
| |
39+
| the nearest open delimiter
40+
...
3141
LL | mod c {
3242
| - unclosed delimiter
3343
LL | enum Bug {
3444
| - this delimiter might not be properly closed...
35-
...
45+
LL | V = [Vec::new; { [0].len() ].len() as isize,
46+
| - - missing open `[` for this delimiter
47+
| |
48+
| the nearest open delimiter
49+
LL |
3650
LL | }
3751
| - ...as it matches this but it has different indentation
3852
LL |

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ error: this file contains an unclosed delimiter
1111
--> $DIR/issue-81827.rs:7:27
1212
|
1313
LL | fn r()->i{0|{#[cfg(r(0{]0
14-
| - - ^
15-
| | |
14+
| - - -- ^
15+
| | | ||
16+
| | | |missing open `[` for this delimiter
17+
| | | the nearest open delimiter
1618
| | unclosed delimiter
1719
| unclosed delimiter
1820

tests/ui/suggestions/issue-94171.stderr

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ error: this file contains an unclosed delimiter
2222
--> $DIR/issue-94171.rs:5:52
2323
|
2424
LL | fn L(]{match
25-
| - unclosed delimiter
25+
| --- unclosed delimiter
26+
| ||
27+
| |missing open `[` for this delimiter
28+
| the nearest open delimiter
2629
LL | (; {`
2730
| - - unclosed delimiter
2831
| |

0 commit comments

Comments
 (0)