Skip to content
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

Edition-specific preludes #82217

Merged
merged 5 commits into from
Mar 10, 2021
Merged

Edition-specific preludes #82217

merged 5 commits into from
Mar 10, 2021

Conversation

m-ou-se
Copy link
Member

@m-ou-se m-ou-se commented Feb 17, 2021

This changes {std,core}::prelude to export edition-specific preludes under rust_2015, rust_2018 and rust_2021. (As suggested in #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

@rust-highfive
Copy link
Collaborator

r? @sfackler

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 17, 2021
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@matklad

This comment has been minimized.

@m-ou-se
Copy link
Member Author

m-ou-se commented Feb 17, 2021

drive by comment, but v1 now seems to be an extra unnecessary layer of indirection?

Yes, but std::prelude::v1 is public and stable, so we can't remove it. We could deprecate it at some point.

Copy link
Contributor

@danielhenrymantilla danielhenrymantilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Could the documentation in of ::std::prelude be adapted too? It uses single-prelude terminology like "the current version of the prelude":

//! The current version of the prelude (version 1) lives in

pub use super::v1::*;

#[unstable(feature = "prelude_2021", issue = "none")]
#[doc(no_inline)]
Copy link
Contributor

@danielhenrymantilla danielhenrymantilla Feb 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Can always be done later) Could this be done for the other editions as well? If only, I think it will be nice to have such a line appear on the documentation of these preludes.

@m-ou-se
Copy link
Member Author

m-ou-se commented Feb 17, 2021

Could the documentation in of ::std::prelude be adapted too? It uses single-prelude terminology like "the current version of the prelude"

I don't think we should do that yet. These new names for the preludes are unstable, and edition 2021 is also not yet stable. So v1 is still the current/only (stable) version of the prelude.

library/core/src/prelude/mod.rs Outdated Show resolved Hide resolved
library/core/src/prelude/mod.rs Outdated Show resolved Hide resolved
library/core/src/prelude/mod.rs Outdated Show resolved Hide resolved
library/core/src/prelude/v1.rs Outdated Show resolved Hide resolved
@bors
Copy link
Contributor

bors commented Feb 19, 2021

☔ The latest upstream changes (presumably #82281) made this pull request unmergeable. Please resolve the merge conflicts.

m-ou-se and others added 5 commits February 25, 2021 12:46
rust_2015 and rust_2018 are just re-exports of v1.
rust_2021 is a module that for now just re-exports everything from v1,
such that we can add more things later.
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
@m-ou-se
Copy link
Member Author

m-ou-se commented Feb 25, 2021

r? @nikomatsakis

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good to me.

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Mar 9, 2021

📌 Commit 76fd8d7 has been approved by nikomatsakis

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 9, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 9, 2021
…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`
@Dylan-DPC-zz
Copy link

failed in rollup

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 9, 2021
@m-ou-se
Copy link
Member Author

m-ou-se commented Mar 9, 2021

@estebank If you have time, I could use some help here. Somehow the E0573 diagnostic suggests to use std::prelude::rust_2021 as an enum, but only when compiling in edition 2015.

use std::result;
impl result {
    fn into_future() -> Err {}
}
fn main() {}
$ rustc +stage1 x.rs --edition=2015
[...]
error[E0573]: expected type, found variant `Err`
 --> x.rs:3:25
  |
3 |     fn into_future() -> Err {}
  |                         ^^^
  |                         |
  |                         not a type
  |                         help: try using the variant's enum: `std::prelude::rust_2021`
$ rustc +stage1 x.rs --edition=2018       
[...]
error[E0573]: expected type, found variant `Err`
 --> x.rs:3:25
  |
3 |     fn into_future() -> Err {}
  |                         ^^^ not a type
  |
help: try using the variant's enum
  |
3 |     fn into_future() -> core::result::Result {}
  |                         ^^^^^^^^^^^^^^^^^^^^
3 |     fn into_future() -> crate::result::Result {}
  |                         ^^^^^^^^^^^^^^^^^^^^^
3 |     fn into_future() -> std::result::Result {}
  |                         ^^^^^^^^^^^^^^^^^^^

@m-ou-se
Copy link
Member Author

m-ou-se commented Mar 9, 2021

This is now blocked on #82942

@m-ou-se m-ou-se added S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 9, 2021
@estebank
Copy link
Contributor

estebank commented Mar 9, 2021

@m-ou-se the ping is resolved by the open PR, right?

@m-ou-se
Copy link
Member Author

m-ou-se commented Mar 9, 2021

@estebank Yes. I'm still curious why it picks the rust_2021 prelude specifically on edition 2015 though. But I suppose that's not really important.

JohnTitor added a commit to JohnTitor/rust that referenced this pull request Mar 9, 2021
…de-v1, r=estebank

Don't hardcode the `v1` prelude in diagnostics, to allow for new preludes.

Instead of looking for `std::prelude::v1`, this changes the two places where that was hardcoded to look for `std::prelude::<anything>` instead.

This is needed for rust-lang#82217.

r? `@estebank`
@m-ou-se
Copy link
Member Author

m-ou-se commented Mar 10, 2021

This should be fine now that #82942 is merged.

@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented Mar 10, 2021

📌 Commit 76fd8d7 has been approved by nikomatsakis

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. labels Mar 10, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 10, 2021
Rollup of 9 pull requests

Successful merges:

 - rust-lang#81309 (always eagerly eval consts in Relate)
 - rust-lang#82217 (Edition-specific preludes)
 - rust-lang#82807 (rustdoc: Remove redundant enableSearchInput function)
 - rust-lang#82924 (WASI: Switch to crt1-command.o to enable support for new-style commands)
 - rust-lang#82949 (Do not attempt to unlock envlock in child process after a fork.)
 - rust-lang#82955 (fix: wrong word)
 - rust-lang#82962 (Treat header as first paragraph for shortened markdown descriptions)
 - rust-lang#82976 (fix error message for copy(_nonoverlapping) overflow)
 - rust-lang#82977 (Rename `Option::get_or_default` to `get_or_insert_default`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 759204f into rust-lang:master Mar 10, 2021
@rustbot rustbot added this to the 1.52.0 milestone Mar 10, 2021
@m-ou-se m-ou-se deleted the edition-prelude branch March 10, 2021 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.