Repository navigation
(Modules) Tracking issue for crate as a visibility modifier #53120
Copy link
Copy link
Closed
Labels
A-visibilityArea: Visibility / privacyArea: Visibility / privacyB-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.Blocker: Approved by a merged RFC but not yet implemented.B-RFC-implementedBlocker: Approved by a merged RFC and implemented but not stabilized.Blocker: Approved by a merged RFC and implemented but not stabilized.B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-design-concernsStatus: There are blocking design concerns.Status: There are blocking design concerns.T-langRelevant to the language teamRelevant to the language teamdisposition-closeThis PR / issue is in PFCP or FCP with a disposition to close it.This PR / issue is in PFCP or FCP with a disposition to close it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Description
This is a sub-tracking issue for the RFC "Clarify and streamline paths and visibility" (rust-lang/rfcs#2126)
dealing with the question of crate as a visibility modifier.
- Implement the RFC
- Adjust documentation (see instructions on forge)
- Stabilization PR (see instructions on forge)
Unresolved questions:
- How do we parse
struct Foo(crate ::bar)?
Reacted by Jeremy Banks
Reacted by accusitive, Mario Ortiz Manero, Vinícius Miguel, João Marcos and Johan Milanov
Reacted by Gurwinder Singh
Reacted by quininer, Ilya Vennik, Hiro Saito, Stepan Koltsov, Vinícius Miguel, João Marcos, Ziru Niu and Jakub Beránek
Metadata
Metadata
Assignees
Labels
A-visibilityArea: Visibility / privacyArea: Visibility / privacyB-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.Blocker: Approved by a merged RFC but not yet implemented.B-RFC-implementedBlocker: Approved by a merged RFC and implemented but not stabilized.Blocker: Approved by a merged RFC and implemented but not stabilized.B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-design-concernsStatus: There are blocking design concerns.Status: There are blocking design concerns.T-langRelevant to the language teamRelevant to the language teamdisposition-closeThis PR / issue is in PFCP or FCP with a disposition to close it.This PR / issue is in PFCP or FCP with a disposition to close it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Activity
Centril commentedon Aug 6, 2018
Comments about
crateas a visibility modifier:Parsing ambiguity
Unnatural / Confusion / Not improvement
A good idea
pub(extern)insteadBikeshed
An early preview
Dedicated thread
Centril commentedon Aug 6, 2018
Personally, I am very much in favor of
crateas a visibility modifier and I share @stepancheg's comment here. I think that we should encourage smaller and stricter visibilities andcratedoes just that.lilianmoraru commentedon Aug 6, 2018
I'm personally ok with writing
pub(crate), the intent seems very explicit.The example given by @johnthagen is really painful to see(using
crate):crate mod color;especially seems confusing, you definitely need to put a bit of thought on what's happening there.rpjohnst commentedon Aug 6, 2018
Some of these examples are very C-
static-esque- intuitively related but really surprisingly distinct.Centril commentedon Aug 6, 2018
The example due to @johnthagen does not read poorly to me. In fact, it reads naturally and I quite like the symmetry. It is beautiful in a way.
If the readability of:
becomes a problem; then an IDE/editor that understands the syntax of Rust can highlight the
cratetokens in the different positions with different colors. That should clear up the difference well I think.matklad commentedon Aug 6, 2018
crateas visibility modifier is definitely weird: it uses very rust-specific keyword for a thing which is not specific to rust. Kotlin & C# useinternalfor this.I'd personally would want to reuse
pubforcrate-visible, and go for a more screamy syntax for world visible, likepub*orpub!.johnthagen commentedon Aug 6, 2018
It's been brought up before, but I think the root issues I see are:
crateis a noun. I thinkpub(crate)is long and odd looking, so I fully support replacing it with something, but it did have the public adjective associated with it, so grammatically it flowed better.crateis now used as the anchor for "this-crate" imports, which means something different than "wherever this is defined, it's also exported visibly from this crate"Compared to an example, using @matklad's
internalfrom Kotlin/C#.I'm not saying
internalis the right keyword (Rust likes it's very short abbreviations, andintis unfortunately full of C/C++/Java confusion), but I personally think that the second example is immediately more readable.I also think the
cratevisibility keyword will be confusing to people coming to Rust from other languages. If even many of us involved enough in Rust to comment on these threads are jarred, I'd have to imagine it will trip up people new to Rust as well.seanmonstar commentedon Aug 6, 2018
The slightly longer syntax of
pub(crate)may not be such a big deal if weren't becoming a warning/error to havepubitems that aren't reachable outside the crate. I personally wish that if I had apub(crate) struct Foo { ... }, that the compiler could realize that all thepub fns in aimpl Fooare clearly not reachable, and not bother me about it.I find it to be just busy work currently in Rust 2015 if I ever mark a type from
pub struct Footopub(crate) struct Foo, how the compiler then yells in all the places that some otherpub fns exist using the suddenlypub(crate)type, when the problem isn't real, because the other type is alsopub(crate).johnthagen commentedon Aug 6, 2018
I also find @matklad's idea of re-purposing
pubas crate-public and usingexportor something for world-visible exports. But that may be too big a divergence for an edition?rpjohnst commentedon Aug 7, 2018
Repurposing
pubas crate-public and adding a new visibility for world-public was the proposal before the current version. Such a change to existing semantics was considered too drastic even for an edition, which is whypubis now keeping its current meaning.What was less discussed and considered, I think, was repurposing
pubsolely via a lint. Perhaps we could switch the lint from "warn onpubthat's not accessible outside the crate" to "warn onpubthat is accessible outside the crate," and add a purely optionalpub(extern)/exportkeyword. That is, don't change any semantics, just add a lint-silencing syntax.I suspect this would be less disruptive, based on the assumption that there are fewer world-public items than crate-public items. It would also preserve the intuitive (though subtly incorrect) meaning of
pubas "export from the current module" rather than confronting everyone with visibility's true behavior.glaebhoerl commentedon Aug 7, 2018
FWIW, though it only saves two characters, if we wanted to abbreviate
internal, the "right" abbreviation would probably, by analogy withexternal, beintern. Unfortunate that that is also a noun with a commonly understood, different meaning. Oh well.112 remaining items
Auto merge of rust-lang#97239 - jhpratt:remove-crate-vis, r=joshtriplett
rfcbot commentedon May 21, 2022
The final comment period, with a disposition to close, as per the review above, is now complete.
As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.
jhpratt commentedon May 21, 2022
PR up for removing the feature itself: #97254
Rollup merge of rust-lang#97254 - jhpratt:remove-crate-vis, r=cjgillot
Rollup merge of rust-lang#97254 - jhpratt:remove-crate-vis, r=cjgillot
joshtriplett commentedon Jul 16, 2022
Removed in #97254 .
Auto merge of #15287 - lowr:internal/remove-crate-vis, r=lnicola
Remove support for `crate` visibility modifier
Remove support for `crate` visibility modifier