1 //! # The Rust Core Library
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.
9 //! [^free]: Strictly speaking, there are some symbols which are needed but
10 //! they aren't always necessary.
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.
16 //! # How to use the core library
18 //! Please note that all of these details are currently not considered stable.
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:
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).
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`.
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`.
41 // Since libcore defines many fundamental lang items, all tests live in a
42 // separate crate, libcoretest, to avoid bizarre issues.
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.
50 // This cfg won't affect doc tests.
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")]
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)))
64 #![warn(deprecated_in_future)]
65 #![warn(missing_docs)]
66 #![warn(missing_debug_implementations)]
67 #![allow(explicit_outlives_requirements)]
68 #![feature(rustc_allow_const_fn_unstable)]
69 #![feature(allow_internal_unstable)]
70 #![feature(arbitrary_self_types)]
72 #![feature(bool_to_option)]
73 #![feature(cfg_target_has_atomic)]
74 #![feature(const_heap)]
75 #![feature(const_alloc_layout)]
76 #![feature(const_arguments_as_str)]
77 #![feature(const_assert_type)]
78 #![feature(const_discriminant)]
79 #![feature(const_cell_into_inner)]
80 #![feature(const_intrinsic_copy)]
81 #![feature(const_intrinsic_forget)]
82 #![feature(const_float_classify)]
83 #![feature(const_float_bits_conv)]
84 #![feature(const_int_unchecked_arith)]
85 #![feature(const_inherent_unchecked_arith)]
86 #![feature(const_mut_refs)]
87 #![feature(const_refs_to_cell)]
88 #![feature(const_panic)]
89 #![feature(const_pin)]
90 #![cfg_attr(bootstrap, feature(const_fn_union))]
91 #![feature(const_impl_trait)]
92 #![feature(const_fn_floating_point_arithmetic)]
93 #![feature(const_fn_fn_ptr_basics)]
94 #![feature(const_fn_trait_bound)]
95 #![feature(const_option)]
96 #![feature(const_precise_live_drops)]
97 #![feature(const_ptr_offset)]
98 #![feature(const_ptr_offset_from)]
99 #![feature(const_ptr_read)]
100 #![feature(const_ptr_write)]
101 #![feature(const_raw_ptr_comparison)]
102 #![feature(const_raw_ptr_deref)]
103 #![feature(const_slice_from_raw_parts)]
104 #![feature(const_slice_ptr_len)]
105 #![feature(const_size_of_val)]
106 #![feature(const_swap)]
107 #![feature(const_align_of_val)]
108 #![feature(const_type_id)]
109 #![feature(const_type_name)]
110 #![feature(const_likely)]
111 #![feature(const_unreachable_unchecked)]
112 #![feature(const_maybe_uninit_assume_init)]
113 #![feature(const_maybe_uninit_as_ptr)]
114 #![feature(custom_inner_attributes)]
115 #![feature(decl_macro)]
117 #![feature(doc_notable_trait)]
118 #![feature(duration_consts_2)]
119 #![feature(extern_types)]
120 #![feature(fundamental)]
121 #![feature(intra_doc_pointers)]
122 #![feature(intrinsics)]
123 #![feature(lang_items)]
124 #![feature(link_llvm_intrinsics)]
125 #![feature(llvm_asm)]
126 #![feature(negative_impls)]
127 #![feature(never_type)]
129 #![feature(exhaustive_patterns)]
131 #![feature(auto_traits)]
132 #![feature(pin_deref_mut)]
133 #![feature(prelude_import)]
134 #![feature(ptr_metadata)]
135 #![feature(repr_simd, platform_intrinsics)]
136 #![feature(rustc_attrs)]
137 #![feature(simd_ffi)]
138 #![feature(min_specialization)]
139 #![feature(staged_api)]
140 #![feature(std_internals)]
141 #![feature(stmt_expr_attributes)]
142 #![feature(str_split_as_str)]
143 #![feature(str_split_inclusive_as_str)]
144 #![feature(char_indices_offset)]
145 #![feature(trait_alias)]
146 #![feature(transparent_unions)]
147 #![feature(try_blocks)]
148 #![feature(unboxed_closures)]
149 #![feature(unsized_fn_params)]
150 #![feature(unwind_attributes)]
151 #![feature(variant_count)]
152 #![feature(tbm_target_feature)]
153 #![feature(sse4a_target_feature)]
154 #![feature(arm_target_feature)]
155 #![feature(powerpc_target_feature)]
156 #![feature(mips_target_feature)]
157 #![feature(aarch64_target_feature)]
158 #![feature(wasm_target_feature)]
159 #![feature(avx512_target_feature)]
160 #![feature(cmpxchg16b_target_feature)]
161 #![feature(rtm_target_feature)]
162 #![feature(f16c_target_feature)]
163 #![feature(hexagon_target_feature)]
164 #![cfg_attr(bootstrap, feature(const_fn_transmute))]
165 #![feature(abi_unadjusted)]
166 #![feature(adx_target_feature)]
167 #![feature(associated_type_bounds)]
168 #![feature(const_caller_location)]
169 #![feature(slice_ptr_get)]
170 #![feature(no_niche)] // rust-lang/rust#68303
171 #![feature(no_coverage)] // rust-lang/rust#84605
172 #![deny(unsafe_op_in_unsafe_fn)]
173 #![deny(rust_2021_incompatible_or_patterns)]
175 // allow using `core::` in intra-doc links
176 #[allow(unused_extern_crates)]
177 extern crate self as core;
183 #[cfg(not(test))] // See #65860
187 // We don't export this through #[macro_export] for now, to avoid breakage.
188 // See https://github.com/rust-lang/rust/issues/82913
190 #[unstable(feature = "assert_matches", issue = "82775")]
191 /// Unstable module containing the unstable `assert_matches` macro.
192 pub mod assert_matches {
193 #[unstable(feature = "assert_matches", issue = "82775")]
194 pub use crate::macros::{assert_matches, debug_assert_matches};
200 #[path = "num/shells/int_macros.rs"]
204 #[path = "num/shells/i128.rs"]
206 #[path = "num/shells/i16.rs"]
208 #[path = "num/shells/i32.rs"]
210 #[path = "num/shells/i64.rs"]
212 #[path = "num/shells/i8.rs"]
214 #[path = "num/shells/isize.rs"]
217 #[path = "num/shells/u128.rs"]
219 #[path = "num/shells/u16.rs"]
221 #[path = "num/shells/u32.rs"]
223 #[path = "num/shells/u64.rs"]
225 #[path = "num/shells/u8.rs"]
227 #[path = "num/shells/usize.rs"]
230 #[path = "num/f32.rs"]
232 #[path = "num/f64.rs"]
238 /* The libcore prelude, not as all-encompassing as the libstd prelude */
242 /* Core modules for ownership management */
249 /* Core language traits */
259 /* Core types and methods on primitives */
268 #[unstable(feature = "once_cell", issue = "74465")]
275 #[unstable(feature = "async_stream", issue = "79024")]
291 /* Heap memory allocator trait */
292 #[allow(missing_docs)]
295 // note: does not need to be public
300 #[stable(feature = "core_primitive", since = "1.43.0")]
303 // Pull in the `core_arch` crate directly into libcore. The contents of
304 // `core_arch` are in a different repository: rust-lang/stdarch.
306 // `core_arch` depends on libcore, but the contents of this module are
307 // set up in such a way that directly pulling it here works such that the
308 // crate uses the this crate as its libcore.
309 #[path = "../../stdarch/crates/core_arch/src/mod.rs"]
312 missing_debug_implementations,
315 unsafe_op_in_unsafe_fn
317 #[allow(rustdoc::bare_urls)]
318 // FIXME: This annotation should be moved into rust-lang/stdarch after clashing_extern_declarations is
319 // merged. It currently cannot because bootstrap fails as the lint hasn't been defined yet.
320 #[allow(clashing_extern_declarations)]
321 #[unstable(feature = "stdsimd", issue = "48556")]
324 #[doc = include_str!("../../stdarch/crates/core_arch/src/core_arch_docs.md")]
325 #[stable(feature = "simd_arch", since = "1.27.0")]
327 #[stable(feature = "simd_arch", since = "1.27.0")]
328 pub use crate::core_arch::arch::*;
332 /// Read the [unstable book] for the usage.
334 /// [unstable book]: ../../unstable-book/library-features/asm.html
338 reason = "inline assembly is not stable enough for use and is subject to change"
340 #[rustc_builtin_macro]
341 pub macro asm("assembly template", $(operands,)* $(options($(option),*))?) {
342 /* compiler built-in */
345 /// Module-level inline assembly.
347 feature = "global_asm",
349 reason = "`global_asm!` is not stable enough for use and is subject to change"
351 #[rustc_builtin_macro]
352 pub macro global_asm("assembly template", $(operands,)* $(options($(option),*))?) {
353 /* compiler built-in */