Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pub silently dropped from nested item macro invocation #14660

Closed
kmcallister opened this issue Jun 5, 2014 · 0 comments · Fixed by #22285
Closed

pub silently dropped from nested item macro invocation #14660

kmcallister opened this issue Jun 5, 2014 · 0 comments · Fixed by #22285
Assignees
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)

Comments

@kmcallister
Copy link
Contributor

#![feature(macro_rules)]

macro_rules! priv_x( () => (
    static x: uint = 0;
))

macro_rules! pub_x( () => (
    pub priv_x!()
))

mod foo {
    pub_x!()
}

fn main() {
    let y: uint = foo::x;
}

expands to

// ...
mod foo {
    use std::prelude::*;
    static x: uint = 0;
}

fn main() { let y: uint = foo::x; }

and fails with

foo.rs:16:19: 16:25 error: static `x` is private
foo.rs:16     let y: uint = foo::x;
                            ^~~~~~

This isn't a hygeine issue; a macro which expands directly to pub static x: uint = 0; works fine.

rustc 0.11.0-pre (ef9bf3a 2014-06-04 13:06:47 -0700)
host: x86_64-unknown-linux-gnu

@kmcallister kmcallister added A-syntaxext Area: Syntax extensions A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) and removed A-syntaxext Area: Syntax extensions labels Sep 27, 2014
@kmcallister kmcallister self-assigned this Feb 3, 2015
kmcallister added a commit to kmcallister/rust that referenced this issue Feb 13, 2015
It's not clear what this means, because a macro in item position can expand to
zero or more items.  For now we disallow it, which is technically a

    [breaking-change]

but is landing without an RFC.  The `pub` keyword previously had no effect,
which seems quite unintended.

Fixes rust-lang#18317.
Fixes rust-lang#14660.
Manishearth added a commit to Manishearth/rust that referenced this issue Feb 15, 2015
 It's not clear what this means, because a macro in item position can expand to zero or more items.  For now we disallow it, which is technically a

    [breaking-change]

but is landing without an RFC.  The `pub` keyword previously had no effect, which seems quite unintended.

Fixes rust-lang#18317.
Fixes rust-lang#14660.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant