From 6c2f322f827ca2f2109bceab0b9630e624ac8810 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 15 Jun 2011 17:51:57 -0700 Subject: Improve and test failure behavior for malformed attributes --- src/comp/front/parser.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/comp/front/parser.rs') diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 88d8516043b..1ee1e2cf0e5 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -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)); -- cgit 1.4.1-3-g733a5