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

Support for additional access specifiers #126

Closed
wants to merge 6 commits into from
Closed

Support for additional access specifiers #126

wants to merge 6 commits into from

Conversation

GabrielMajeri
Copy link
Contributor

@GabrielMajeri GabrielMajeri commented Oct 11, 2017

This pull request adds support for new access specifiers like pub (crate) or pub (in some_module).

This is currently a nightly only feature, so this pull request should not currently be merged.
It breaks all doctests and integration tests, since they'd need to manually enable #![feature(macro_vis_matcher)].

Fixes #72 (once merged).

@KodrAus
Copy link
Member

KodrAus commented Oct 11, 2017

Nice work! Thanks @GabrielMajeri. I'm not sure if we've got an idea of when macro_vis_matcher should stabilise yet, but hopefully there shouldn't be much churn here so I think it's safe to keep this around for a bit.

Also worth noting that once it does stabilise and we do merge then the minimum rustc version will be bumped.

@tamird
Copy link
Contributor

tamird commented Oct 17, 2017

This can go in behind a cargo feature, right?

@GabrielMajeri
Copy link
Contributor Author

@tamird yes it can, I've now placed it behind the visibility Cargo feature.

@KodrAus
Copy link
Member

KodrAus commented Oct 17, 2017

Hmm, I'm not personally sold on the need for a cargo feature, at least not long-term. I get that bumping the minimum rustc version is potentially breaking, especially if we bump it to the latest stable right away. But since pub(restricted) is a fundamental language feature it seems weird to need a cargo feature to support a language feature in another language feature. So if we did want one now to minimise breakage then I'd be happy if we had a plan to make it the status-quo down the track.

Do you have any thoughts @alexcrichton?

@tamird
Copy link
Contributor

tamird commented Oct 17, 2017

I don't follow, @KodrAus. Using a cargo feature allows this to merge before the necessary bits are stabilized upstream. Bumping the minimum rust version is a separate discussion - there's no reason to hold this up on that decision.

@KodrAus
Copy link
Member

KodrAus commented Oct 17, 2017

Yep, sorry @tamird I was getting ahead of myself 😅 Feel free to ignore all of that until vis stabilises.

@alexcrichton
Copy link
Contributor

Oh I figured we'd just add support when this is in stable rust, but I don't think it is?

@KodrAus
Copy link
Member

KodrAus commented Oct 18, 2017

Yeh it looks like it's still unstable.

I was originally thinking we shouldn't release with a cargo feature because then we'd have to maintain a fork of the macro, and people shouldn't need to use a feature to get pub(restricted) once it's stable.

But I think we could use a feature, and then when it does stabilise we could just make that feature a no-op, since the :vis macro version is essentially more general.

I guess the alternative is not use a feature and let this PR sit here waiting until it can work on stable, but I don't know when that would be.

@alexcrichton
Copy link
Contributor

That's true yeah, I'd also be ok landing it behind an off-by-default feature.

Copy link
Contributor

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to do this in a way that immediately works on stable. Would something like this be possible?

/*
#![feature(macro_vis_matcher)]

macro_rules! m {
    ($vis:vis const $n:ident) => {
        $vis const $n: i32 = 0;
    };
}
*/

macro_rules! m {
    (const $n:ident) => {
        __impl_m!(() const $n);
    };
    (pub const $n:ident) => {
        __impl_m!((pub) const $n);
    };
    (pub ($($vis:tt)+) const $n:ident) => {
        __impl_m!((pub ($($vis)+)) const $n);
    };
}

macro_rules! __impl_m {
    (($($vis:tt)*) const $n:ident) => {
        $($vis)* const $n: i32 = 0;
    };
}

m!(const PRIV);
m!(pub(crate) const CRATE);
m!(pub const PUB);

fn main() {
    println!("{} {} {}", PRIV, CRATE, PUB);
}

@KodrAus
Copy link
Member

KodrAus commented Nov 8, 2017

Neat! What do you think @GabrielMajeri?

@GabrielMajeri
Copy link
Contributor Author

GabrielMajeri commented Nov 8, 2017

@KodrAus I have created a new pull request for that (#135), and will keep this updated for when vis stabilizes.

Was removed when merging upstream changes
@dtolnay
Copy link
Contributor

dtolnay commented Nov 12, 2017

Superseded by #135.

@dtolnay dtolnay closed this Nov 12, 2017
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

Successfully merging this pull request may close these issues.

None yet

5 participants