Change:
Hey, I have an issue on my macros use. The source code of my macro is . I can't put the pub keyword and if I call my macro like this : The methods aren't public. Am I doing something wrong or is it a compiler's bug ? Thanks in advance.
Any news on it ?
Related?
I think.
I just encountered this. I can reproduce it with:
Now let's just hope it'll be fixed sooner or later !
Hm, what should actually mean? A macro in item position can expand to zero or more items. Should the qualifier apply to all of them, or should it be an error to use it with a multi-item macro? We might want to forbid in this position for 1.0, and come back to the issue later. I had a design for that I think would be rather nice. The current workaround is to write The precise syntax is up to the macro author and can accommodate multiple items. This workaround would be less annoying if we had a "0 or 1" repeat operator in macros.
Could you be a little more explicit about the workaround - I can't seem to get it to work.
from the compiler itself. looks better, with less duplicated code.
Thanks for the examples. If I understand them correctly (neither of which generate forms, iiuc), I should be matching on and inserting a literal in the expansion, but does not seem to work :
It works for me on rustc 1.0.0-dev ( 2015-02-16). The playpen is just to have my fix for .
Thanks for the confirmation. I'll be looking forward to a new nightly for once :)

Discussion:
self.parse_method(attrs, visa) } <ins> fn complain_if_pub_macro(&mut self, visa: Visibility, span: Span) { match visa { Public => { self.span_err(span, "can't qualify macro invocation with `pub`"); self.span_help(span, "try adjusting the macro to put `pub` inside  the invocation"); } Inherited => (), } } </ins> /// Parse a method in a trait impl, starting with `attrs` attributes. pub fn parse_method(&mut self, attrs: Vec<Attribute>,

&& (self.look_ahead(2, |t| *t == token::OpenDelim(token::Paren)) || self.look_ahead(2, |t| *t == token::OpenDelim(token::Brace))) { // method macro. <ins> let last_span = self.last_span; self.complain_if_pub_macro(visa, last_span); </ins> let pth = self.parse_path(NoTypesAllowed); self.expect(&token::Not);

|| self.look_ahead(2, |t| *t == token::OpenDelim(token::Brace))) { // MACRO INVOCATION ITEM <ins> let last_span = self.last_span; self.complain_if_pub_macro(visibility, last_span); </ins> // item macro. let pth = self.parse_path(NoTypesAllowed); self.expect(&token::Not);

<ins> // 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 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. // Issue #14660 macro_rules! priv_x { () => { static x: u32 = 0; }} macro_rules! pub_x { () => { pub priv_x!(); //~ ERROR can't qualify macro invocation with `pub` //~^ HELP try adjusting the macro to put `pub` inside the invocation }} mod foo { pub_x!(); } fn main() { let y: u32 = foo::x; } </ins>

<ins> // 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 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. // Issue #18317 mod bleh { macro_rules! defn { ($n:ident) => ( fn $n (&self) -> i32 { println!("{}", stringify!($n)); 1 } ) } #[derive(Copy)] pub struct S; impl S { pub defn!(f); //~ ERROR can't qualify macro invocation with `pub` //~^ HELP try adjusting the macro to put `pub` inside the invocation } } fn main() { bleh::S.f(); } </ins>

<ins> // 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 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. // Issue #14660 mod bleh { macro_rules! foo { () => { pub fn bar() { } } } foo!(); } fn main() { bleh::bar(); } </ins>