diff --git a/src/libsyntax/parse/lexer/tokentrees.rs b/src/libsyntax/parse/lexer/tokentrees.rs index 86c87cf898d09..f087dd9bcbc6f 100644 --- a/src/libsyntax/parse/lexer/tokentrees.rs +++ b/src/libsyntax/parse/lexer/tokentrees.rs @@ -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(); } diff --git a/src/test/ui/parser/unmatched-delimiter-at-end-of-file.rs b/src/test/ui/parser/unmatched-delimiter-at-end-of-file.rs new file mode 100644 index 0000000000000..3eef75bafd39b --- /dev/null +++ b/src/test/ui/parser/unmatched-delimiter-at-end-of-file.rs @@ -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 diff --git a/src/test/ui/parser/unmatched-delimiter-at-end-of-file.stderr b/src/test/ui/parser/unmatched-delimiter-at-end-of-file.stderr new file mode 100644 index 0000000000000..442837e580802 --- /dev/null +++ b/src/test/ui/parser/unmatched-delimiter-at-end-of-file.stderr @@ -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 +