Skip to content

Commit 9130c02

Browse files
committed
Auto merge of rust-lang#125107 - ChrisDenton:core-prelude, r=<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.
2 parents ac385a5 + a222427 commit 9130c02

File tree

10 files changed

+85
-17
lines changed

10 files changed

+85
-17
lines changed

library/core/src/prelude/common.rs

+61
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,67 @@ pub use crate::option::Option::{self, None, Some};
4141
#[doc(no_inline)]
4242
pub use crate::result::Result::{self, Err, Ok};
4343

44+
#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
45+
#[doc(no_inline)]
46+
pub use crate::cell::{Cell, LazyCell, OnceCell, RefCell, SyncUnsafeCell, UnsafeCell};
47+
48+
#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
49+
#[doc(no_inline)]
50+
pub use crate::ffi::{
51+
c_char, c_double, c_float, c_int, c_long, c_longlong, c_ptrdiff_t, c_schar, c_short, c_size_t,
52+
c_ssize_t, c_str, c_uchar, c_uint, c_ulong, c_ulonglong, c_ushort, c_void, CStr,
53+
};
54+
55+
#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
56+
#[doc(no_inline)]
57+
pub use crate::io::{BorrowedBuf, BorrowedCursor};
58+
59+
#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
60+
#[doc(no_inline)]
61+
pub use crate::marker::{PhantomData, PhantomPinned};
62+
63+
#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
64+
#[doc(no_inline)]
65+
pub use crate::mem::{ManuallyDrop, MaybeUninit};
66+
67+
#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
68+
#[doc(no_inline)]
69+
pub use crate::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
70+
71+
#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
72+
#[doc(no_inline)]
73+
pub use crate::num::{
74+
NonZero, NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, NonZeroU128,
75+
NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize,
76+
};
77+
78+
#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
79+
#[doc(no_inline)]
80+
pub use crate::panic::PanicInfo;
81+
82+
#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
83+
#[doc(no_inline)]
84+
pub use crate::pin::Pin;
85+
86+
#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
87+
#[doc(no_inline)]
88+
pub use crate::ptr::NonNull;
89+
90+
#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
91+
#[doc(no_inline)]
92+
pub use crate::sync::atomic::{
93+
AtomicBool, AtomicI16, AtomicI32, AtomicI64, AtomicI8, AtomicIsize, AtomicPtr, AtomicU16,
94+
AtomicU32, AtomicU64, AtomicU8, AtomicUsize,
95+
};
96+
97+
#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
98+
#[doc(no_inline)]
99+
pub use crate::time::Duration;
100+
101+
#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
102+
#[doc(no_inline)]
103+
pub use crate::ops::ControlFlow;
104+
44105
// Re-exported built-in macros
45106
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
46107
#[doc(no_inline)]

src/tools/clippy/clippy_lints/src/lifetimes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -599,15 +599,15 @@ fn has_where_lifetimes<'tcx>(cx: &LateContext<'tcx>, generics: &'tcx Generics<'_
599599
struct LifetimeChecker<'cx, 'tcx, F> {
600600
cx: &'cx LateContext<'tcx>,
601601
map: FxHashMap<Symbol, Span>,
602-
phantom: std::marker::PhantomData<F>,
602+
phantom: PhantomData<F>,
603603
}
604604

605605
impl<'cx, 'tcx, F> LifetimeChecker<'cx, 'tcx, F> {
606606
fn new(cx: &'cx LateContext<'tcx>, map: FxHashMap<Symbol, Span>) -> LifetimeChecker<'cx, 'tcx, F> {
607607
Self {
608608
cx,
609609
map,
610-
phantom: std::marker::PhantomData,
610+
phantom: PhantomData,
611611
}
612612
}
613613
}

src/tools/clippy/clippy_lints/src/zero_repeat_side_effects.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ fn inner_check(cx: &LateContext<'_>, expr: &'_ rustc_hir::Expr<'_>, inner_expr:
6868
// check if expr is a call or has a call inside it
6969
if for_each_expr(inner_expr, |x| {
7070
if let ExprKind::Call(_, _) | ExprKind::MethodCall(_, _, _, _) = x.kind {
71-
std::ops::ControlFlow::Break(())
71+
ControlFlow::Break(())
7272
} else {
73-
std::ops::ControlFlow::Continue(())
73+
ControlFlow::Continue(())
7474
}
7575
})
7676
.is_some()

src/tools/clippy/tests/ui-toml/toml_disallowed_types/conf_disallowed_types.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: `std::sync::atomic::AtomicU32` is not allowed according to config
1+
error: `std::prelude::rust_2021::AtomicU32` is not allowed according to config
22
--> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:7:1
33
|
44
LL | use std::sync::atomic::AtomicU32;
@@ -25,7 +25,7 @@ error: `std::time::Instant` is not allowed according to config
2525
LL | fn bad_arg_type(_: impl Fn(Sneaky) -> foo::atomic::AtomicU32) {}
2626
| ^^^^^^
2727

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

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

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

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

src/tools/clippy/tests/ui/crashes/ice-6252.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// originally from glacier fixed/77919.rs
22
// encountered errors resolving bounds after type-checking
33
//@no-rustfix
4+
#![no_implicit_prelude]
45
trait TypeVal<T> {
56
const VAL: T;
67
}

src/tools/clippy/tests/ui/crashes/ice-6252.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0412]: cannot find type `PhantomData` in this scope
2-
--> tests/ui/crashes/ice-6252.rs:9:9
2+
--> tests/ui/crashes/ice-6252.rs:10:9
33
|
44
LL | _n: PhantomData,
55
| ^^^^^^^^^^^ not found in this scope
@@ -12,7 +12,7 @@ LL + use std::marker::PhantomData;
1212
|
1313

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

2525
error[E0046]: not all trait items implemented, missing: `VAL`
26-
--> tests/ui/crashes/ice-6252.rs:11:1
26+
--> tests/ui/crashes/ice-6252.rs:12:1
2727
|
2828
LL | const VAL: T;
2929
| ------------ `VAL` from trait

tests/ui/proc-macro/meta-macro-hygiene.stdout

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctx
5555
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "diagnostic::on_unimplemented")
5656
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
5757
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
58+
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
59+
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
60+
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
5861
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "include")
5962

6063
SyntaxContexts:

tests/ui/proc-macro/nonterminal-token-hygiene.stdout

+3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctx
7777
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "diagnostic::on_unimplemented")
7878
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
7979
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
80+
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
81+
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
82+
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
8083
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "include")
8184

8285
SyntaxContexts:

tests/ui/std-uncopyable-atomics.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0507]: cannot move out of a shared reference
22
--> $DIR/std-uncopyable-atomics.rs:9:13
33
|
44
LL | let x = *&x;
5-
| ^^^ move occurs because value has type `std::sync::atomic::AtomicBool`, which does not implement the `Copy` trait
5+
| ^^^ move occurs because value has type `std::prelude::rust_2021::AtomicBool`, which does not implement the `Copy` trait
66
|
77
help: consider removing the dereference here
88
|
@@ -14,7 +14,7 @@ error[E0507]: cannot move out of a shared reference
1414
--> $DIR/std-uncopyable-atomics.rs:11:13
1515
|
1616
LL | let x = *&x;
17-
| ^^^ move occurs because value has type `std::sync::atomic::AtomicIsize`, which does not implement the `Copy` trait
17+
| ^^^ move occurs because value has type `std::prelude::rust_2021::AtomicIsize`, which does not implement the `Copy` trait
1818
|
1919
help: consider removing the dereference here
2020
|
@@ -26,7 +26,7 @@ error[E0507]: cannot move out of a shared reference
2626
--> $DIR/std-uncopyable-atomics.rs:13:13
2727
|
2828
LL | let x = *&x;
29-
| ^^^ move occurs because value has type `std::sync::atomic::AtomicUsize`, which does not implement the `Copy` trait
29+
| ^^^ move occurs because value has type `std::prelude::rust_2021::AtomicUsize`, which does not implement the `Copy` trait
3030
|
3131
help: consider removing the dereference here
3232
|
@@ -38,7 +38,7 @@ error[E0507]: cannot move out of a shared reference
3838
--> $DIR/std-uncopyable-atomics.rs:15:13
3939
|
4040
LL | let x = *&x;
41-
| ^^^ move occurs because value has type `std::sync::atomic::AtomicPtr<usize>`, which does not implement the `Copy` trait
41+
| ^^^ move occurs because value has type `std::prelude::rust_2021::AtomicPtr<usize>`, which does not implement the `Copy` trait
4242
|
4343
help: consider removing the dereference here
4444
|

tests/ui/suggestions/core-std-import-order-issue-83564.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | let _x = NonZero::new(5u32).unwrap();
66
|
77
help: consider importing one of these items
88
|
9-
LL + use core::num::NonZero;
9+
LL + use core::prelude::rust_2024::NonZero;
1010
|
1111
LL + use std::num::NonZero;
1212
|

0 commit comments

Comments
 (0)