Skip to content

Commit

Permalink
Do not point at delim spans for complete correct blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Dec 17, 2018
1 parent f4a421e commit 25b3c82
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/libsyntax/parse/lexer/tokentrees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,15 @@ impl<'a> StringReader<'a> {
// Correct delimiter.
token::CloseDelim(d) if d == delim => {
let (open_brace, open_brace_span) = self.open_braces.pop().unwrap();
self.matching_delim_spans.push((open_brace, open_brace_span, self.span));
if self.open_braces.len() == 0 {
// Clear up these spans to avoid suggesting them as we've found
// properly matched delimiters so far for an entire block.
self.matching_delim_spans.clear();
} else {
self.matching_delim_spans.push(
(open_brace, open_brace_span, self.span),
);
}
// Parse the close delimiter.
self.real_token();
}
Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/parser/unmatched-delimiter-at-end-of-file.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
struct S {
x: usize,
y: usize,
}

fn main() {
S { x: 4,
y: 5 };
}

fn foo() { //~ ERROR this file contains an un-closed delimiter
8 changes: 8 additions & 0 deletions src/test/ui/parser/unmatched-delimiter-at-end-of-file.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: this file contains an un-closed delimiter
--> $DIR/unmatched-delimiter-at-end-of-file.rs:11:64
|
LL | fn foo() { //~ ERROR this file contains an un-closed delimiter
| - un-closed delimiter ^

error: aborting due to previous error

0 comments on commit 25b3c82

Please sign in to comment.