-
Notifications
You must be signed in to change notification settings - Fork 13k
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
(Modules) Tracking issue for crate
as a visibility modifier
#53120
Comments
Personally, I am very much in favor of |
I'm personally ok with writing use crate::menu::{Sound, Volume};
crate mod color;
...
/// A type for storing text and an associated color it should
/// be drawn as.
crate struct ColoredText {
crate color: types::Color,
crate text: &'static str,
}
|
Some of these examples are very C- |
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: crate struct ColoredText {
crate color: types::Color,
crate text: &'static str,
} becomes a problem; then an IDE/editor that understands the syntax of Rust can highlight the |
I'd personally would want to reuse |
It's been brought up before, but I think the root issues I see are:
// Here `crate` means the root of this crate.
use crate::menu::{Sound, Volume};
// Here, `crate` means: export crate::game::color
// The `crate` is referring to `color`, not the root.
crate mod color;
...
/// A type for storing text and an associated color it should
/// be drawn as.
// Same potential confusion as `crate mod color`
crate struct ColoredText {
crate color: types::Color,
crate text: &'static str,
} Compared to an example, using @matklad's use crate::menu::{Sound, Volume};
internal mod color;
...
/// A type for storing text and an associated color it should
/// be drawn as.
internal struct ColoredText {
internal color: types::Color,
internal text: &'static str,
} I'm not saying I also think the |
The slightly longer syntax of I find it to be just busy work currently in Rust 2015 if I ever mark a type from |
I also find @matklad's idea of re-purposing |
Repurposing What was less discussed and considered, I think, was repurposing 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 |
FWIW, though it only saves two characters, if we wanted to abbreviate |
@glaebhoerl The symmetry with It's short, (only 1 more character than The updated example would look like: use crate::menu::{Sound, Volume};
intern mod color;
...
/// A type for storing text and an associated color it should
/// be drawn as.
intern struct ColoredText {
intern color: types::Color,
intern text: &'static str,
} |
I've mentioned it before, but I'm not sure what the problem is with nouns used as adjectives? To recap: there are plenty of nouns that can be used as adjectives, eg. a house cat, a computer mouse, a computer desk, etc... A google search for english nouns used as adjectives seems to indicate there's nothing inherently wrong although not all nouns work as adjectives. Let's try it: crate mod hello; A crate module named hello, feels fine. crate use self::local::Foo; Ack, this one does not work, a crate use? You can read it as crate usable item named Foo. It does break the pattern. It can also be awkward when used in front of struct members and even more in combination with crate as the root of a path. While crate isn't perfect, I'm not convinced that 'being a noun' is a deciding factor. |
The problem is that it is very uncommon. There is no programming language I know that use nouns as type modifier. |
Personally, while I find features of different editors nice, I don't think we should design the language with the assumption of a sufficiently advanced editor. I felt like C# was designed this way and it was a major factor in my frustration with that language. |
@epage I think |
As an IDE person, I think such highlighting would add significant amount of noise for a very little amount of information, netting negative. IMO (this is highly personal, but informed by both using and implementing powerful IDEs) highlighting works best when it conveys semantic non-local information (does this usage refers to a variable that was declared with |
It seems to me that It has three letters (nice for alignment, easy to remember), it's not a noun, and - other than 'Document Object Model' - I don't think it has any particular ambiguity attached to it. pub struct MyStruct {
dom num: i32,
pub msg: String,
} Does anybody have thoughts on this? |
One angle on this that I've seen mentioned but couldn't find in the summary (thanks for doing that btw!) is how a shortcut fits in with the existing If For example, if we use
Considering this and my understanding of the goal (clarify public API from internal API), led me to recreate @vitiral's idea of
|
RE Impact on encapsulation One benefit of the existing While there will still be I suspect this isn't an issue because of the culture of small crates. But in considering this, it gives me another iteration on my above comment on
I previously brought up the concern of people transitioning from other languages. This better aligns with them.
imo this is the best of all worlds. So tear it apart and help me understand why not :) |
I still hate the |
@parasyte |
|
Some thoughts from someone who changed camp: At first I was very opposed to I then tried it side-by-side in some of my projects and let it sink in. Frankly, after a few days I couldn't stand looking at Initially I feared there might be (visual) ambiguity; but to me the opposite happened: If I see I can see there might be still be residual "harder" (visual) ambiguity in some cases, but I wouldn't want to trade that back for what now feels like an massive quantitative readability win (as in: "source code lines that require less visual tokenization / effort vs. source code lines that became more ambiguous" ). From that angle Having said this, I don't know about parsing ambiguity. If I had to pick one, I'd much rather have a good story around " |
Team member @joshtriplett has proposed to close this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
I presume if/when the FCP completes, it would be acceptable to remove the |
@jhpratt Yes. And in the meantime it's probably a good idea to start preparing PRs to remove the usage of it. |
Ok. I can, at the least, remove all usage of it in the main repositories. That should be quite easy. If I have time, I will also remove the internals of it. If someone else feels the urge to do that, though, feel free; just let me know so I won't. |
Large (understatement) PR up removing all use of the |
Remove `crate` visibility modifier FCP to remove this syntax is just about complete in rust-lang#53120. Once it completes, this should be merged ASAP to avoid merge conflicts. The first two commits remove usage of the feature in this repository, while the last removes the feature itself.
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. |
PR up for removing the feature itself: #97254 |
Remove feature: `crate` visibility modifier FCP completed in rust-lang#53120.
Remove feature: `crate` visibility modifier FCP completed in rust-lang#53120.
Removed in #97254 . |
internal: remove `crate` visibility modifier This PR removes `crate` as a now-unaccepted experimental visibility modifier from our parser. This feature has been [unaccepted] and [removed] from rustc more than a year ago, so I don't think this removal affects anyone. [unaccepted]: rust-lang/rust#53120 (comment) [removed]: rust-lang/rust#97239
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.Unresolved questions:
struct Foo(crate ::bar)
?The text was updated successfully, but these errors were encountered: