Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for RFC 2126: Clarify and streamline paths and visibility #44660
Comments
aturon
added
B-RFC-approved
T-lang
labels
Sep 17, 2017
aturon
referenced this issue
Sep 17, 2017
Merged
RFC: Clarify and streamline paths and visibility #2126
aturon
added
E-needs-mentor
WG-compiler-front
labels
Sep 17, 2017
TimNN
added
the
C-tracking-issue
label
Sep 17, 2017
This comment has been minimized.
This comment has been minimized.
|
That RFC has 4 distinct features and yet we still only have one tracking issue for all of them. Can we please not shove together disparate features like this? |
This comment has been minimized.
This comment has been minimized.
|
@retep998 As explained throughout the RFC discussions, these features are connected through global design considerations. E.g., providing an external mechanism for renaming crates is motivated in part by the eventual deprecation of |
This comment has been minimized.
This comment has been minimized.
|
Having an external mechanism to rename crates is something which has already been desired and needed for years (rust-lang/cargo#1311) and could have stood alone just fine, but instead it's being used as nothing more than a pawn to support killing off We've had no problems with having separate RFCs for closely related features in the past (the RFCs for |
This comment has been minimized.
This comment has been minimized.
|
Just to make sure this point sticks around, since it's a relatively subtle aspect of the syntax unresolved question: Using I would thus like to (at least) experiment with leaving out the |
This comment has been minimized.
This comment has been minimized.
|
I wouldn't mind splitting the As far as external crate renaming... there already is a separate issue for it? It is pretty important for the path changes so I think it's fine being part of this one as well. |
This comment has been minimized.
This comment has been minimized.
neon64
commented
Sep 18, 2017
|
Despite lots of discussion a few weeks ago regarding the choice of It's great that this module redesign has progressed so far, but at the same time it's important that we don't blunder ahead just to make the 'impl period', and end up making decisions without consulting the majority of Rust users. And, unfortunately, I think the people involved in Github RFC discussions aren't representative of the whole user base, because of the sheer flood of information/comments/opinions there can be discouraging. So somehow that needs to be dealt with too. |
This comment has been minimized.
This comment has been minimized.
lilianmoraru
commented
Sep 18, 2017
|
It isn't clear how the implementation ended-up... |
This comment has been minimized.
This comment has been minimized.
|
@rpjohnst @retep998 I have opened a new RFC to discuss Edit: I suggest we open another RFC to discuss |
This comment has been minimized.
This comment has been minimized.
Isn't |
This comment has been minimized.
This comment has been minimized.
|
@est31 No, that requires doing name resolution during parsing which is definitely not something we want to do. It's one of the more annoying parts of parsing C and C++, which have similar ambiguities around If we ever start allowing dependencies and top-level modules with the same name, even tangling up name resolution with parsing won't save us- To keep this in perspective, we could just arbitrarily resolve the ambiguity one way or the other and require parentheses to write the other case (probably the |
This comment has been minimized.
This comment has been minimized.
This is a tiny issue, IMO, given that both visibilities on tuple struct fields and "inline" absolute paths are rare. |
This comment has been minimized.
This comment has been minimized.
|
@rpjohnst @petrochenkov could you please share a code example where Edit: the only place where this could be relevant is inside macros when you match for a visibility qualifier + a path. But that's a very small breakage so acceptable IMO. |
This comment has been minimized.
This comment has been minimized.
|
@est31 You seem to have the wrong idea- it's not about relative paths, they're never an issue. It's about building the AST before you know what any of the names refer to. Here's a full sample: struct S(crate :: x :: y);Given that you're not allowed to look up any of those names yet, how do you convert that string of characters into an AST? There are two possible answers. One has a private field of a type |
This comment has been minimized.
This comment has been minimized.
|
@rpjohnst I see thanks for clarifying. Its indeed an ambiguity. |
This comment has been minimized.
This comment has been minimized.
CasualX
commented
Sep 19, 2017
•
|
A simple solution is to define it unambiguously parse to the crate visibility modifier. If you want to parse it as a tuple struct with private member of the given type, do it like this: struct S(:: crate :: x :: y);(note the This is consistent with how other root namespaces need to be referred to in submodules (eg |
This comment has been minimized.
This comment has been minimized.
|
Just disambiguating to Should we do this? Allowing |
This comment has been minimized.
This comment has been minimized.
This may be reasonable, at least for a start (nothing prevents relaxing this later). |
petrochenkov
referenced this issue
Sep 20, 2017
Merged
RFC: Type privacy and private-in-public lints #2145
This comment has been minimized.
This comment has been minimized.
|
I'm not a fan of the |
This comment has been minimized.
This comment has been minimized.
zengsai
commented
Sep 22, 2017
•
|
How about add one more implicit rule? Automatically import extern crate into root namespace, make a more coincident path expression.( I'm not good at English, pls learn my view from the following example) e.g.
src
Make the extern crate's scope as the top level module in crate, then we can write code like this anywhere. for fully/qualified path
relative path write like this
we first look up serde\finlib\foo in current mod scope, if not found lookup in supper mod, until the root namespace. if there have name conflict, we write fully path instead. also we can use |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
neon64
commented
Sep 23, 2017
|
Wouldn't the easiest solution to this ambiguity be to use a different keyword for the crate-local visibility modifier (ie: the |
This comment has been minimized.
This comment has been minimized.
|
That just introduces another ambiguity between |
This comment has been minimized.
This comment has been minimized.
neon64
commented
Sep 24, 2017
|
@rpjohnst ah damn.. But isn't that a problem the epochs were designed to solve? Eg: in the current epoch we just use |
This comment has been minimized.
This comment has been minimized.
|
The reason why we need a short name for In Rust 2018, using |
This comment has been minimized.
This comment has been minimized.
boojies
commented
Jul 30, 2018
|
Sorry, I accidentally created a new issue for this rather than responding to this thread. Oops, I am rather new to github and simply clicked a button that caused me to sign in to what I thought was responding here but which was actually creating a new issue. I will paste what I wrote in the new issue here, and my new issue can be deleted, sorry about that. Seeing as the edition manual suggested people leave feedback here, I've decided to do so. I don't really mind either crate:: or :: for accessing elements from the crate root. :: is what is already the syntax however, so if it is possible to have both crate:: and :: I think that both should be used. The way I see it is that the new suggested crate system regarding paths is essentially equivalent to the old syntax, with the only difference being that you no longer need to use the extern keyword, and things are more accessible rather than needing to use them explicitly in submodules they are essentially implicitly imported everywhere. The only other addition seems to be that you start the crate root with crate:: rather than ::. I prefer starting it with just ::, as this is consistent with the way I originally learned it, however I can see people who haven't learned the module system yet finding starting it with crate:: more intuitive. Why not allow for both syntax forms? Is there some reason that makes it infeasible to have both of them? If both can be supported I thoroughly endorse supporting both of them. If only one can be supported, I am inclined more so toward :: just as it is what I've become accustomed to, though it may be easier for newbies to learn it as crate:: and I can trivially update my understanding of it to be such, so perhaps my motivation is selfish. So essentially, I ultimately don't really care, but I personally prefer ::, but I think supporting both would be ideal, though if one must be selected and people think that starting it with crate:: is superior for newbies then I don't object to this. |
This comment has been minimized.
This comment has been minimized.
|
How is IIUC, right now, given two files mod foo {
#[path = "X/bar.rs"]
mod bar;
}such that the module |
This comment has been minimized.
This comment has been minimized.
parasyte
commented
Aug 2, 2018
•
|
Since we're bikeshedding on a good name for a In one crate I wrote, I found typing But I don't believe In that sense, I like the keyword For completeness, it covers the use cases brought up by @seanmonstar, @johnthagen, et al.: export use crate::generic::{Combine, Func};
// Or even better using relative paths
export use ::generic::{Combine, Func};export struct Bar {
export foo: crate::Foo,
}
export struct Baz(export crate::Foo);use crate::menu::{Sound, Volume};
export mod color;
// ...
/// A type for storing text and an associated color it should
/// be drawn as.
export struct ColoredText {
export color: types::Color,
export text: &'static str,
}All that said, I'm in favor of killing |
This comment has been minimized.
This comment has been minimized.
|
@parasyte The problem I see with It seems like most people agree I haven't heard any "official" feedback if this is still open for discussion though? |
This comment has been minimized.
This comment has been minimized.
|
In the interest of introducing some more words along the lines of @parasyte's suggestion (I agree with @johnthagen that shared use ::generic::{Combine, Func};
shared struct ColoredText {
export color: types::Color,
export text: &'static str,
}global use ::generic::{Combine, Func};
global struct ColoredText {
export color: types::Color,
export text: &'static str,
}We could also follow in Java's footsteps and use something like |
This comment has been minimized.
This comment has been minimized.
|
How would people feel about |
This comment has been minimized.
This comment has been minimized.
CasualX
commented
Aug 2, 2018
|
Using If you squint a little using crate as an adjective doesn't sound that disconcerting. Words such as 'house' can be used as adjectives just fine. IANAEnglishProfessor. I think reexporting a crate visible item isn't super problematic. Personally I've only ever reexported an item in a direct parent of the module which defines it, which means you (probably) want to use mod detail {
crate struct Foo;
}
crate use self::detail::Foo;Using crate as a visibility combined with absolute path to a type (again using seanmonstar's example) does look more problematic: use crate::Bar;
crate struct Foo(crate Bar); |
This comment has been minimized.
This comment has been minimized.
parasyte
commented
Aug 2, 2018
|
I do like the suggestion of To pick on JavaScript for a moment, ES6 doesn't even have a concept of package versus module built into the language. There are only modules. The This isn't greatly different from |
Centril
referenced this issue
Aug 6, 2018
Open
(Modules) Tracking issue for `crate` as a visibility modifier #53120
This comment has been minimized.
This comment has been minimized.
|
The issue of the |
This comment has been minimized.
This comment has been minimized.
|
The issue of the |
This comment has been minimized.
This comment has been minimized.
|
The issue of the |
This comment has been minimized.
This comment has been minimized.
|
The issue of picking a Module Path System has been extracted out to #53130. |
This comment has been minimized.
This comment has been minimized.
|
Having extracted out all bits from this issue into separate issues; I am hereby closing this one. |
Centril
closed this
Aug 6, 2018
petrochenkov
referenced this issue
Aug 21, 2018
Closed
Tracking issue for RFC 1566: Procedural macros #38356
This comment has been minimized.
This comment has been minimized.
sanmai-NL
commented
Sep 20, 2018
|
@Centril: https://doc.rust-lang.org/unstable-book/print.html#extern_prelude links here. Where is this being discussed? If this info is indeed missing, could you add it to the OP? |
This comment has been minimized.
This comment has been minimized.
|
@sanmai-NL can you refresh my memory on what the "extern prelude" was? If it is just the ability to do |
This comment has been minimized.
This comment has been minimized.
sanmai-NL
commented
Sep 20, 2018
|
Some of it is being discussed in #54230. |
This comment has been minimized.
This comment has been minimized.
|
@sanmai-NL I believe that issue is mainly for diagnostics. |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
In general, "prelude" is currently used for all names that are in scope for the whole crate and not attached to a specific module. (There are a lot of those actually.) |
This comment has been minimized.
This comment has been minimized.
|
@petrochenkov So what's "extern" prelude in relation to that? |
This comment has been minimized.
This comment has been minimized.
|
@alexreg |
This comment has been minimized.
This comment has been minimized.
sanmai-NL
commented
Sep 21, 2018
•
|
It would be great if these nuggets of info, no matter how volatile, are recorded in some official source of documentation. Esp. if there are outside mentions of the concept, e.g. in the Unstable book. I’m not saying the maintainers who implement these concepts should do that, though. |
This comment has been minimized.
This comment has been minimized.
|
@petrochenkov Thanks, makes sense. |
This comment has been minimized.
This comment has been minimized.
@Centril Tracking issues in the current beta version link here. Would you update the original comment with the most recent information so that people don't have to spelunk the comments? |
aturon commentedSep 17, 2017
•
edited by Manishearth
This is a tracking issue for the RFC "Clarify and streamline paths and visibility" (rust-lang/rfcs#2126).
Steps:
foo.rsorfoo/mod.rsto support submodules likefoo/bar.rs#45385crateas a visibility modifier #45388crateto begin an absolute path #45477pubitems that are not visible from crate root #45521crateto begin an absolute path. Neither of these items would take effect unless we are using that extension:crate(#48722)extern cratewhen feature gate is givenUnresolved questions:
How should we approach migration? Via a fallback, as proposed, or via epochs? It is probably best to make this determination with more experience, e.g. after we have a
rustfixtool in hand.The final syntax for absolute paths; there's more bikeshedding to be done here in a context where we can actually try out the various options. In particular, there are some real advantages to having both
crate::andextern::paths, but ideally we could do it in a more succinct way.::crate::fooonly. However, we also parsestruct Foo(crate ::foo)as an illegal path, rather than treatingcrateas a visibility modifier. @petrochenkov describes some of the reasoning in this comment.