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 #![warn(deprecated_in_future)]
93 #![warn(missing_debug_implementations)]
94 #![warn(missing_docs)]
95 #![allow(explicit_outlives_requirements)]
96 #![allow(incomplete_features)]
99 #![feature(const_align_offset)]
100 #![feature(const_align_of_val)]
101 #![feature(const_arguments_as_str)]
102 #![feature(const_array_into_iter_constructors)]
103 #![feature(const_bigint_helper_methods)]
104 #![feature(const_black_box)]
105 #![feature(const_caller_location)]
106 #![feature(const_cell_into_inner)]
107 #![feature(const_char_convert)]
108 #![feature(const_clone)]
109 #![feature(const_cmp)]
110 #![feature(const_discriminant)]
111 #![feature(const_eval_select)]
112 #![feature(const_float_bits_conv)]
113 #![feature(const_float_classify)]
114 #![feature(const_fmt_arguments_new)]
115 #![feature(const_heap)]
116 #![feature(const_convert)]
117 #![feature(const_index_range_slice_index)]
118 #![feature(const_inherent_unchecked_arith)]
119 #![feature(const_int_unchecked_arith)]
120 #![feature(const_intrinsic_forget)]
121 #![feature(const_likely)]
122 #![feature(const_maybe_uninit_uninit_array)]
123 #![feature(const_maybe_uninit_as_mut_ptr)]
124 #![feature(const_maybe_uninit_assume_init)]
125 #![feature(const_nonnull_new)]
126 #![feature(const_num_from_num)]
127 #![feature(const_ops)]
128 #![feature(const_option)]
129 #![feature(const_option_ext)]
130 #![feature(const_pin)]
131 #![feature(const_ptr_sub_ptr)]
132 #![feature(const_replace)]
133 #![feature(const_ptr_as_ref)]
134 #![feature(const_ptr_is_null)]
135 #![feature(const_ptr_read)]
136 #![feature(const_ptr_write)]
137 #![feature(const_raw_ptr_comparison)]
138 #![feature(const_size_of_val)]
139 #![feature(const_slice_from_raw_parts_mut)]
140 #![feature(const_slice_ptr_len)]
141 #![feature(const_slice_split_at_mut)]
142 #![feature(const_str_from_utf8_unchecked_mut)]
143 #![feature(const_swap)]
144 #![feature(const_trait_impl)]
145 #![feature(const_try)]
146 #![feature(const_type_id)]
147 #![feature(const_type_name)]
148 #![feature(const_default_impls)]
149 #![feature(const_unicode_case_lookup)]
150 #![feature(const_unsafecell_get_mut)]
151 #![feature(const_waker)]
152 #![feature(core_panic)]
153 #![feature(duration_consts_float)]
154 #![feature(maybe_uninit_uninit_array)]
155 #![feature(ptr_metadata)]
156 #![feature(slice_ptr_get)]
157 #![feature(slice_split_at_unchecked)]
158 #![feature(str_internals)]
159 #![feature(utf16_extra)]
160 #![feature(utf16_extra_const)]
161 #![feature(variant_count)]
162 #![feature(const_array_from_ref)]
163 #![feature(const_slice_from_ref)]
164 #![feature(const_slice_index)]
165 #![feature(const_is_char_boundary)]
166 #![feature(const_cstr_methods)]
168 // Language features:
169 #![feature(abi_unadjusted)]
170 #![feature(adt_const_params)]
171 #![feature(allow_internal_unsafe)]
172 #![feature(allow_internal_unstable)]
173 #![feature(associated_type_bounds)]
174 #![feature(auto_traits)]
175 #![feature(cfg_sanitize)]
176 #![feature(cfg_target_has_atomic)]
177 #![feature(cfg_target_has_atomic_equal_alignment)]
178 #![feature(const_fn_floating_point_arithmetic)]
179 #![feature(const_mut_refs)]
180 #![feature(const_precise_live_drops)]
181 #![feature(const_refs_to_cell)]
182 #![feature(decl_macro)]
183 #![feature(deprecated_suggestion)]
185 #![feature(doc_notable_trait)]
186 #![feature(rustdoc_internals)]
187 #![feature(exhaustive_patterns)]
188 #![feature(doc_cfg_hide)]
189 #![feature(extern_types)]
190 #![feature(fundamental)]
191 #![feature(if_let_guard)]
192 #![feature(intra_doc_pointers)]
193 #![feature(intrinsics)]
194 #![feature(lang_items)]
195 #![feature(link_llvm_intrinsics)]
196 #![feature(macro_metavar_expr)]
197 #![feature(min_specialization)]
198 #![feature(must_not_suspend)]
199 #![feature(negative_impls)]
200 #![feature(never_type)]
202 #![feature(no_coverage)] // rust-lang/rust#84605
203 #![feature(platform_intrinsics)]
204 #![feature(prelude_import)]
205 #![feature(repr_simd)]
206 #![feature(rustc_allow_const_fn_unstable)]
207 #![feature(rustc_attrs)]
208 #![feature(simd_ffi)]
209 #![feature(staged_api)]
210 #![feature(stmt_expr_attributes)]
211 #![feature(trait_alias)]
212 #![feature(transparent_unions)]
213 #![feature(try_blocks)]
214 #![feature(unboxed_closures)]
215 #![feature(unsized_fn_params)]
216 #![feature(asm_const)]
219 #![feature(arm_target_feature)]
220 #![feature(avx512_target_feature)]
221 #![feature(cmpxchg16b_target_feature)]
222 #![feature(f16c_target_feature)]
223 #![feature(hexagon_target_feature)]
224 #![feature(mips_target_feature)]
225 #![feature(powerpc_target_feature)]
226 #![feature(rtm_target_feature)]
227 #![feature(sse4a_target_feature)]
228 #![feature(tbm_target_feature)]
229 #![feature(wasm_target_feature)]
231 // allow using `core::` in intra-doc links
232 #[allow(unused_extern_crates)]
233 extern crate self as core;
239 #[cfg(not(test))] // See #65860
243 // We don't export this through #[macro_export] for now, to avoid breakage.
244 // See https://github.com/rust-lang/rust/issues/82913
246 #[unstable(feature = "assert_matches", issue = "82775")]
247 /// Unstable module containing the unstable `assert_matches` macro.
248 pub mod assert_matches {
249 #[unstable(feature = "assert_matches", issue = "82775")]
250 pub use crate::macros::{assert_matches, debug_assert_matches};
256 #[path = "num/shells/int_macros.rs"]
260 #[path = "num/shells/i128.rs"]
262 #[path = "num/shells/i16.rs"]
264 #[path = "num/shells/i32.rs"]
266 #[path = "num/shells/i64.rs"]
268 #[path = "num/shells/i8.rs"]
270 #[path = "num/shells/isize.rs"]
273 #[path = "num/shells/u128.rs"]
275 #[path = "num/shells/u16.rs"]
277 #[path = "num/shells/u32.rs"]
279 #[path = "num/shells/u64.rs"]
281 #[path = "num/shells/u8.rs"]
283 #[path = "num/shells/usize.rs"]
286 #[path = "num/f32.rs"]
288 #[path = "num/f64.rs"]
294 /* The libcore prelude, not as all-encompassing as the libstd prelude */
298 /* Core modules for ownership management */
305 /* Core language traits */
316 /* Core types and methods on primitives */
322 #[unstable(feature = "async_iterator", issue = "79024")]
328 #[unstable(feature = "once_cell", issue = "74465")]
349 /* Heap memory allocator trait */
350 #[allow(missing_docs)]
353 // note: does not need to be public
360 #[stable(feature = "core_primitive", since = "1.43.0")]
363 // Pull in the `core_arch` crate directly into libcore. The contents of
364 // `core_arch` are in a different repository: rust-lang/stdarch.
366 // `core_arch` depends on libcore, but the contents of this module are
367 // set up in such a way that directly pulling it here works such that the
368 // crate uses the this crate as its libcore.
369 #[path = "../../stdarch/crates/core_arch/src/mod.rs"]
372 missing_debug_implementations,
375 unsafe_op_in_unsafe_fn
377 #[allow(rustdoc::bare_urls)]
378 // FIXME: This annotation should be moved into rust-lang/stdarch after clashing_extern_declarations is
379 // merged. It currently cannot because bootstrap fails as the lint hasn't been defined yet.
380 #[allow(clashing_extern_declarations)]
381 #[unstable(feature = "stdsimd", issue = "48556")]
384 #[doc = include_str!("../../stdarch/crates/core_arch/src/core_arch_docs.md")]
385 #[stable(feature = "simd_arch", since = "1.27.0")]
387 #[stable(feature = "simd_arch", since = "1.27.0")]
388 pub use crate::core_arch::arch::*;
392 /// Refer to [rust by example] for a usage guide and the [reference] for
393 /// detailed information about the syntax and available options.
395 /// [rust by example]: https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html
396 /// [reference]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html
397 #[stable(feature = "asm", since = "1.59.0")]
398 #[rustc_builtin_macro]
399 pub macro asm("assembly template", $(operands,)* $(options($(option),*))?) {
400 /* compiler built-in */
403 /// Module-level inline assembly.
405 /// Refer to [rust by example] for a usage guide and the [reference] for
406 /// detailed information about the syntax and available options.
408 /// [rust by example]: https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html
409 /// [reference]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html
410 #[stable(feature = "global_asm", since = "1.59.0")]
411 #[rustc_builtin_macro]
412 pub macro global_asm("assembly template", $(operands,)* $(options($(option),*))?) {
413 /* compiler built-in */
417 // Pull in the `core_simd` crate directly into libcore. The contents of
418 // `core_simd` are in a different repository: rust-lang/portable-simd.
420 // `core_simd` depends on libcore, but the contents of this module are
421 // set up in such a way that directly pulling it here works such that the
422 // crate uses this crate as its libcore.
423 #[path = "../../portable-simd/crates/core_simd/src/mod.rs"]
424 #[allow(missing_debug_implementations, dead_code, unsafe_op_in_unsafe_fn, unused_unsafe)]
425 #[allow(rustdoc::bare_urls)]
426 #[unstable(feature = "portable_simd", issue = "86656")]
429 #[doc = include_str!("../../portable-simd/crates/core_simd/src/core_simd_docs.md")]
430 #[unstable(feature = "portable_simd", issue = "86656")]
432 #[unstable(feature = "portable_simd", issue = "86656")]
433 pub use crate::core_simd::simd::*;
436 include!("primitive_docs.rs");