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 upresolve: Minimize hacks in name resolution of primitive types #32131
Conversation
This comment has been minimized.
This comment has been minimized.
|
LGTM, but I'd like to see a decision from @rust-lang/lang. |
eddyb
added
the
S-waiting-on-crater
label
Mar 8, 2016
This comment has been minimized.
This comment has been minimized.
|
Looks good to me, +1 for this change. I'm having trouble seeing why this isn't backwards compatible -- @petrochenkov can you come up with an example that breaks? |
alexcrichton
assigned
eddyb
Mar 8, 2016
jseyfried
reviewed
Mar 9, 2016
| // use std::u8; // bring module u8 in scope | ||
| // fn f() -> u8 { // OK, resolves to primitive u8, not to std::u8 | ||
| // u8::MAX // OK, resolves to associated constant <u8>::MAX, | ||
| // // not to non-existent std::u8::MAX |
This comment has been minimized.
This comment has been minimized.
jseyfried
Mar 9, 2016
Contributor
I believe this resolves to ::std::u8::MAX; MAX is not an associated const of <u8>.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
For some reason I thought extern crates have their own (The changes to prelude will require a crater run though, but I've not included them in this PR) |
This comment has been minimized.
This comment has been minimized.
Excellent. I can't think of any other reason to continue disallowing types that would shadow primitive types.
The prelude is shadowable by everything else, so I think it would be backwards compatible to add to the prelude for all code that doesn't manually import the prelude. |
This comment has been minimized.
This comment has been minimized.
|
@petrochenkov What would you think about moving to disallow modules that shadow primitive types? Then, once associated consts stabilize, we could make Without modules that shadow primitive types, I believe this change would be backwards compatible (except for |
This comment has been minimized.
This comment has been minimized.
"Numeric" modules are more or less fixable if associated constants are improved, but we also have http://doc.rust-lang.org/nightly/std/str/... |
This comment has been minimized.
This comment has been minimized.
|
Ok, but
|
aturon
added
I-nominated
T-lang
labels
Mar 9, 2016
This comment has been minimized.
This comment has been minimized.
|
Nominated for discussion at next lang team meeting. |
This comment has been minimized.
This comment has been minimized.
|
On Wed, Mar 09, 2016 at 12:51:41AM -0800, Jeffrey Seyfried wrote:
I do hope we will do this eventually; I think making imports of associated items work would be a pre-req to doing such a change. |
petrochenkov
force-pushed the
petrochenkov:prim
branch
from
c22949e
to
b830fc2
Mar 10, 2016
This comment has been minimized.
This comment has been minimized.
|
Is another way to view "no implicit prelude" as actually giving you a smaller prelude, that just contains the builtin numeric types? Also, I think we could get away with retroactively feature-gating no-implicit-prelude, which seems like something we did not mean to stabilize. |
This comment has been minimized.
This comment has been minimized.
Sorry, I haven't answered to this.
should give an error message "S is a module and not a type" and not "type name |
This comment has been minimized.
This comment has been minimized.
+1
With prelude changes from #32167 the fallback implemented in this PR starts looking like kind of a small lower priority prelude hardcoded in the resolve (except for "legacy" module shadowing) :) |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis yeah, I think that is a good way to view
I really like this idea! I think we could take this further by including the primitive type modules in the prelude, only allowing primitive types to be used via a
|
This comment has been minimized.
This comment has been minimized.
|
Finally, we could avoid any immediate breakage with a warning cycle, something like: mod u8 {}
fn f(_: u8) {}
//~^ WARN the type `u8` is shadowed by the user-defined module `::u8`, use `::std::u8` instead |
This comment has been minimized.
This comment has been minimized.
I'm not sure removing primitive types together with the main prelude is practical. I need to experiment with
I suspect this will turn out to be much larger hack, then the current fallback. |
This comment has been minimized.
This comment has been minimized.
I think of it as less of a hack if the semantics are cleaner (which I believe they would be). Also, the current implementation can be so simple only because |
This comment has been minimized.
This comment has been minimized.
|
@jseyfried |
This comment has been minimized.
This comment has been minimized.
Completely agree. In the mean time, perhaps we could leverage the existing prelude injection by adding a private module mod std {
pub use prelude; // i.e. `libcore`'s prelude
}and enabling ordinary prelude injection in |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
I've implemented Primitive types are bound to items in cc @eddyb, you wanted to do this looong time ago |
This comment has been minimized.
This comment has been minimized.
|
Nice! I definitely like the result. |
This comment has been minimized.
This comment has been minimized.
|
How about |
This comment has been minimized.
This comment has been minimized.
For documentation purpose only (the item body is ignored) or rust-lang/rfcs#348?
Ok, I'll fix the |
Manishearth
closed this
Mar 26, 2016
Manishearth
reopened this
Mar 26, 2016
bors
added a commit
that referenced
this pull request
Mar 26, 2016
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Mar 26, 2016
This comment has been minimized.
This comment has been minimized.
|
|
bors
added a commit
that referenced
this pull request
Mar 26, 2016
This comment has been minimized.
This comment has been minimized.
|
|
bors
added a commit
that referenced
this pull request
Mar 26, 2016
This comment has been minimized.
This comment has been minimized.
|
|
bors
added a commit
that referenced
this pull request
Mar 26, 2016
This comment has been minimized.
This comment has been minimized.
|
|
bors
added a commit
that referenced
this pull request
Mar 26, 2016
This comment has been minimized.
This comment has been minimized.
|
|
bors
added a commit
that referenced
this pull request
Mar 26, 2016
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Mar 26, 2016
This comment has been minimized.
This comment has been minimized.
|
|
petrochenkov commentedMar 8, 2016
When resolving the first unqualified segment in a path with
nsegments andn - 1associated item segments, e.g. (aora::assocora::assoc::assocetc) try to resolveawithout considering primitive types first. If the "normal" lookup fails or results in a module, then try to resolveaas a primitive type as a fallback.This way backward compatibility is respected, but the restriction from E0317 can be lifted, i.e. primitive names mostly can be shadowed like any other names.
Furthermore, if names of primitive types are put into prelude (now it's possible to do), then most of names will be resolved in conventional way and amount of code relying on this fallback will be greatly reduced. Although, it's not entirely convenient to put them into prelude right now due to temporary conflicts like
use prelude::v1::*; use usize;in libcore/libstd, I'd better wait for proper glob shadowing before doing it.I wish the
no_preludeattribute were unstable as intended :(cc @jseyfried @arielb1
r? @eddyb