]> git.lizzy.rs Git - rust.git/blob - library/core/src/lib.rs
Rollup merge of #106661 - mjguzik:linux_statx, 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`, `strlen` - 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 core defines many fundamental lang items, all tests live in a
42 // separate crate, libcoretest (library/core/tests), 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 core) 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 core tests without x.py without ending up with two copies of core, 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 #![doc(cfg_hide(
64     not(test),
65     any(not(feature = "miri-test-libstd"), test, doctest),
66     no_fp_fmt_parse,
67     target_pointer_width = "16",
68     target_pointer_width = "32",
69     target_pointer_width = "64",
70     target_has_atomic = "8",
71     target_has_atomic = "16",
72     target_has_atomic = "32",
73     target_has_atomic = "64",
74     target_has_atomic = "ptr",
75     target_has_atomic_equal_alignment = "8",
76     target_has_atomic_equal_alignment = "16",
77     target_has_atomic_equal_alignment = "32",
78     target_has_atomic_equal_alignment = "64",
79     target_has_atomic_equal_alignment = "ptr",
80     target_has_atomic_load_store = "8",
81     target_has_atomic_load_store = "16",
82     target_has_atomic_load_store = "32",
83     target_has_atomic_load_store = "64",
84     target_has_atomic_load_store = "ptr",
85 ))]
86 #![no_core]
87 #![rustc_coherence_is_core]
88 //
89 // Lints:
90 #![deny(rust_2021_incompatible_or_patterns)]
91 #![deny(unsafe_op_in_unsafe_fn)]
92 #![deny(fuzzy_provenance_casts)]
93 #![warn(deprecated_in_future)]
94 #![warn(missing_debug_implementations)]
95 #![warn(missing_docs)]
96 #![allow(explicit_outlives_requirements)]
97 #![allow(incomplete_features)]
98 //
99 // Library features:
100 #![feature(const_align_offset)]
101 #![feature(const_align_of_val)]
102 #![feature(const_align_of_val_raw)]
103 #![feature(const_alloc_layout)]
104 #![feature(const_arguments_as_str)]
105 #![feature(const_array_into_iter_constructors)]
106 #![feature(const_bigint_helper_methods)]
107 #![feature(const_black_box)]
108 #![feature(const_caller_location)]
109 #![feature(const_cell_into_inner)]
110 #![feature(const_char_from_u32_unchecked)]
111 #![feature(const_clone)]
112 #![feature(const_cmp)]
113 #![feature(const_discriminant)]
114 #![feature(const_eval_select)]
115 #![feature(const_exact_div)]
116 #![feature(const_float_bits_conv)]
117 #![feature(const_float_classify)]
118 #![feature(const_fmt_arguments_new)]
119 #![feature(const_hash)]
120 #![feature(const_heap)]
121 #![feature(const_convert)]
122 #![feature(const_index_range_slice_index)]
123 #![feature(const_inherent_unchecked_arith)]
124 #![feature(const_int_unchecked_arith)]
125 #![feature(const_intrinsic_forget)]
126 #![feature(const_likely)]
127 #![feature(const_maybe_uninit_uninit_array)]
128 #![feature(const_maybe_uninit_as_mut_ptr)]
129 #![feature(const_maybe_uninit_assume_init)]
130 #![feature(const_nonnull_new)]
131 #![feature(const_num_from_num)]
132 #![feature(const_ops)]
133 #![feature(const_option)]
134 #![feature(const_option_ext)]
135 #![feature(const_pin)]
136 #![feature(const_pointer_is_aligned)]
137 #![feature(const_ptr_sub_ptr)]
138 #![feature(const_replace)]
139 #![feature(const_result_drop)]
140 #![feature(const_ptr_as_ref)]
141 #![feature(const_ptr_is_null)]
142 #![feature(const_ptr_read)]
143 #![feature(const_ptr_write)]
144 #![feature(const_raw_ptr_comparison)]
145 #![feature(const_size_of_val)]
146 #![feature(const_size_of_val_raw)]
147 #![feature(const_slice_from_raw_parts_mut)]
148 #![feature(const_slice_ptr_len)]
149 #![feature(const_slice_split_at_mut)]
150 #![feature(const_str_from_utf8_unchecked_mut)]
151 #![feature(const_swap)]
152 #![feature(const_trait_impl)]
153 #![feature(const_try)]
154 #![feature(const_type_id)]
155 #![feature(const_type_name)]
156 #![feature(const_default_impls)]
157 #![feature(const_unicode_case_lookup)]
158 #![feature(const_unsafecell_get_mut)]
159 #![feature(const_waker)]
160 #![feature(core_panic)]
161 #![feature(char_indices_offset)]
162 #![feature(duration_consts_float)]
163 #![feature(maybe_uninit_uninit_array)]
164 #![feature(ptr_alignment_type)]
165 #![feature(ptr_metadata)]
166 #![feature(set_ptr_value)]
167 #![feature(slice_ptr_get)]
168 #![feature(slice_split_at_unchecked)]
169 #![feature(str_internals)]
170 #![feature(str_split_remainder)]
171 #![feature(str_split_inclusive_remainder)]
172 #![feature(strict_provenance)]
173 #![feature(utf16_extra)]
174 #![feature(utf16_extra_const)]
175 #![feature(variant_count)]
176 #![feature(const_array_from_ref)]
177 #![feature(const_slice_from_ref)]
178 #![feature(const_slice_index)]
179 #![feature(const_is_char_boundary)]
180 #![feature(const_cstr_methods)]
181 #![feature(is_ascii_octdigit)]
182 //
183 // Language features:
184 #![feature(abi_unadjusted)]
185 #![feature(adt_const_params)]
186 #![feature(allow_internal_unsafe)]
187 #![feature(allow_internal_unstable)]
188 #![feature(associated_type_bounds)]
189 #![feature(auto_traits)]
190 #![feature(c_unwind)]
191 #![feature(cfg_sanitize)]
192 #![feature(cfg_target_has_atomic)]
193 #![feature(cfg_target_has_atomic_equal_alignment)]
194 #![cfg_attr(not(bootstrap), feature(const_closures))]
195 #![feature(const_fn_floating_point_arithmetic)]
196 #![feature(const_mut_refs)]
197 #![feature(const_precise_live_drops)]
198 #![feature(const_refs_to_cell)]
199 #![feature(decl_macro)]
200 #![feature(deprecated_suggestion)]
201 #![feature(derive_const)]
202 #![feature(doc_cfg)]
203 #![feature(doc_notable_trait)]
204 #![feature(rustdoc_internals)]
205 #![feature(exhaustive_patterns)]
206 #![feature(doc_cfg_hide)]
207 #![feature(extern_types)]
208 #![feature(fundamental)]
209 #![feature(if_let_guard)]
210 #![feature(inline_const)]
211 #![feature(intra_doc_pointers)]
212 #![feature(intrinsics)]
213 #![feature(lang_items)]
214 #![feature(link_llvm_intrinsics)]
215 #![feature(macro_metavar_expr)]
216 #![feature(min_specialization)]
217 #![feature(must_not_suspend)]
218 #![feature(negative_impls)]
219 #![feature(never_type)]
220 #![feature(no_core)]
221 #![feature(no_coverage)] // rust-lang/rust#84605
222 #![feature(platform_intrinsics)]
223 #![feature(prelude_import)]
224 #![feature(repr_simd)]
225 #![feature(rustc_allow_const_fn_unstable)]
226 #![feature(rustc_attrs)]
227 #![feature(simd_ffi)]
228 #![feature(staged_api)]
229 #![feature(stmt_expr_attributes)]
230 #![feature(target_feature_11)]
231 #![feature(trait_alias)]
232 #![feature(transparent_unions)]
233 #![feature(try_blocks)]
234 #![feature(unboxed_closures)]
235 #![feature(unsized_fn_params)]
236 #![feature(asm_const)]
237 #![feature(const_transmute_copy)]
238 //
239 // Target features:
240 #![feature(arm_target_feature)]
241 #![feature(avx512_target_feature)]
242 #![feature(cmpxchg16b_target_feature)]
243 #![feature(hexagon_target_feature)]
244 #![feature(mips_target_feature)]
245 #![feature(powerpc_target_feature)]
246 #![feature(riscv_target_feature)]
247 #![feature(rtm_target_feature)]
248 #![feature(sse4a_target_feature)]
249 #![feature(tbm_target_feature)]
250 #![feature(wasm_target_feature)]
251 #![cfg_attr(bootstrap, feature(f16c_target_feature))]
252
253 // allow using `core::` in intra-doc links
254 #[allow(unused_extern_crates)]
255 extern crate self as core;
256
257 #[prelude_import]
258 #[allow(unused)]
259 use prelude::v1::*;
260
261 #[cfg(not(test))] // See #65860
262 #[macro_use]
263 mod macros;
264
265 // We don't export this through #[macro_export] for now, to avoid breakage.
266 // See https://github.com/rust-lang/rust/issues/82913
267 #[cfg(not(test))]
268 #[unstable(feature = "assert_matches", issue = "82775")]
269 /// Unstable module containing the unstable `assert_matches` macro.
270 pub mod assert_matches {
271     #[unstable(feature = "assert_matches", issue = "82775")]
272     pub use crate::macros::{assert_matches, debug_assert_matches};
273 }
274
275 #[macro_use]
276 mod internal_macros;
277
278 #[path = "num/shells/int_macros.rs"]
279 #[macro_use]
280 mod int_macros;
281
282 #[path = "num/shells/i128.rs"]
283 pub mod i128;
284 #[path = "num/shells/i16.rs"]
285 pub mod i16;
286 #[path = "num/shells/i32.rs"]
287 pub mod i32;
288 #[path = "num/shells/i64.rs"]
289 pub mod i64;
290 #[path = "num/shells/i8.rs"]
291 pub mod i8;
292 #[path = "num/shells/isize.rs"]
293 pub mod isize;
294
295 #[path = "num/shells/u128.rs"]
296 pub mod u128;
297 #[path = "num/shells/u16.rs"]
298 pub mod u16;
299 #[path = "num/shells/u32.rs"]
300 pub mod u32;
301 #[path = "num/shells/u64.rs"]
302 pub mod u64;
303 #[path = "num/shells/u8.rs"]
304 pub mod u8;
305 #[path = "num/shells/usize.rs"]
306 pub mod usize;
307
308 #[path = "num/f32.rs"]
309 pub mod f32;
310 #[path = "num/f64.rs"]
311 pub mod f64;
312
313 #[macro_use]
314 pub mod num;
315
316 /* The core prelude, not as all-encompassing as the std prelude */
317
318 pub mod prelude;
319
320 /* Core modules for ownership management */
321
322 pub mod hint;
323 pub mod intrinsics;
324 pub mod mem;
325 pub mod ptr;
326
327 /* Core language traits */
328
329 pub mod borrow;
330 pub mod clone;
331 pub mod cmp;
332 pub mod convert;
333 pub mod default;
334 pub mod error;
335 pub mod marker;
336 pub mod ops;
337
338 /* Core types and methods on primitives */
339
340 pub mod any;
341 pub mod array;
342 pub mod ascii;
343 pub mod asserting;
344 #[unstable(feature = "async_iterator", issue = "79024")]
345 pub mod async_iter;
346 pub mod cell;
347 pub mod char;
348 pub mod ffi;
349 pub mod iter;
350 pub mod option;
351 pub mod panic;
352 pub mod panicking;
353 pub mod pin;
354 pub mod result;
355 pub mod sync;
356
357 pub mod fmt;
358 pub mod hash;
359 pub mod slice;
360 pub mod str;
361 pub mod time;
362
363 pub mod unicode;
364
365 /* Async */
366 pub mod future;
367 pub mod task;
368
369 /* Heap memory allocator trait */
370 #[allow(missing_docs)]
371 pub mod alloc;
372
373 // note: does not need to be public
374 mod bool;
375 mod tuple;
376 mod unit;
377
378 mod const_closure;
379
380 #[stable(feature = "core_primitive", since = "1.43.0")]
381 pub mod primitive;
382
383 // Pull in the `core_arch` crate directly into core. The contents of
384 // `core_arch` are in a different repository: rust-lang/stdarch.
385 //
386 // `core_arch` depends on core, but the contents of this module are
387 // set up in such a way that directly pulling it here works such that the
388 // crate uses the this crate as its core.
389 #[path = "../../stdarch/crates/core_arch/src/mod.rs"]
390 #[allow(
391     missing_docs,
392     missing_debug_implementations,
393     dead_code,
394     unused_imports,
395     unsafe_op_in_unsafe_fn
396 )]
397 #[allow(rustdoc::bare_urls)]
398 // FIXME: This annotation should be moved into rust-lang/stdarch after clashing_extern_declarations is
399 // merged. It currently cannot because bootstrap fails as the lint hasn't been defined yet.
400 #[allow(clashing_extern_declarations)]
401 #[unstable(feature = "stdsimd", issue = "48556")]
402 mod core_arch;
403
404 #[stable(feature = "simd_arch", since = "1.27.0")]
405 pub mod arch;
406
407 // Pull in the `core_simd` crate directly into core. The contents of
408 // `core_simd` are in a different repository: rust-lang/portable-simd.
409 //
410 // `core_simd` depends on core, but the contents of this module are
411 // set up in such a way that directly pulling it here works such that the
412 // crate uses this crate as its core.
413 #[path = "../../portable-simd/crates/core_simd/src/mod.rs"]
414 #[allow(missing_debug_implementations, dead_code, unsafe_op_in_unsafe_fn, unused_unsafe)]
415 #[allow(rustdoc::bare_urls)]
416 #[unstable(feature = "portable_simd", issue = "86656")]
417 mod core_simd;
418
419 #[doc = include_str!("../../portable-simd/crates/core_simd/src/core_simd_docs.md")]
420 #[unstable(feature = "portable_simd", issue = "86656")]
421 pub mod simd {
422     #[unstable(feature = "portable_simd", issue = "86656")]
423     pub use crate::core_simd::simd::*;
424 }
425
426 include!("primitive_docs.rs");