Skip to content

Commit f907d97

Browse files
huonwalexcrichton
authored andcommitted
syntax: parse outer attributes in quote_item! calls.
Fixes #14857.
1 parent 9d5ec04 commit f907d97

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

src/libsyntax/ext/quote.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,8 @@ pub fn expand_quote_item(cx: &mut ExtCtxt,
358358
sp: Span,
359359
tts: &[ast::TokenTree])
360360
-> Box<base::MacResult> {
361-
let e_attrs = cx.expr_vec_ng(sp);
362-
let expanded = expand_parse_call(cx, sp, "parse_item",
363-
vec!(e_attrs), tts);
361+
let expanded = expand_parse_call(cx, sp, "parse_item_with_outer_attributes",
362+
vec!(), tts);
364363
base::MacExpr::new(expanded)
365364
}
366365

src/libsyntax/ext/tt/macro_rules.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ impl<'a> MacResult for ParserAnyMacro<'a> {
7373
let mut ret = SmallVector::zero();
7474
loop {
7575
let mut parser = self.parser.borrow_mut();
76-
let attrs = parser.parse_outer_attributes();
77-
match parser.parse_item(attrs) {
76+
match parser.parse_item_with_outer_attributes() {
7877
Some(item) => ret.push(item),
7978
None => break
8079
}

src/libsyntax/parse/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ pub fn parse_item_from_source_str(name: String,
117117
sess: &ParseSess)
118118
-> Option<Gc<ast::Item>> {
119119
let mut p = new_parser_from_source_str(sess, cfg, name, source);
120-
let attrs = p.parse_outer_attributes();
121-
maybe_aborted(p.parse_item(attrs),p)
120+
maybe_aborted(p.parse_item_with_outer_attributes(),p)
122121
}
123122

124123
pub fn parse_meta_from_source_str(name: String,

src/libsyntax/parse/parser.rs

+5
Original file line numberDiff line numberDiff line change
@@ -4965,6 +4965,11 @@ impl<'a> Parser<'a> {
49654965
return IoviNone(attrs);
49664966
}
49674967

4968+
pub fn parse_item_with_outer_attributes(&mut self) -> Option<Gc<Item>> {
4969+
let attrs = self.parse_outer_attributes();
4970+
self.parse_item(attrs)
4971+
}
4972+
49684973
pub fn parse_item(&mut self, attrs: Vec<Attribute> ) -> Option<Gc<Item>> {
49694974
match self.parse_item_or_view_item(attrs, true) {
49704975
IoviNone(_) => None,

src/test/run-pass-fulldeps/quote-tokens.rs

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ fn syntax_extension(cx: &ExtCtxt) {
2828
let _f: @syntax::ast::Expr = quote_expr!(cx, ());
2929
let _g: @syntax::ast::Expr = quote_expr!(cx, true);
3030
let _h: @syntax::ast::Expr = quote_expr!(cx, 'a');
31+
32+
let i: Option<@syntax::ast::Item> = quote_item!(cx, #[deriving(Eq)] struct Foo; );
33+
assert!(i.is_some());
3134
}
3235

3336
fn main() {

0 commit comments

Comments
 (0)