syntax: parse outer attributes in quote_item! calls.

Fixes #14857.
This commit is contained in:
Huon Wilson 2014-06-13 09:40:10 +10:00 committed by Alex Crichton
parent 9d5ec04d18
commit f907d9772c
5 changed files with 12 additions and 7 deletions

View File

@ -358,9 +358,8 @@ pub fn expand_quote_item(cx: &mut ExtCtxt,
sp: Span,
tts: &[ast::TokenTree])
-> Box<base::MacResult> {
let e_attrs = cx.expr_vec_ng(sp);
let expanded = expand_parse_call(cx, sp, "parse_item",
vec!(e_attrs), tts);
let expanded = expand_parse_call(cx, sp, "parse_item_with_outer_attributes",
vec!(), tts);
base::MacExpr::new(expanded)
}

View File

@ -73,8 +73,7 @@ impl<'a> MacResult for ParserAnyMacro<'a> {
let mut ret = SmallVector::zero();
loop {
let mut parser = self.parser.borrow_mut();
let attrs = parser.parse_outer_attributes();
match parser.parse_item(attrs) {
match parser.parse_item_with_outer_attributes() {
Some(item) => ret.push(item),
None => break
}

View File

@ -117,8 +117,7 @@ pub fn parse_item_from_source_str(name: String,
sess: &ParseSess)
-> Option<Gc<ast::Item>> {
let mut p = new_parser_from_source_str(sess, cfg, name, source);
let attrs = p.parse_outer_attributes();
maybe_aborted(p.parse_item(attrs),p)
maybe_aborted(p.parse_item_with_outer_attributes(),p)
}
pub fn parse_meta_from_source_str(name: String,

View File

@ -4965,6 +4965,11 @@ impl<'a> Parser<'a> {
return IoviNone(attrs);
}
pub fn parse_item_with_outer_attributes(&mut self) -> Option<Gc<Item>> {
let attrs = self.parse_outer_attributes();
self.parse_item(attrs)
}
pub fn parse_item(&mut self, attrs: Vec<Attribute> ) -> Option<Gc<Item>> {
match self.parse_item_or_view_item(attrs, true) {
IoviNone(_) => None,

View File

@ -28,6 +28,9 @@ fn syntax_extension(cx: &ExtCtxt) {
let _f: @syntax::ast::Expr = quote_expr!(cx, ());
let _g: @syntax::ast::Expr = quote_expr!(cx, true);
let _h: @syntax::ast::Expr = quote_expr!(cx, 'a');
let i: Option<@syntax::ast::Item> = quote_item!(cx, #[deriving(Eq)] struct Foo; );
assert!(i.is_some());
}
fn main() {