From 228603d9d210d121599ca384d2a66a90ba4299e1 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Fri, 13 Feb 2015 12:52:33 -0800 Subject: [PATCH] Parse `pub` in the expansion of a method macro Fixes #17436. --- src/libsyntax/ext/tt/macro_rules.rs | 3 +- src/test/run-pass/pub-method-inside-macro.rs | 29 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 src/test/run-pass/pub-method-inside-macro.rs diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index de61bdefa5d..f322cf8bad0 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -89,8 +89,7 @@ impl<'a> MacResult for ParserAnyMacro<'a> { match parser.token { token::Eof => break, _ => { - let attrs = parser.parse_outer_attributes(); - ret.push(parser.parse_method(attrs, ast::Inherited)) + ret.push(parser.parse_method_with_outer_attributes()); } } } diff --git a/src/test/run-pass/pub-method-inside-macro.rs b/src/test/run-pass/pub-method-inside-macro.rs new file mode 100644 index 00000000000..af2f217c1fb --- /dev/null +++ b/src/test/run-pass/pub-method-inside-macro.rs @@ -0,0 +1,29 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Issue #17436 + +mod bleh { + macro_rules! foo { + () => { + pub fn bar(&self) { } + } + } + + pub struct S; + + impl S { + foo!(); + } +} + +fn main() { + bleh::S.bar(); +}