-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
[DO NOT MERGE] Expand core's prelude with more types #125107
Conversation
r? @Nilstrieb rustbot has assigned @Nilstrieb. Use |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably bias most heavily to the "this is basically a kind of primitive to the language runtime" cases. i.e. there may be other reasonable impls of Cell out there, but there sure isn't another one of UnsafeCell.
|
||
#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")] | ||
#[doc(no_inline)] | ||
pub use crate::marker::{PhantomData, PhantomPinned}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...yeah, really want these two.
library/core/src/prelude/common.rs
Outdated
@@ -41,6 +41,67 @@ pub use crate::option::Option::{self, None, Some}; | |||
#[doc(no_inline)] | |||
pub use crate::result::Result::{self, Err, Ok}; | |||
|
|||
#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")] | |||
#[doc(no_inline)] | |||
pub use crate::cell::{Cell, LazyCell, OnceCell, RefCell, SyncUnsafeCell, UnsafeCell}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, the OnceCell case seems like it may risk confusion due to once_cell
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I think that the parts of once_cell
that overlap with std are considered deprecated in favour of std (MSRV willing).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean the author basically contributed the code, so yeah.
library/core/src/prelude/common.rs
Outdated
|
||
#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")] | ||
#[doc(no_inline)] | ||
pub use crate::time::Duration; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like it would risk confusion because time::Duration exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That feels like an awkward one because, without further context, time::Duration
is ambiguous too. I.e. is this the time crate or is there a use std::time
somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right.
and don't forget chrono::Duration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'm willing to see if crater has anything to say about this 😛
Obviously the crater run(?) will be educational in any case. |
This comment has been minimized.
This comment has been minimized.
This will break src\tools\clippy\tests\ui\crashes\ice-6252.rs but I'm not sure if fixing would defeat the purpose of the test. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@bors try |
[DO NOT MERGE] Expand core's prelude with more types This adds some more types to the core prelude, to explore the [proposed prelude policy](rust-lang/std-dev-guide#66). Without any further context, types in the standard library are strongly associated with the standard library so they are good candidates for the prelude, assuming their name doesn't require a module to make sense of. As a bonus this avoids some of the repetition required for `cell::Cell`, `pin::Pin`, `atomic::Atomic*`, etc. Currently this includes some nightly types. These should be removed before this is merged.
☀️ Try build successful - checks-actions |
@craterbot check |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🎉 Experiment
|
Yeah, I figured Cell wouldn't be an option, not in a zillion years. It's not as ubiquitous as Node, but almost. |
people are denying |
I was kinda hoping the prelude was special enough that this sort of issue didn't arise even if there are other good reasons not to have it in the prelude. But alas adding types to the prelude does come with some amount of risk.
I was kinda ignoring them because they're getting exactly what they're asking for 😉 |
@ChrisDenton Can you remove |
Ok, I've removed a few things. I'm ignoring the unnecessary qualifications lint for now because if not breaking that is a requirement then we can never add anything to the prelude (except in a new edition). I'm not sure about removing |
@bors try while I figure out the crater magic |
[DO NOT MERGE] Expand core's prelude with more types This adds some more types to the core prelude, to explore the [proposed prelude policy](rust-lang/std-dev-guide#66). Without any further context, types in the standard library are strongly associated with the standard library so they are good candidates for the prelude, assuming their name doesn't require a module to make sense of. As a bonus this avoids some of the repetition required for `cell::Cell`, `pin::Pin`, `atomic::Atomic*`, etc. Currently this includes some nightly types. These should be removed before this is merged. In summary, this PR currently exports the following from the prelude: ```rust pub use core::cell::{Cell, LazyCell, OnceCell, RefCell, SyncUnsafeCell, UnsafeCell}; pub use core::ffi::{ c_char, c_double, c_float, c_int, c_long, c_longlong, c_ptrdiff_t, c_schar, c_short, c_size_t, c_ssize_t, c_str, c_uchar, c_uint, c_ulong, c_ulonglong, c_ushort, c_void, CStr, }; pub use core::io::{BorrowedBuf, BorrowedCursor}; pub use core::marker::{PhantomData, PhantomPinned}; pub use core::mem::{ManuallyDrop, MaybeUninit}; pub use core::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}; pub use core::num::{ NonZero, NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize, }; pub use core::panic::PanicInfo; pub use core::pin::Pin; pub use core::ptr::NonNull; pub use core::sync::atomic::{ AtomicBool, AtomicI16, AtomicI32, AtomicI64, AtomicI8, AtomicIsize, AtomicPtr, AtomicU16, AtomicU32, AtomicU64, AtomicU8, AtomicUsize, }; pub use core::time::Duration; pub use core::ops::ControlFlow; ``` UPDATE: There have so far been concerns raised about the following types: - `Cell` is maybe too generic a word to be in a prelude type - It is common for time libs to make their own `Duration` type so having it in the prelude may be confusing. This perhaps also suggests the design of std's `Duration` is not ideal but in any case that can't be changed at this point.
the relevant command looks like |
Ah, I'll try that once the try build is finished. |
☀️ Try build successful - checks-actions |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
Now that I look closer at the crater results, it seems all the mod duration {
pub trait Duration {}
}
use duration::*;
use core::prelude::v1::*;
pub struct Timer<Dur: Duration> {
dur: Dur
} Which leads to "error[E0659]: And just for completeness, here are minimized examples of the other failures... error[E0530]: let bindings cannot shadow unit structs: fn main() {
let (PhantomData @ _) = ();
} error[E0308]: mismatched types: fn main() {
let PhantomData = ();
} |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🎉 Experiment
|
Ok, that's down to 25 regressions. 18 of those are caused by using The other failures are all caused by something like |
Time to send https://github.com/loiclec/fuzzcheck-rs a PR I guess. |
r? @ghost |
Failed to set assignee to
|
Oh I think this can be closed now. Unless anyone has any more experiments they want me to run. |
This adds some more types to the core prelude, to explore the proposed prelude policy.
Without any further context, types in the standard library are strongly associated with the standard library so they are good candidates for the prelude, assuming their name doesn't require a module to make sense of. As a bonus this avoids some of the repetition required for
cell::Cell
,pin::Pin
,atomic::Atomic*
, etc.Currently this includes some nightly types. These should be removed before this is merged.
In summary, this PR currently exports the following from the prelude:
UPDATE:
There have so far been concerns raised about the following types:
Cell
is maybe too generic a word to be in a prelude typeDuration
type so having it in the prelude may be confusing. This perhaps also suggests the design of std'sDuration
is not ideal but in any case that can't be changed at this point.