-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
permit crate
as a shorthand visibility identifier
#45388
Comments
To implementors: Ensure tests related to |
I volunteer. |
With regrets, this breaks rustfmt and rls. This is in the matter of rust-lang#45388.
…, r=nikomatsakis `crate` shorthand visibility modifier cc #45388. r? @nikomatsakis
Seems like this is done! |
`unreachable-pub` lint (as authorized by RFC 2126) To whom it may concern: RFC 2126 commissions the creation of a lint for `pub` items that are not visible from crate root (#45521). We understand (but seek confirmation from more knowledgable compiler elders) that this can be implemented by linting HIR items that are _not_ ~~`cx.access_levels.is_exported`~~ `cx.access_levels.is_reachable` but have a `vis` (-ibility) field of `hir::Visibility::Public`. The lint, tentatively called ~~`unexported-pub`~~ `unreachable-pub` (with the understanding that much could be written on the merits of various names, as it is said of the colors of bicycle-sheds), suggests `crate` as a replacement for `pub` if the `crate_visibility_modifier` feature is enabled (see #45388), and `pub(crate)` otherwise. We also use help messaging to suggest the other potential fix of exporting the item; feedback is desired as to whether this may be confusing or could be worded better. As a preview of what respecting the proposed lint would look like (and to generate confirmatory evidence that this implementation doesn't issue false positives), ~~we take its suggestions for `libcore`~~ (save one, which is deferred to another pull request because it brings up an unrelated technical matter). I remain your obedient servant. ![unexported_pub](https://user-images.githubusercontent.com/1076988/32089794-fbd02420-baa0-11e7-87e5-3ec01f18924a.png) r? @petrochenkov
Reopening as a tracking issue because
|
cc @rust-lang/lang @petrochenkov -- I really want to stabilize the crate visibility modifier. However, there is one issue we ought to resolve first: struct Foo(crate :: X) This is presently interpreted as I am not sure that this is correct: I would think that, since (But if we stabilized |
@nikomatsakis // `#![feature(crate_visibility_modifier)]` is not required
#![feature(crate_in_paths)] // <-- On the other hand, this is required
struct Z;
mod m {
pub struct S(crate::Z);
pub fn get_s() -> S { S(::Z) }
}
fn main() {
m::get_s().0; // ERROR field `0` of struct `m::S` is private
} |
Could we get an FCP to stabilize then? |
I don't think we should stabilize this until we finalize the module changes. There's still some active discussion on one last point of those: whether to write Let's wait and stabilize all of them together, as a unit, in the combination we settle on. |
@joshtriplett do you have any pointers to places where that discussion is happening? |
@est31 The last discussions I saw were on internals.rust-lang.org threads; I believe they're in a bit of a lull at the moment due to attention placed on the edition. |
I haven't seen any discussion on leading crate vs leading :: since https://internals.rust-lang.org/t/the-great-module-adventure-continues/6678 ended in March. |
@Ixrec Likewise. |
This is a duplicate issue of #53120; so I'm closing this one. |
…fier-issue-number, r=Centril Change crate-visibility-modifier issue number in The Unstable Book rust-lang#45388 is closed. Because, it's duplicate issue of rust-lang#53120.
As part of #44660, we plan to support
crate
as a visibility modifier equivalent topub(crate)
. Given thatpub(crate)
exists, this should be relatively straight-forward.Visibilities are stored in the AST type
Visibility
. We will want to extend theCrate
variant to include one additional field, indicating whether the sugarcrate
or the expanded formpub(crate)
was used. We can add an enum likeand add this field to the
Crate
variant, so that it looks likeCrate(Span, CrateSugar)
. Actually, at the same time we can remove theSpan
field, which appears to be unused, so it would just becomeCrate(CrateSugar)
. Doing this simultaneously is sorta bad but will save you some editing, since all existing uses look likeCrate(_)
, and 99% of them want to ignore theCrateSugar
field anyway. =)The one user that does NOT want to ignore
CrateSugar
is the pretty printer. We just want to change this line to something like:Naturally, we also will want to alter the parser itself, in particular the
parse_visibility
function. Currently, if it doesn't see the wordpub
, it just returns. We need to extend this to look forcrate
and -- if it finds it -- to return the new visibility (with sugarJustCrate
). We also need to modify the existingpub(crate)
code to returnPubCrate
for the sugar.(Note: Please limit discussion on this issue strictly to implementation concerns relative to this particular change. Policy discussion as to whether or not to make this change -- or whether to make other changes to the module system -- belong in #44660.)
The text was updated successfully, but these errors were encountered: