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 all 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
57 changes: 57 additions & 0 deletions library/core/src/prelude/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,63 @@ 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::{LazyCell, OnceCell, RefCell, SyncUnsafeCell, UnsafeCell};

#[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_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::ops::ControlFlow;

// Re-exported built-in macros
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
#[doc(no_inline)]
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,15 +599,15 @@ fn has_where_lifetimes<'tcx>(cx: &LateContext<'tcx>, generics: &'tcx Generics<'_
struct LifetimeChecker<'cx, 'tcx, F> {
cx: &'cx LateContext<'tcx>,
map: FxHashMap<Symbol, Span>,
phantom: std::marker::PhantomData<F>,
phantom: PhantomData<F>,
}

impl<'cx, 'tcx, F> LifetimeChecker<'cx, 'tcx, F> {
fn new(cx: &'cx LateContext<'tcx>, map: FxHashMap<Symbol, Span>) -> LifetimeChecker<'cx, 'tcx, F> {
Self {
cx,
map,
phantom: std::marker::PhantomData,
phantom: PhantomData,
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/zero_repeat_side_effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ fn inner_check(cx: &LateContext<'_>, expr: &'_ rustc_hir::Expr<'_>, inner_expr:
// check if expr is a call or has a call inside it
if for_each_expr(inner_expr, |x| {
if let ExprKind::Call(_, _) | ExprKind::MethodCall(_, _, _, _) = x.kind {
std::ops::ControlFlow::Break(())
ControlFlow::Break(())
} else {
std::ops::ControlFlow::Continue(())
ControlFlow::Continue(())
}
})
.is_some()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: `std::sync::atomic::AtomicU32` is not allowed according to config
error: `std::prelude::rust_2021::AtomicU32` is not allowed according to config
--> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:7:1
|
LL | use std::sync::atomic::AtomicU32;
Expand All @@ -25,7 +25,7 @@ error: `std::time::Instant` is not allowed according to config
LL | fn bad_arg_type(_: impl Fn(Sneaky) -> foo::atomic::AtomicU32) {}
| ^^^^^^

error: `std::sync::atomic::AtomicU32` is not allowed according to config
error: `std::prelude::rust_2021::AtomicU32` is not allowed according to config
--> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:16:39
|
LL | fn bad_arg_type(_: impl Fn(Sneaky) -> foo::atomic::AtomicU32) {}
Expand Down Expand Up @@ -93,19 +93,19 @@ error: `std::time::Instant` is not allowed according to config
LL | let _ = Sneaky::now();
| ^^^^^^

error: `std::sync::atomic::AtomicU32` is not allowed according to config
error: `std::prelude::rust_2021::AtomicU32` is not allowed according to config
--> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:36:13
|
LL | let _ = foo::atomic::AtomicU32::new(0);
| ^^^^^^^^^^^^^^^^^^^^^^

error: `std::sync::atomic::AtomicU32` is not allowed according to config
error: `std::prelude::rust_2021::AtomicU32` is not allowed according to config
--> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:37:17
|
LL | static FOO: std::sync::atomic::AtomicU32 = foo::atomic::AtomicU32::new(1);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: `std::sync::atomic::AtomicU32` is not allowed according to config
error: `std::prelude::rust_2021::AtomicU32` is not allowed according to config
--> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:37:48
|
LL | static FOO: std::sync::atomic::AtomicU32 = foo::atomic::AtomicU32::new(1);
Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/tests/ui/crashes/ice-6252.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// originally from glacier fixed/77919.rs
// encountered errors resolving bounds after type-checking
//@no-rustfix
#![no_implicit_prelude]
trait TypeVal<T> {
const VAL: T;
}
Expand Down
6 changes: 3 additions & 3 deletions src/tools/clippy/tests/ui/crashes/ice-6252.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0412]: cannot find type `PhantomData` in this scope
--> tests/ui/crashes/ice-6252.rs:9:9
--> tests/ui/crashes/ice-6252.rs:10:9
|
LL | _n: PhantomData,
| ^^^^^^^^^^^ not found in this scope
Expand All @@ -12,7 +12,7 @@ LL + use std::marker::PhantomData;
|

error[E0412]: cannot find type `VAL` in this scope
--> tests/ui/crashes/ice-6252.rs:11:63
--> tests/ui/crashes/ice-6252.rs:12:63
|
LL | impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
| ^^^ not found in this scope
Expand All @@ -23,7 +23,7 @@ LL | impl<N, M, VAL> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
| +++++

error[E0046]: not all trait items implemented, missing: `VAL`
--> tests/ui/crashes/ice-6252.rs:11:1
--> tests/ui/crashes/ice-6252.rs:12:1
|
LL | const VAL: T;
| ------------ `VAL` from trait
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