Skip to content

Commit 3b945dc

Browse files
committed
auto merge of #17787 : bgamari/rust/fix-quote-method, r=huonw
The previous fix introduced in 75d49c8 neglected to parse outer attributes as described in #17782.
2 parents 8881c35 + a5a11a8 commit 3b945dc

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/libsyntax/ext/quote.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -464,13 +464,8 @@ pub fn expand_quote_method(cx: &mut ExtCtxt,
464464
sp: Span,
465465
tts: &[ast::TokenTree])
466466
-> Box<base::MacResult+'static> {
467-
let e_attrs = cx.expr_vec_ng(sp);
468-
let e_visibility = cx.expr_path(cx.path_global(sp, vec!(
469-
id_ext("syntax"),
470-
id_ext("ast"),
471-
id_ext("Inherited"))));
472-
let expanded = expand_parse_call(cx, sp, "parse_method",
473-
vec!(e_attrs, e_visibility), tts);
467+
let expanded = expand_parse_call(cx, sp, "parse_method_with_outer_attributes",
468+
vec!(), tts);
474469
base::MacExpr::new(expanded)
475470
}
476471

src/libsyntax/parse/parser.rs

+7
Original file line numberDiff line numberDiff line change
@@ -4371,6 +4371,13 @@ impl<'a> Parser<'a> {
43714371
(ident, ItemFn(decl, fn_style, abi, generics, body), Some(inner_attrs))
43724372
}
43734373

4374+
/// Parse a method in a trait impl
4375+
pub fn parse_method_with_outer_attributes(&mut self) -> P<Method> {
4376+
let attrs = self.parse_outer_attributes();
4377+
let visa = self.parse_visibility();
4378+
self.parse_method(attrs, visa)
4379+
}
4380+
43744381
/// Parse a method in a trait impl, starting with `attrs` attributes.
43754382
pub fn parse_method(&mut self,
43764383
attrs: Vec<Attribute>,

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

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fn syntax_extension(cx: &ExtCtxt) {
3737
assert!(i.is_some());
3838

3939
let _j: P<syntax::ast::Method> = quote_method!(cx, fn foo(&self) {});
40+
let _k: P<syntax::ast::Method> = quote_method!(cx, #[doc = "hello"] fn foo(&self) {});
4041
}
4142

4243
fn main() {

0 commit comments

Comments
 (0)