Skip to content

Commit 26d816d

Browse files
committed
---
yaml --- r: 82986 b: refs/heads/auto c: 8db52a5 h: refs/heads/master v: v3
1 parent ffd476f commit 26d816d

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: e293026e9c41a5322d95098c30e193fdb815c1bb
16+
refs/heads/auto: 8db52a5c0eff35a87007533d57127e7afd91fb24
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/libsyntax/parse/parser.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ pub fn Parser(sess: @mut ParseSess,
309309
quote_depth: @mut 0,
310310
obsolete_set: @mut HashSet::new(),
311311
mod_path_stack: @mut ~[],
312+
open_braces: @mut ~[]
312313
}
313314
}
314315

@@ -337,6 +338,8 @@ pub struct Parser {
337338
obsolete_set: @mut HashSet<ObsoleteSyntax>,
338339
/// Used to determine the path to externally loaded source files
339340
mod_path_stack: @mut ~[@str],
341+
/// Stack of spans of open delimiters. Used for error message.
342+
open_braces: @mut ~[Span]
340343
}
341344

342345
#[unsafe_destructor]
@@ -2024,12 +2027,18 @@ impl Parser {
20242027

20252028
match *self.token {
20262029
token::EOF => {
2027-
self.fatal("file ended with unbalanced delimiters");
2030+
for sp in self.open_braces.iter() {
2031+
self.span_note(*sp, "Did you mean to close this delimiter?");
2032+
}
2033+
// There shouldn't really be a span, but it's easier for the test runner
2034+
// if we give it one
2035+
self.fatal("This file contains an un-closed delimiter ");
20282036
}
20292037
token::LPAREN | token::LBRACE | token::LBRACKET => {
20302038
let close_delim = token::flip_delimiter(&*self.token);
20312039

20322040
// Parse the open delimiter.
2041+
(*self.open_braces).push(*self.span);
20332042
let mut result = ~[parse_any_tt_tok(self)];
20342043

20352044
let trees =
@@ -2040,6 +2049,7 @@ impl Parser {
20402049

20412050
// Parse the close delimiter.
20422051
result.push(parse_any_tt_tok(self));
2052+
self.open_braces.pop();
20432053

20442054
tt_delim(@mut result)
20452055
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
static foo: int = 2; } //~ ERROR incorrect close delimiter:
12+

branches/auto/src/test/compile-fail/issue-2354.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// xfail-test
12-
/*
13-
Ideally, the error about the missing close brace in foo would be reported
14-
near the corresponding open brace. But currently it's reported at the end.
15-
xfailed for now (see Issue #2354)
16-
*/
17-
fn foo() { //~ ERROR this open brace is not closed
11+
fn foo() { //~ NOTE Did you mean to close this delimiter?
1812
match Some(x) {
1913
Some(y) { fail!(); }
2014
None { fail!(); }
@@ -25,4 +19,4 @@ fn bar() {
2519
while (i < 1000) {}
2620
}
2721

28-
fn main() {}
22+
fn main() {} //~ ERROR This file contains an un-closed delimiter

0 commit comments

Comments
 (0)