Skip to content

[DO NOT MERGE] Expand core's prelude with more types #125107

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions library/core/src/prelude/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Copy link
Member

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.

Copy link
Member Author

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).

Copy link
Member

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.


#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
#[doc(no_inline)]
pub use crate::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,
};

#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
#[doc(no_inline)]
pub use crate::io::{BorrowedBuf, BorrowedCursor};

#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
#[doc(no_inline)]
pub use crate::marker::{PhantomData, PhantomPinned};
Copy link
Member

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.


#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
#[doc(no_inline)]
pub use crate::mem::{ManuallyDrop, MaybeUninit};

#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
#[doc(no_inline)]
pub use crate::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};

#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
#[doc(no_inline)]
pub use crate::num::{
NonZero, NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, NonZeroU128,
NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize,
};

#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
#[doc(no_inline)]
pub use crate::panic::PanicInfo;

#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
#[doc(no_inline)]
pub use crate::pin::Pin;

#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
#[doc(no_inline)]
pub use crate::ptr::NonNull;

#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
#[doc(no_inline)]
pub use crate::sync::atomic::{
AtomicBool, AtomicI16, AtomicI32, AtomicI64, AtomicI8, AtomicIsize, AtomicPtr, AtomicU16,
AtomicU32, AtomicU64, AtomicU8, AtomicUsize,
};

#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
#[doc(no_inline)]
pub use crate::time::Duration;
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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 😛


#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
#[doc(no_inline)]
pub use crate::ops::ControlFlow;

// Re-exported built-in macros
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
#[doc(no_inline)]
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/proc-macro/meta-macro-hygiene.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctx
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "diagnostic::on_unimplemented")
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "include")

SyntaxContexts:
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/proc-macro/nonterminal-token-hygiene.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctx
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "diagnostic::on_unimplemented")
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "include")

SyntaxContexts:
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/std-uncopyable-atomics.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0507]: cannot move out of a shared reference
--> $DIR/std-uncopyable-atomics.rs:9:13
|
LL | let x = *&x;
| ^^^ move occurs because value has type `std::sync::atomic::AtomicBool`, which does not implement the `Copy` trait
| ^^^ move occurs because value has type `std::prelude::rust_2021::AtomicBool`, which does not implement the `Copy` trait
|
help: consider removing the dereference here
|
Expand All @@ -14,7 +14,7 @@ error[E0507]: cannot move out of a shared reference
--> $DIR/std-uncopyable-atomics.rs:11:13
|
LL | let x = *&x;
| ^^^ move occurs because value has type `std::sync::atomic::AtomicIsize`, which does not implement the `Copy` trait
| ^^^ move occurs because value has type `std::prelude::rust_2021::AtomicIsize`, which does not implement the `Copy` trait
|
help: consider removing the dereference here
|
Expand All @@ -26,7 +26,7 @@ error[E0507]: cannot move out of a shared reference
--> $DIR/std-uncopyable-atomics.rs:13:13
|
LL | let x = *&x;
| ^^^ move occurs because value has type `std::sync::atomic::AtomicUsize`, which does not implement the `Copy` trait
| ^^^ move occurs because value has type `std::prelude::rust_2021::AtomicUsize`, which does not implement the `Copy` trait
|
help: consider removing the dereference here
|
Expand All @@ -38,7 +38,7 @@ error[E0507]: cannot move out of a shared reference
--> $DIR/std-uncopyable-atomics.rs:15:13
|
LL | let x = *&x;
| ^^^ move occurs because value has type `std::sync::atomic::AtomicPtr<usize>`, which does not implement the `Copy` trait
| ^^^ move occurs because value has type `std::prelude::rust_2021::AtomicPtr<usize>`, which does not implement the `Copy` trait
|
help: consider removing the dereference here
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | let _x = NonZero::new(5u32).unwrap();
|
help: consider importing one of these items
|
LL + use core::num::NonZero;
LL + use core::prelude::rust_2024::NonZero;
|
LL + use std::num::NonZero;
|
Expand Down
Loading