-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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 the 2018 edition’s prelude #51418
Comments
(Not exactly, but close enough for an easier explanation. The relevant code is in |
Should we rename |
@eddyb Maybe. Either way seems easy enough for the compiler. |
I really like naming the preludes after the editions instead sequential |
Also, what I think should be added, ordered from most important to least important:
|
@clarcharr The advantage of having |
Yes please! I often find myself using deprecated EDIT: alternative solution for this specific problem: #51610
IIRC, names in prelude are shadowed by anything, including The situation with traits specifically is more difficult: although traits themselves enjoy shadowing, trait methods do not, so ambiguous method call between explicitly and glob imported trait is a compile-time error (I haven't thought about it deeply, but looks like it should be possible, and even natural and consistent, to extend shadowing behavior to trait's methods? (EDIT: filed #51497)). |
@clarcharr Other than @matklad Exactly, the name collision was not with the traits themselves but with the methods that are in scope. |
#51434 had a naïve implementation but was missing something required by https://rust-lang.github.io/rfcs/2052-epochs.html#a-broad-policy-on-epoch-changes: a warning for 2015-edition code that would break with the new prelude. Unfortunately I don’t know how to go about implementing that warning, so any help here is appreciated. Alternatively, tweaking the method resolution rules so that methods from traits that are only in scope through the prelude have “less priority” and do not collide with other methods would allow us to add |
"very unlikely to clash with anything" may applies to many many other types. |
The lang team discussed this; here are my take at some notes:
But there was an observation made that How do people feel about that approach? |
I kinda dropped the ball here and nobody picked it up. The 2018 edition is stable in Rust 1.31 which is now in beta so it’s likely too late for this, closing. |
We can still do the libcore/libstd organizational changes, right? |
Sorry, it’s been a while. What changes are those? |
I just mean having e.g. |
Should we think about re-opening this for the 2021 edition? Or better to start a new thread? |
@oconnor663 there appears to be a new thread at #65512 , I'd suggest anyone else interested in this should migrate there as well. |
…akis Edition-specific preludes This changes `{std,core}::prelude` to export edition-specific preludes under `rust_2015`, `rust_2018` and `rust_2021`. (As suggested in rust-lang#51418 (comment).) For now they all just re-export `v1::*`, but this allows us to add things to the 2021edition prelude soon. This also changes the compiler to make the automatically injected prelude import dependent on the selected edition. cc `@rust-lang/libs` `@djc`
…akis Edition-specific preludes This changes `{std,core}::prelude` to export edition-specific preludes under `rust_2015`, `rust_2018` and `rust_2021`. (As suggested in rust-lang#51418 (comment).) For now they all just re-export `v1::*`, but this allows us to add things to the 2021edition prelude soon. This also changes the compiler to make the automatically injected prelude import dependent on the selected edition. cc `@rust-lang/libs` `@djc`
Currently, every module has something like
use std::prelude::v1::*;
implicitly inserted into it by default.In #49305 we added the
TryFrom
andTryInto
traits to the prelude, and reverted that in #49518 because that a breaking change for a significant number on crates that had their ownTryFrom
orTryInto
traits. (Ironically, identical to thestd
ones and duplicated because those were still unstable.)Consensus is that we’d still like to have those traits in the prelude, but to avoid breakage we need to make that opt-in. The upcoming 2018 edition seems to be a good opportunity for that. For modules in crates that opt into the 2018 edition, we could replace
v1
in that inserted code withedition2018
and createsrc/libstd/prelude/edition2018.rs
andsrc/libcore/prelude/edition2018.rs
like so:Are there more items we considered adding to the prelude but didn’t because of breakage or breakage risk?
Update: implemented in #51434.
The text was updated successfully, but these errors were encountered: