Skip to content

Commit

Permalink
add limit for unclosed delimiters in lexer diagnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Jul 19, 2024
1 parent 521874a commit fcdbd21
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
20 changes: 17 additions & 3 deletions compiler/rustc_parse/src/lexer/tokentrees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,30 @@ impl<'psess, 'src> TokenTreesReader<'psess, 'src> {
fn eof_err(&mut self) -> PErr<'psess> {
let msg = "this file contains an unclosed delimiter";
let mut err = self.string_reader.dcx().struct_span_err(self.token.span, msg);
for &(_, sp) in &self.diag_info.open_braces {
err.span_label(sp, "unclosed delimiter");

let unclosed_delimiter_show_limits = 5;
for &(_, span) in &self.diag_info.open_braces[..unclosed_delimiter_show_limits] {
err.span_label(span, "unclosed delimiter");
self.diag_info.unmatched_delims.push(UnmatchedDelim {
found_delim: None,
found_span: self.token.span,
unclosed_span: Some(sp),
unclosed_span: Some(span),
candidate_span: None,
});
}

if let Some((_, span)) = self.diag_info.open_braces.get(unclosed_delimiter_show_limits)
&& self.diag_info.open_braces.len() >= unclosed_delimiter_show_limits + 2
{
err.span_label(
*span,
format!(
"another {} unclosed delimiters begin from here",
self.diag_info.open_braces.len() - unclosed_delimiter_show_limits
),
);
}

if let Some((delim, _)) = self.diag_info.open_braces.last() {
report_suspicious_mismatch_block(
&mut err,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,9 @@ error: this file contains an unclosed delimiter
LL | fn main() {
| - unclosed delimiter
LL | let a = [[[[[[[[[[[[[[[[[[[[1, {, (, [,;
| -------------------- - this delimiter might not be properly closed...
| ||||||||||||||||||||
| |||||||||||||||||||unclosed delimiter
| ||||||||||||||||||unclosed delimiter
| |||||||||||||||||unclosed delimiter
| ||||||||||||||||unclosed delimiter
| |||||||||||||||unclosed delimiter
| ||||||||||||||unclosed delimiter
| |||||||||||||unclosed delimiter
| ||||||||||||unclosed delimiter
| |||||||||||unclosed delimiter
| ||||||||||unclosed delimiter
| |||||||||unclosed delimiter
| ||||||||unclosed delimiter
| |||||||unclosed delimiter
| ||||||unclosed delimiter
| |||||unclosed delimiter
| ||||unclosed delimiter
| ----- - this delimiter might not be properly closed...
| |||||
| ||||another 16 unclosed delimiters begin from here
| |||unclosed delimiter
| ||unclosed delimiter
| |unclosed delimiter
Expand Down

0 comments on commit fcdbd21

Please sign in to comment.