mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
Improve and test failure behavior for malformed attributes
This commit is contained in:
parent
67360ae618
commit
6c2f322f82
@ -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));
|
||||
|
10
src/test/compile-fail/attr-before-stmt.rs
Normal file
10
src/test/compile-fail/attr-before-stmt.rs
Normal file
@ -0,0 +1,10 @@
|
||||
// xfail-stage0
|
||||
// error-pattern:expected item
|
||||
|
||||
fn f() {
|
||||
#[foo = "bar"]
|
||||
auto x = 10;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
8
src/test/compile-fail/attr-before-view-item.rs
Normal file
8
src/test/compile-fail/attr-before-view-item.rs
Normal file
@ -0,0 +1,8 @@
|
||||
// xfail-stage0
|
||||
// error-pattern:expected item
|
||||
|
||||
#[foo = "bar"]
|
||||
use std;
|
||||
|
||||
fn main() {
|
||||
}
|
9
src/test/compile-fail/attr-dangling-in-fn.rs
Normal file
9
src/test/compile-fail/attr-dangling-in-fn.rs
Normal file
@ -0,0 +1,9 @@
|
||||
// xfail-stage0
|
||||
// error-pattern:expected item
|
||||
|
||||
fn f() {
|
||||
#[foo = "bar"]
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
7
src/test/compile-fail/attr-dangling-in-mod.rs
Normal file
7
src/test/compile-fail/attr-dangling-in-mod.rs
Normal file
@ -0,0 +1,7 @@
|
||||
// xfail-stage0
|
||||
// error-pattern:expected item
|
||||
|
||||
fn main() {
|
||||
}
|
||||
|
||||
#[foo = "bar"]
|
Loading…
Reference in New Issue
Block a user