-
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
Tracking issue for RFC 2126: Clarify and streamline paths and visibility #44660
Comments
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? |
@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 |
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 |
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 |
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. |
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. |
It isn't clear how the implementation ended-up... |
@rpjohnst @retep998 I have opened a new RFC to discuss Edit: I suggest we open another RFC to discuss |
Isn't |
@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 is a tiny issue, IMO, given that both visibilities on tuple struct fields and "inline" absolute paths are rare. |
@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. |
@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 |
@rpjohnst I see thanks for clarifying. Its indeed an ambiguity. |
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 |
Just disambiguating to Should we do this? Allowing |
This may be reasonable, at least for a start (nothing prevents relaxing this later). |
I'm not a fan of the |
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 |
Wouldn't the easiest solution to this ambiguity be to use a different keyword for the crate-local visibility modifier (ie: the |
That just introduces another ambiguity between |
@rpjohnst ah damn.. But isn't that a problem the epochs were designed to solve? Eg: in the current epoch we just use |
@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? |
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 |
How would people feel about |
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); |
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 |
The issue of the |
The issue of the |
The issue of the |
The issue of picking a Module Path System has been extracted out to #53130. |
Having extracted out all bits from this issue into separate issues; I am hereby closing this one. |
@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? |
@sanmai-NL can you refresh my memory on what the "extern prelude" was? If it is just the ability to do |
Some of it is being discussed in #54230. |
@sanmai-NL I believe that issue is mainly for diagnostics. |
|
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.) |
@petrochenkov So what's "extern" prelude in relation to that? |
@alexreg |
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. |
@petrochenkov Thanks, makes sense. |
@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? |
This is a tracking issue for the RFC "Clarify and streamline paths and visibility" (rust-lang/rfcs#2126).
Steps:
foo.rs
orfoo/mod.rs
to support submodules likefoo/bar.rs
[RFC 2126] permitfoo.rs
orfoo/mod.rs
to support submodules likefoo/bar.rs
#45385crate
as a visibility modifier permitcrate
as a shorthand visibility identifier #45388crate
to begin an absolute path permitcrate
in absolute paths #45477pub
items that are not visible from crate root add a lint forpub
items that are not reachable from crate root #45521crate
to begin an absolute path. Neither of these items would take effect unless we are using that extension:crate
(Add epoch breakage lint for fully qualified paths that do not usecrate
,self
, orsuper
#48722)extern crate
when feature gate is givenextern crate
epoch lint for Path Clarity RFC (2126) #48719Unresolved 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
rustfix
tool 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::foo
only. However, we also parsestruct Foo(crate ::foo)
as an illegal path, rather than treatingcrate
as a visibility modifier. @petrochenkov describes some of the reasoning in this comment.The text was updated successfully, but these errors were encountered: