]> git.lizzy.rs Git - rust.git/blob - library/core/src/lib.rs
Auto merge of #90042 - pietroalbini:1.56-master, r=Mark-Simulacrum
[rust.git] / library / core / src / lib.rs
1 //! # The Rust Core Library
2 //!
3 //! The Rust Core Library is the dependency-free[^free] foundation of [The
4 //! Rust Standard Library](../std/index.html). It is the portable glue
5 //! between the language and its libraries, defining the intrinsic and
6 //! primitive building blocks of all Rust code. It links to no
7 //! upstream libraries, no system libraries, and no libc.
8 //!
9 //! [^free]: Strictly speaking, there are some symbols which are needed but
10 //!          they aren't always necessary.
11 //!
12 //! The core library is *minimal*: it isn't even aware of heap allocation,
13 //! nor does it provide concurrency or I/O. These things require
14 //! platform integration, and this library is platform-agnostic.
15 //!
16 //! # How to use the core library
17 //!
18 //! Please note that all of these details are currently not considered stable.
19 //!
20 // FIXME: Fill me in with more detail when the interface settles
21 //! This library is built on the assumption of a few existing symbols:
22 //!
23 //! * `memcpy`, `memcmp`, `memset` - These are core memory routines which are
24 //!   often generated by LLVM. Additionally, this library can make explicit
25 //!   calls to these functions. Their signatures are the same as found in C.
26 //!   These functions are often provided by the system libc, but can also be
27 //!   provided by the [compiler-builtins crate](https://crates.io/crates/compiler_builtins).
28 //!
29 //! * `rust_begin_panic` - This function takes four arguments, a
30 //!   `fmt::Arguments`, a `&'static str`, and two `u32`'s. These four arguments
31 //!   dictate the panic message, the file at which panic was invoked, and the
32 //!   line and column inside the file. It is up to consumers of this core
33 //!   library to define this panic function; it is only required to never
34 //!   return. This requires a `lang` attribute named `panic_impl`.
35 //!
36 //! * `rust_eh_personality` - is used by the failure mechanisms of the
37 //!    compiler. This is often mapped to GCC's personality function, but crates
38 //!    which do not trigger a panic can be assured that this function is never
39 //!    called. The `lang` attribute is called `eh_personality`.
40
41 // Since libcore defines many fundamental lang items, all tests live in a
42 // separate crate, libcoretest, to avoid bizarre issues.
43 //
44 // Here we explicitly #[cfg]-out this whole crate when testing. If we don't do
45 // this, both the generated test artifact and the linked libtest (which
46 // transitively includes libcore) will both define the same set of lang items,
47 // and this will cause the E0152 "found duplicate lang item" error. See
48 // discussion in #50466 for details.
49 //
50 // This cfg won't affect doc tests.
51 #![cfg(not(test))]
52 // To run libcore tests without x.py without ending up with two copies of libcore, Miri needs to be
53 // able to "empty" this crate. See <https://github.com/rust-lang/miri-test-libstd/issues/4>.
54 // rustc itself never sets the feature, so this line has no affect there.
55 #![cfg(any(not(feature = "miri-test-libstd"), test, doctest))]
56 #![stable(feature = "core", since = "1.6.0")]
57 #![doc(
58     html_playground_url = "https://play.rust-lang.org/",
59     issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
60     test(no_crate_inject, attr(deny(warnings))),
61     test(attr(allow(dead_code, deprecated, unused_variables, unused_mut)))
62 )]
63 #![cfg_attr(
64     not(bootstrap),
65     doc(cfg_hide(
66         not(test),
67         any(not(feature = "miri-test-libstd"), test, doctest),
68         no_fp_fmt_parse,
69         target_pointer_width = "16",
70         target_pointer_width = "32",
71         target_pointer_width = "64",
72         target_has_atomic = "8",
73         target_has_atomic = "16",
74         target_has_atomic = "32",
75         target_has_atomic = "64",
76         target_has_atomic = "ptr",
77         target_has_atomic_equal_alignment = "8",
78         target_has_atomic_equal_alignment = "16",
79         target_has_atomic_equal_alignment = "32",
80         target_has_atomic_equal_alignment = "64",
81         target_has_atomic_equal_alignment = "ptr",
82         target_has_atomic_load_store = "8",
83         target_has_atomic_load_store = "16",
84         target_has_atomic_load_store = "32",
85         target_has_atomic_load_store = "64",
86         target_has_atomic_load_store = "ptr",
87     ))
88 )]
89 #![no_core]
90 //
91 // Lints:
92 #![deny(rust_2021_incompatible_or_patterns)]
93 #![deny(unsafe_op_in_unsafe_fn)]
94 #![warn(deprecated_in_future)]
95 #![warn(missing_debug_implementations)]
96 #![warn(missing_docs)]
97 #![allow(explicit_outlives_requirements)]
98 //
99 // Library features for const fns:
100 #![feature(const_align_of_val)]
101 #![feature(const_alloc_layout)]
102 #![feature(const_arguments_as_str)]
103 #![feature(const_assert_type)]
104 #![feature(const_bigint_helper_methods)]
105 #![feature(const_caller_location)]
106 #![feature(const_cell_into_inner)]
107 #![feature(const_discriminant)]
108 #![feature(const_float_bits_conv)]
109 #![feature(const_float_classify)]
110 #![feature(const_heap)]
111 #![feature(const_inherent_unchecked_arith)]
112 #![feature(const_int_unchecked_arith)]
113 #![feature(const_intrinsic_copy)]
114 #![feature(const_intrinsic_forget)]
115 #![feature(const_likely)]
116 #![feature(const_maybe_uninit_as_ptr)]
117 #![feature(const_maybe_uninit_assume_init)]
118 #![feature(const_num_from_num)]
119 #![feature(const_option)]
120 #![feature(const_pin)]
121 #![feature(const_replace)]
122 #![feature(const_ptr_offset)]
123 #![feature(const_ptr_offset_from)]
124 #![feature(const_ptr_read)]
125 #![feature(const_ptr_write)]
126 #![feature(const_raw_ptr_comparison)]
127 #![feature(const_size_of_val)]
128 #![feature(const_slice_from_raw_parts)]
129 #![feature(const_slice_ptr_len)]
130 #![feature(const_swap)]
131 #![feature(const_trait_impl)]
132 #![feature(const_type_id)]
133 #![feature(const_type_name)]
134 #![feature(const_default_impls)]
135 #![feature(duration_consts_2)]
136 #![feature(ptr_metadata)]
137 #![feature(slice_ptr_get)]
138 #![feature(variant_count)]
139 #![feature(const_array_from_ref)]
140 #![feature(const_slice_from_ref)]
141 //
142 // Language features:
143 #![feature(abi_unadjusted)]
144 #![feature(allow_internal_unsafe)]
145 #![feature(allow_internal_unstable)]
146 #![feature(asm)]
147 #![feature(associated_type_bounds)]
148 #![feature(auto_traits)]
149 #![feature(cfg_target_has_atomic)]
150 #![feature(const_fn_floating_point_arithmetic)]
151 #![feature(const_fn_fn_ptr_basics)]
152 #![feature(const_fn_trait_bound)]
153 #![feature(const_impl_trait)]
154 #![feature(const_mut_refs)]
155 #![feature(const_precise_live_drops)]
156 #![feature(const_raw_ptr_deref)]
157 #![feature(const_refs_to_cell)]
158 #![feature(decl_macro)]
159 #![feature(doc_cfg)]
160 #![feature(doc_notable_trait)]
161 #![feature(doc_primitive)]
162 #![feature(exhaustive_patterns)]
163 #![feature(doc_cfg_hide)]
164 #![feature(extern_types)]
165 #![feature(fundamental)]
166 #![feature(if_let_guard)]
167 #![feature(intra_doc_pointers)]
168 #![feature(intrinsics)]
169 #![feature(lang_items)]
170 #![feature(link_llvm_intrinsics)]
171 #![feature(llvm_asm)]
172 #![feature(min_specialization)]
173 #![feature(mixed_integer_ops)]
174 #![feature(must_not_suspend)]
175 #![feature(negative_impls)]
176 #![feature(never_type)]
177 #![feature(no_core)]
178 #![feature(no_coverage)] // rust-lang/rust#84605
179 #![feature(no_niche)] // rust-lang/rust#68303
180 #![feature(platform_intrinsics)]
181 #![feature(prelude_import)]
182 #![feature(repr_simd)]
183 #![feature(rustc_allow_const_fn_unstable)]
184 #![feature(rustc_attrs)]
185 #![feature(simd_ffi)]
186 #![feature(staged_api)]
187 #![feature(stmt_expr_attributes)]
188 #![feature(trait_alias)]
189 #![feature(transparent_unions)]
190 #![feature(try_blocks)]
191 #![feature(unboxed_closures)]
192 #![feature(unsized_fn_params)]
193 //
194 // Target features:
195 #![feature(aarch64_target_feature)]
196 #![feature(adx_target_feature)]
197 #![feature(arm_target_feature)]
198 #![feature(avx512_target_feature)]
199 #![feature(cmpxchg16b_target_feature)]
200 #![feature(f16c_target_feature)]
201 #![feature(hexagon_target_feature)]
202 #![feature(mips_target_feature)]
203 #![feature(powerpc_target_feature)]
204 #![feature(rtm_target_feature)]
205 #![feature(sse4a_target_feature)]
206 #![feature(tbm_target_feature)]
207 #![feature(wasm_target_feature)]
208
209 // allow using `core::` in intra-doc links
210 #[allow(unused_extern_crates)]
211 extern crate self as core;
212
213 #[prelude_import]
214 #[allow(unused)]
215 use prelude::v1::*;
216
217 #[cfg(not(test))] // See #65860
218 #[macro_use]
219 mod macros;
220
221 // We don't export this through #[macro_export] for now, to avoid breakage.
222 // See https://github.com/rust-lang/rust/issues/82913
223 #[cfg(not(test))]
224 #[unstable(feature = "assert_matches", issue = "82775")]
225 /// Unstable module containing the unstable `assert_matches` macro.
226 pub mod assert_matches {
227     #[unstable(feature = "assert_matches", issue = "82775")]
228     pub use crate::macros::{assert_matches, debug_assert_matches};
229 }
230
231 #[macro_use]
232 mod internal_macros;
233
234 #[path = "num/shells/int_macros.rs"]
235 #[macro_use]
236 mod int_macros;
237
238 #[path = "num/shells/i128.rs"]
239 pub mod i128;
240 #[path = "num/shells/i16.rs"]
241 pub mod i16;
242 #[path = "num/shells/i32.rs"]
243 pub mod i32;
244 #[path = "num/shells/i64.rs"]
245 pub mod i64;
246 #[path = "num/shells/i8.rs"]
247 pub mod i8;
248 #[path = "num/shells/isize.rs"]
249 pub mod isize;
250
251 #[path = "num/shells/u128.rs"]
252 pub mod u128;
253 #[path = "num/shells/u16.rs"]
254 pub mod u16;
255 #[path = "num/shells/u32.rs"]
256 pub mod u32;
257 #[path = "num/shells/u64.rs"]
258 pub mod u64;
259 #[path = "num/shells/u8.rs"]
260 pub mod u8;
261 #[path = "num/shells/usize.rs"]
262 pub mod usize;
263
264 #[path = "num/f32.rs"]
265 pub mod f32;
266 #[path = "num/f64.rs"]
267 pub mod f64;
268
269 #[macro_use]
270 pub mod num;
271
272 /* The libcore prelude, not as all-encompassing as the libstd prelude */
273
274 pub mod prelude;
275
276 /* Core modules for ownership management */
277
278 pub mod hint;
279 pub mod intrinsics;
280 pub mod mem;
281 pub mod ptr;
282
283 /* Core language traits */
284
285 pub mod borrow;
286 pub mod clone;
287 pub mod cmp;
288 pub mod convert;
289 pub mod default;
290 pub mod marker;
291 pub mod ops;
292
293 /* Core types and methods on primitives */
294
295 pub mod any;
296 pub mod array;
297 pub mod ascii;
298 pub mod cell;
299 pub mod char;
300 pub mod ffi;
301 pub mod iter;
302 #[unstable(feature = "once_cell", issue = "74465")]
303 pub mod lazy;
304 pub mod option;
305 pub mod panic;
306 pub mod panicking;
307 pub mod pin;
308 pub mod result;
309 #[unstable(feature = "async_stream", issue = "79024")]
310 pub mod stream;
311 pub mod sync;
312
313 pub mod fmt;
314 pub mod hash;
315 pub mod slice;
316 pub mod str;
317 pub mod time;
318
319 pub mod unicode;
320
321 /* Async */
322 pub mod future;
323 pub mod task;
324
325 /* Heap memory allocator trait */
326 #[allow(missing_docs)]
327 pub mod alloc;
328
329 // note: does not need to be public
330 mod bool;
331 mod tuple;
332 mod unit;
333
334 #[stable(feature = "core_primitive", since = "1.43.0")]
335 pub mod primitive;
336
337 // Pull in the `core_arch` crate directly into libcore. The contents of
338 // `core_arch` are in a different repository: rust-lang/stdarch.
339 //
340 // `core_arch` depends on libcore, but the contents of this module are
341 // set up in such a way that directly pulling it here works such that the
342 // crate uses the this crate as its libcore.
343 #[path = "../../stdarch/crates/core_arch/src/mod.rs"]
344 #[allow(
345     missing_docs,
346     missing_debug_implementations,
347     dead_code,
348     unused_imports,
349     unsafe_op_in_unsafe_fn
350 )]
351 #[allow(rustdoc::bare_urls)]
352 // FIXME: This annotation should be moved into rust-lang/stdarch after clashing_extern_declarations is
353 // merged. It currently cannot because bootstrap fails as the lint hasn't been defined yet.
354 #[allow(clashing_extern_declarations)]
355 #[unstable(feature = "stdsimd", issue = "48556")]
356 mod core_arch;
357
358 #[doc = include_str!("../../stdarch/crates/core_arch/src/core_arch_docs.md")]
359 #[stable(feature = "simd_arch", since = "1.27.0")]
360 pub mod arch {
361     #[stable(feature = "simd_arch", since = "1.27.0")]
362     pub use crate::core_arch::arch::*;
363
364     /// Inline assembly.
365     ///
366     /// Read the [unstable book] for the usage.
367     ///
368     /// [unstable book]: ../../unstable-book/library-features/asm.html
369     #[unstable(
370         feature = "asm",
371         issue = "72016",
372         reason = "inline assembly is not stable enough for use and is subject to change"
373     )]
374     #[rustc_builtin_macro]
375     pub macro asm("assembly template", $(operands,)* $(options($(option),*))?) {
376         /* compiler built-in */
377     }
378
379     /// Module-level inline assembly.
380     #[unstable(
381         feature = "global_asm",
382         issue = "35119",
383         reason = "`global_asm!` is not stable enough for use and is subject to change"
384     )]
385     #[rustc_builtin_macro]
386     pub macro global_asm("assembly template", $(operands,)* $(options($(option),*))?) {
387         /* compiler built-in */
388     }
389 }
390
391 include!("primitive_docs.rs");