auto merge of #17787 : bgamari/rust/fix-quote-method, r=huonw

The previous fix introduced in 75d49c8203 neglected to parse outer attributes as described in #17782.
This commit is contained in:
bors 2014-10-07 23:12:08 +00:00
commit 3b945dcae6
3 changed files with 10 additions and 7 deletions

View file

@ -464,13 +464,8 @@ pub fn expand_quote_method(cx: &mut ExtCtxt,
sp: Span, sp: Span,
tts: &[ast::TokenTree]) tts: &[ast::TokenTree])
-> Box<base::MacResult+'static> { -> Box<base::MacResult+'static> {
let e_attrs = cx.expr_vec_ng(sp); let expanded = expand_parse_call(cx, sp, "parse_method_with_outer_attributes",
let e_visibility = cx.expr_path(cx.path_global(sp, vec!( vec!(), tts);
id_ext("syntax"),
id_ext("ast"),
id_ext("Inherited"))));
let expanded = expand_parse_call(cx, sp, "parse_method",
vec!(e_attrs, e_visibility), tts);
base::MacExpr::new(expanded) base::MacExpr::new(expanded)
} }

View file

@ -4371,6 +4371,13 @@ impl<'a> Parser<'a> {
(ident, ItemFn(decl, fn_style, abi, generics, body), Some(inner_attrs)) (ident, ItemFn(decl, fn_style, abi, generics, body), Some(inner_attrs))
} }
/// Parse a method in a trait impl
pub fn parse_method_with_outer_attributes(&mut self) -> P<Method> {
let attrs = self.parse_outer_attributes();
let visa = self.parse_visibility();
self.parse_method(attrs, visa)
}
/// Parse a method in a trait impl, starting with `attrs` attributes. /// Parse a method in a trait impl, starting with `attrs` attributes.
pub fn parse_method(&mut self, pub fn parse_method(&mut self,
attrs: Vec<Attribute>, attrs: Vec<Attribute>,

View file

@ -37,6 +37,7 @@ fn syntax_extension(cx: &ExtCtxt) {
assert!(i.is_some()); assert!(i.is_some());
let _j: P<syntax::ast::Method> = quote_method!(cx, fn foo(&self) {}); let _j: P<syntax::ast::Method> = quote_method!(cx, fn foo(&self) {});
let _k: P<syntax::ast::Method> = quote_method!(cx, #[doc = "hello"] fn foo(&self) {});
} }
fn main() { fn main() {