Improve and test failure behavior for malformed attributes

This commit is contained in:
Brian Anderson 2011-06-15 17:51:57 -07:00
parent 67360ae618
commit 6c2f322f82
5 changed files with 47 additions and 1 deletions

View File

@ -1451,7 +1451,19 @@ fn parse_source_stmt(&parser p) -> @ast::stmt {
}
}
alt (parse_item(p, item_attrs)) {
auto maybe_item = parse_item(p, item_attrs);
// If we have attributes then we should have an item
if (vec::len(item_attrs) > 0u) {
alt (maybe_item) {
case (got_item(_)) { /* fallthrough */ }
case (_) {
ret p.err("expected item");
}
}
}
alt (maybe_item) {
case (got_item(?i)) {
auto hi = i.span.hi;
auto decl = @spanned(lo, hi, ast::decl_item(i));

View File

@ -0,0 +1,10 @@
// xfail-stage0
// error-pattern:expected item
fn f() {
#[foo = "bar"]
auto x = 10;
}
fn main() {
}

View File

@ -0,0 +1,8 @@
// xfail-stage0
// error-pattern:expected item
#[foo = "bar"]
use std;
fn main() {
}

View File

@ -0,0 +1,9 @@
// xfail-stage0
// error-pattern:expected item
fn f() {
#[foo = "bar"]
}
fn main() {
}

View File

@ -0,0 +1,7 @@
// xfail-stage0
// error-pattern:expected item
fn main() {
}
#[foo = "bar"]