Skip to content

Commit ab19861

Browse files
committed
Add a note for unclosed delimiters
Currently, the parser doesn't give any context when it finds an unclosed delimiter and it's not EOF. Report the most recent unclosed delimiter, to help the user along. Closes #10636
1 parent b3ff24a commit ab19861

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

src/libsyntax/parse/parser.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -2086,15 +2086,13 @@ impl Parser {
20862086
fn parse_non_delim_tt_tok(p: &Parser) -> token_tree {
20872087
maybe_whole!(deref p, nt_tt);
20882088
match *p.token {
2089-
token::RPAREN | token::RBRACE | token::RBRACKET
2090-
=> {
2091-
p.fatal(
2092-
format!(
2093-
"incorrect close delimiter: `{}`",
2094-
p.this_token_to_str()
2095-
)
2096-
);
2097-
}
2089+
token::RPAREN | token::RBRACE | token::RBRACKET => {
2090+
// This is a conservative error: only report the last unclosed delimiter. The
2091+
// previous unclosed delimiters could actually be closed! The parser just hasn't
2092+
// gotten to them yet.
2093+
p.open_braces.last_opt().map(|sp| p.span_note(*sp, "unclosed delimiter"));
2094+
p.fatal(format!("incorrect close delimiter: `{}`", p.this_token_to_str()));
2095+
},
20982096
/* we ought to allow different depths of unquotation */
20992097
token::DOLLAR if *p.quote_depth > 0u => {
21002098
p.bump();
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct Obj { //~ NOTE: unclosed delimiter
12+
member: uint
13+
) //~ ERROR: incorrect close delimiter
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub fn trace_option(option: Option<int>) {
12+
option.map(|some| 42; //~ NOTE: unclosed delimiter
13+
} //~ ERROR: incorrect close delimiter

0 commit comments

Comments
 (0)