Skip to content

Commit

Permalink
syntax: Parse outer attributes in quote_method!
Browse files Browse the repository at this point in the history
Fixes #17782.
  • Loading branch information
bgamari committed Oct 6, 2014
1 parent c586490 commit a5a11a8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/libsyntax/ext/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,13 +464,8 @@ pub fn expand_quote_method(cx: &mut ExtCtxt,
sp: Span,
tts: &[ast::TokenTree])
-> Box<base::MacResult+'static> {
let e_attrs = cx.expr_vec_ng(sp);
let e_visibility = cx.expr_path(cx.path_global(sp, vec!(
id_ext("syntax"),
id_ext("ast"),
id_ext("Inherited"))));
let expanded = expand_parse_call(cx, sp, "parse_method",
vec!(e_attrs, e_visibility), tts);
let expanded = expand_parse_call(cx, sp, "parse_method_with_outer_attributes",
vec!(), tts);
base::MacExpr::new(expanded)
}

Expand Down
7 changes: 7 additions & 0 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4371,6 +4371,13 @@ impl<'a> Parser<'a> {
(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.
pub fn parse_method(&mut self,
attrs: Vec<Attribute>,
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass-fulldeps/quote-tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fn syntax_extension(cx: &ExtCtxt) {
assert!(i.is_some());

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() {
Expand Down

9 comments on commit a5a11a8

@bors
Copy link
Contributor

@bors bors commented on a5a11a8 Oct 7, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from huonw
at bgamari@a5a11a8

@bors
Copy link
Contributor

@bors bors commented on a5a11a8 Oct 7, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging bgamari/rust/fix-quote-method = a5a11a8 into auto

@bors
Copy link
Contributor

@bors bors commented on a5a11a8 Oct 7, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bgamari/rust/fix-quote-method = a5a11a8 merged ok, testing candidate = 610b3a27

@bors
Copy link
Contributor

@bors bors commented on a5a11a8 Oct 7, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on a5a11a8 Oct 7, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from huonw
at bgamari@a5a11a8

@bors
Copy link
Contributor

@bors bors commented on a5a11a8 Oct 7, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging bgamari/rust/fix-quote-method = a5a11a8 into auto

@bors
Copy link
Contributor

@bors bors commented on a5a11a8 Oct 7, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bgamari/rust/fix-quote-method = a5a11a8 merged ok, testing candidate = 3b945dc

@bors
Copy link
Contributor

@bors bors commented on a5a11a8 Oct 8, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on a5a11a8 Oct 8, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 3b945dc

Please sign in to comment.