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`, `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).
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)))
65 any(not(feature = "miri-test-libstd"), test, doctest),
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",
87 #![rustc_coherence_is_core]
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)]
100 #![feature(const_align_offset)]
101 #![feature(const_align_of_val)]
102 #![feature(const_arguments_as_str)]
103 #![feature(const_array_into_iter_constructors)]
104 #![feature(const_bigint_helper_methods)]
105 #![feature(const_black_box)]
106 #![feature(const_caller_location)]
107 #![feature(const_cell_into_inner)]
108 #![feature(const_char_from_u32_unchecked)]
109 #![feature(const_clone)]
110 #![feature(const_cmp)]
111 #![feature(const_discriminant)]
112 #![feature(const_eval_select)]
113 #![feature(const_exact_div)]
114 #![feature(const_float_bits_conv)]
115 #![feature(const_float_classify)]
116 #![feature(const_fmt_arguments_new)]
117 #![feature(const_hash)]
118 #![feature(const_heap)]
119 #![feature(const_convert)]
120 #![feature(const_index_range_slice_index)]
121 #![feature(const_inherent_unchecked_arith)]
122 #![feature(const_int_unchecked_arith)]
123 #![feature(const_intrinsic_forget)]
124 #![feature(const_likely)]
125 #![feature(const_maybe_uninit_uninit_array)]
126 #![feature(const_maybe_uninit_as_mut_ptr)]
127 #![feature(const_maybe_uninit_assume_init)]
128 #![feature(const_nonnull_new)]
129 #![feature(const_num_from_num)]
130 #![feature(const_ops)]
131 #![feature(const_option)]
132 #![feature(const_option_ext)]
133 #![feature(const_pin)]
134 #![feature(const_pointer_is_aligned)]
135 #![feature(const_ptr_sub_ptr)]
136 #![feature(const_replace)]
137 #![feature(const_result_drop)]
138 #![feature(const_ptr_as_ref)]
139 #![feature(const_ptr_is_null)]
140 #![feature(const_ptr_read)]
141 #![feature(const_ptr_write)]
142 #![feature(const_raw_ptr_comparison)]
143 #![feature(const_size_of_val)]
144 #![feature(const_slice_from_raw_parts_mut)]
145 #![feature(const_slice_ptr_len)]
146 #![feature(const_slice_split_at_mut)]
147 #![feature(const_str_from_utf8_unchecked_mut)]
148 #![feature(const_swap)]
149 #![feature(const_trait_impl)]
150 #![feature(const_try)]
151 #![feature(const_type_id)]
152 #![feature(const_type_name)]
153 #![feature(const_default_impls)]
154 #![feature(const_unicode_case_lookup)]
155 #![feature(const_unsafecell_get_mut)]
156 #![feature(const_waker)]
157 #![feature(core_panic)]
158 #![feature(duration_consts_float)]
159 #![feature(maybe_uninit_uninit_array)]
160 #![feature(ptr_alignment_type)]
161 #![feature(ptr_metadata)]
162 #![feature(set_ptr_value)]
163 #![feature(slice_ptr_get)]
164 #![feature(slice_split_at_unchecked)]
165 #![feature(str_internals)]
166 #![feature(strict_provenance)]
167 #![feature(utf16_extra)]
168 #![feature(utf16_extra_const)]
169 #![feature(variant_count)]
170 #![feature(const_array_from_ref)]
171 #![feature(const_slice_from_ref)]
172 #![feature(const_slice_index)]
173 #![feature(const_is_char_boundary)]
174 #![feature(const_cstr_methods)]
175 #![feature(is_ascii_octdigit)]
177 // Language features:
178 #![feature(abi_unadjusted)]
179 #![feature(adt_const_params)]
180 #![feature(allow_internal_unsafe)]
181 #![feature(allow_internal_unstable)]
182 #![feature(associated_type_bounds)]
183 #![feature(auto_traits)]
184 #![feature(c_unwind)]
185 #![feature(cfg_sanitize)]
186 #![feature(cfg_target_has_atomic)]
187 #![feature(cfg_target_has_atomic_equal_alignment)]
188 #![feature(const_fn_floating_point_arithmetic)]
189 #![feature(const_mut_refs)]
190 #![feature(const_precise_live_drops)]
191 #![feature(const_refs_to_cell)]
192 #![feature(decl_macro)]
193 #![feature(deprecated_suggestion)]
194 #![cfg_attr(not(bootstrap), feature(derive_const))]
196 #![feature(doc_notable_trait)]
197 #![feature(rustdoc_internals)]
198 #![feature(exhaustive_patterns)]
199 #![feature(doc_cfg_hide)]
200 #![feature(extern_types)]
201 #![feature(fundamental)]
202 #![feature(if_let_guard)]
203 #![feature(inline_const)]
204 #![feature(intra_doc_pointers)]
205 #![feature(intrinsics)]
206 #![feature(lang_items)]
207 #![feature(link_llvm_intrinsics)]
208 #![feature(macro_metavar_expr)]
209 #![feature(min_specialization)]
210 #![feature(must_not_suspend)]
211 #![feature(negative_impls)]
212 #![feature(never_type)]
214 #![feature(no_coverage)] // rust-lang/rust#84605
215 #![feature(platform_intrinsics)]
216 #![feature(prelude_import)]
217 #![feature(repr_simd)]
218 #![feature(rustc_allow_const_fn_unstable)]
219 #![feature(rustc_attrs)]
220 #![feature(simd_ffi)]
221 #![feature(staged_api)]
222 #![feature(stmt_expr_attributes)]
223 #![feature(target_feature_11)]
224 #![feature(trait_alias)]
225 #![feature(transparent_unions)]
226 #![feature(try_blocks)]
227 #![feature(unboxed_closures)]
228 #![feature(unsized_fn_params)]
229 #![feature(asm_const)]
230 #![feature(const_transmute_copy)]
233 #![feature(arm_target_feature)]
234 #![feature(avx512_target_feature)]
235 #![feature(cmpxchg16b_target_feature)]
236 #![feature(f16c_target_feature)]
237 #![feature(hexagon_target_feature)]
238 #![feature(mips_target_feature)]
239 #![feature(powerpc_target_feature)]
240 #![feature(riscv_target_feature)]
241 #![feature(rtm_target_feature)]
242 #![feature(sse4a_target_feature)]
243 #![feature(tbm_target_feature)]
244 #![feature(wasm_target_feature)]
246 // allow using `core::` in intra-doc links
247 #[allow(unused_extern_crates)]
248 extern crate self as core;
254 #[cfg(not(test))] // See #65860
258 // We don't export this through #[macro_export] for now, to avoid breakage.
259 // See https://github.com/rust-lang/rust/issues/82913
261 #[unstable(feature = "assert_matches", issue = "82775")]
262 /// Unstable module containing the unstable `assert_matches` macro.
263 pub mod assert_matches {
264 #[unstable(feature = "assert_matches", issue = "82775")]
265 pub use crate::macros::{assert_matches, debug_assert_matches};
271 #[path = "num/shells/int_macros.rs"]
275 #[path = "num/shells/i128.rs"]
277 #[path = "num/shells/i16.rs"]
279 #[path = "num/shells/i32.rs"]
281 #[path = "num/shells/i64.rs"]
283 #[path = "num/shells/i8.rs"]
285 #[path = "num/shells/isize.rs"]
288 #[path = "num/shells/u128.rs"]
290 #[path = "num/shells/u16.rs"]
292 #[path = "num/shells/u32.rs"]
294 #[path = "num/shells/u64.rs"]
296 #[path = "num/shells/u8.rs"]
298 #[path = "num/shells/usize.rs"]
301 #[path = "num/f32.rs"]
303 #[path = "num/f64.rs"]
309 /* The libcore prelude, not as all-encompassing as the libstd prelude */
313 /* Core modules for ownership management */
320 /* Core language traits */
331 /* Core types and methods on primitives */
337 #[unstable(feature = "async_iterator", issue = "79024")]
362 /* Heap memory allocator trait */
363 #[allow(missing_docs)]
366 // note: does not need to be public
373 #[stable(feature = "core_primitive", since = "1.43.0")]
376 // Pull in the `core_arch` crate directly into libcore. The contents of
377 // `core_arch` are in a different repository: rust-lang/stdarch.
379 // `core_arch` depends on libcore, but the contents of this module are
380 // set up in such a way that directly pulling it here works such that the
381 // crate uses the this crate as its libcore.
382 #[path = "../../stdarch/crates/core_arch/src/mod.rs"]
385 missing_debug_implementations,
388 unsafe_op_in_unsafe_fn
390 #[allow(rustdoc::bare_urls)]
391 // FIXME: This annotation should be moved into rust-lang/stdarch after clashing_extern_declarations is
392 // merged. It currently cannot because bootstrap fails as the lint hasn't been defined yet.
393 #[allow(clashing_extern_declarations)]
394 #[unstable(feature = "stdsimd", issue = "48556")]
397 #[stable(feature = "simd_arch", since = "1.27.0")]
400 // Pull in the `core_simd` crate directly into libcore. The contents of
401 // `core_simd` are in a different repository: rust-lang/portable-simd.
403 // `core_simd` depends on libcore, but the contents of this module are
404 // set up in such a way that directly pulling it here works such that the
405 // crate uses this crate as its libcore.
406 #[path = "../../portable-simd/crates/core_simd/src/mod.rs"]
407 #[allow(missing_debug_implementations, dead_code, unsafe_op_in_unsafe_fn, unused_unsafe)]
408 #[allow(rustdoc::bare_urls)]
409 #[unstable(feature = "portable_simd", issue = "86656")]
412 #[doc = include_str!("../../portable-simd/crates/core_simd/src/core_simd_docs.md")]
413 #[unstable(feature = "portable_simd", issue = "86656")]
415 #[unstable(feature = "portable_simd", issue = "86656")]
416 pub use crate::core_simd::simd::*;
419 include!("primitive_docs.rs");