提交 f907d977 编写于 作者: H Huon Wilson 提交者: Alex Crichton

syntax: parse outer attributes in `quote_item!` calls.

Fixes #14857.
上级 9d5ec04d
......@@ -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)
}
......
......@@ -73,8 +73,7 @@ fn make_items(&self) -> Option<SmallVector<Gc<ast::Item>>> {
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
}
......
......@@ -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,
......
......@@ -4965,6 +4965,11 @@ fn parse_macro_use_or_failure(
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,
......
......@@ -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() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册