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 core defines many fundamental lang items, all tests live in a
42 // separate crate, libcoretest (library/core/tests), 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 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.
50 // This cfg won't affect doc tests.
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")]
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_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)]
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 #![feature(const_fn_floating_point_arithmetic)]
195 #![feature(const_mut_refs)]
196 #![feature(const_precise_live_drops)]
197 #![feature(const_refs_to_cell)]
198 #![feature(decl_macro)]
199 #![feature(deprecated_suggestion)]
200 #![feature(derive_const)]
202 #![feature(doc_notable_trait)]
203 #![feature(rustdoc_internals)]
204 #![feature(exhaustive_patterns)]
205 #![feature(doc_cfg_hide)]
206 #![feature(extern_types)]
207 #![feature(fundamental)]
208 #![feature(if_let_guard)]
209 #![feature(inline_const)]
210 #![feature(intra_doc_pointers)]
211 #![feature(intrinsics)]
212 #![feature(lang_items)]
213 #![feature(link_llvm_intrinsics)]
214 #![feature(macro_metavar_expr)]
215 #![feature(min_specialization)]
216 #![feature(must_not_suspend)]
217 #![feature(negative_impls)]
218 #![feature(never_type)]
220 #![feature(no_coverage)] // rust-lang/rust#84605
221 #![feature(platform_intrinsics)]
222 #![feature(prelude_import)]
223 #![feature(repr_simd)]
224 #![feature(rustc_allow_const_fn_unstable)]
225 #![feature(rustc_attrs)]
226 #![feature(simd_ffi)]
227 #![feature(staged_api)]
228 #![feature(stmt_expr_attributes)]
229 #![feature(target_feature_11)]
230 #![feature(trait_alias)]
231 #![feature(transparent_unions)]
232 #![feature(try_blocks)]
233 #![feature(unboxed_closures)]
234 #![feature(unsized_fn_params)]
235 #![feature(asm_const)]
236 #![feature(const_transmute_copy)]
239 #![feature(arm_target_feature)]
240 #![feature(avx512_target_feature)]
241 #![feature(cmpxchg16b_target_feature)]
242 #![feature(f16c_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)]
252 // allow using `core::` in intra-doc links
253 #[allow(unused_extern_crates)]
254 extern crate self as core;
260 #[cfg(not(test))] // See #65860
264 // We don't export this through #[macro_export] for now, to avoid breakage.
265 // See https://github.com/rust-lang/rust/issues/82913
267 #[unstable(feature = "assert_matches", issue = "82775")]
268 /// Unstable module containing the unstable `assert_matches` macro.
269 pub mod assert_matches {
270 #[unstable(feature = "assert_matches", issue = "82775")]
271 pub use crate::macros::{assert_matches, debug_assert_matches};
277 #[path = "num/shells/int_macros.rs"]
281 #[path = "num/shells/i128.rs"]
283 #[path = "num/shells/i16.rs"]
285 #[path = "num/shells/i32.rs"]
287 #[path = "num/shells/i64.rs"]
289 #[path = "num/shells/i8.rs"]
291 #[path = "num/shells/isize.rs"]
294 #[path = "num/shells/u128.rs"]
296 #[path = "num/shells/u16.rs"]
298 #[path = "num/shells/u32.rs"]
300 #[path = "num/shells/u64.rs"]
302 #[path = "num/shells/u8.rs"]
304 #[path = "num/shells/usize.rs"]
307 #[path = "num/f32.rs"]
309 #[path = "num/f64.rs"]
315 /* The core prelude, not as all-encompassing as the std prelude */
319 /* Core modules for ownership management */
326 /* Core language traits */
337 /* Core types and methods on primitives */
343 #[unstable(feature = "async_iterator", issue = "79024")]
368 /* Heap memory allocator trait */
369 #[allow(missing_docs)]
372 // note: does not need to be public
379 #[stable(feature = "core_primitive", since = "1.43.0")]
382 // Pull in the `core_arch` crate directly into core. The contents of
383 // `core_arch` are in a different repository: rust-lang/stdarch.
385 // `core_arch` depends on core, but the contents of this module are
386 // set up in such a way that directly pulling it here works such that the
387 // crate uses the this crate as its core.
388 #[path = "../../stdarch/crates/core_arch/src/mod.rs"]
391 missing_debug_implementations,
394 unsafe_op_in_unsafe_fn
396 #[allow(rustdoc::bare_urls)]
397 // FIXME: This annotation should be moved into rust-lang/stdarch after clashing_extern_declarations is
398 // merged. It currently cannot because bootstrap fails as the lint hasn't been defined yet.
399 #[allow(clashing_extern_declarations)]
400 #[unstable(feature = "stdsimd", issue = "48556")]
403 #[stable(feature = "simd_arch", since = "1.27.0")]
406 // Pull in the `core_simd` crate directly into core. The contents of
407 // `core_simd` are in a different repository: rust-lang/portable-simd.
409 // `core_simd` depends on core, but the contents of this module are
410 // set up in such a way that directly pulling it here works such that the
411 // crate uses this crate as its core.
412 #[path = "../../portable-simd/crates/core_simd/src/mod.rs"]
413 #[allow(missing_debug_implementations, dead_code, unsafe_op_in_unsafe_fn, unused_unsafe)]
414 #[allow(rustdoc::bare_urls)]
415 #[unstable(feature = "portable_simd", issue = "86656")]
418 #[doc = include_str!("../../portable-simd/crates/core_simd/src/core_simd_docs.md")]
419 #[unstable(feature = "portable_simd", issue = "86656")]
421 #[unstable(feature = "portable_simd", issue = "86656")]
422 pub use crate::core_simd::simd::*;
425 include!("primitive_docs.rs");