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

Does not support crate visibility restriction #87

Closed
fuine opened this issue Nov 2, 2017 · 1 comment
Closed

Does not support crate visibility restriction #87

fuine opened this issue Nov 2, 2017 · 1 comment

Comments

@fuine
Copy link
Contributor

fuine commented Nov 2, 2017

Consider this example:

#[macro_use]
extern crate lazy_static;

mod a {
    pub mod b {
        use std::collections::HashMap;
        lazy_static! {
            pub(in a) static ref HASHMAP: HashMap<u32, &'static str> = {
                let mut m = HashMap::new();
                m.insert(0, "baz");
                m
            };
        }
    }
    
    use self::b::HASHMAP;

    pub fn foo() {
        println!("{}", HASHMAP[&0]);
    }
}

fn main() {
    a::foo();
}

It works as intended, but if we switch pub(in a) to pub(crate) (both of which are valid visibility restrictions as of Rust v.1.18 and higher) we get an error:

error: no rules expected the token `crate`
 --> src/main.rs:8:17
  |
8 |             pub(crate) static ref HASHMAP: HashMap<u32, &'static str> = {
  |                 ^^^^^

I would submit a patch, but unfortunately my macro-foo is not high enough to take on this issue alone (although if someone is willing to mentor I can try to fix this).

@KodrAus
Copy link
Contributor

KodrAus commented Nov 2, 2017

Yeh it looks like we're hard-coding the in $path part here... My macro-foo is also weak, but @dtolnay posted a snippet in another crate that supports pub(crate) and pub(in path). Maybe we should have a look at that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants