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