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`, `memmove`, `memset`, `memcmp`, `bcmp`, `strlen` - These are core memory routines
24//! which are generated by Rust codegen backends. Additionally, this library can make explicit
25//! calls to `strlen`. Their signatures are the same as found in C, but there are extra
26//! assumptions about their semantics: For `memcpy`, `memmove`, `memset`, `memcmp`, and `bcmp`, if
27//! the `n` parameter is 0, the function is assumed to not be UB, even if the pointers are NULL or
28//! dangling. (Note that making extra assumptions about these functions is common among compilers:
29//! [clang](https://reviews.llvm.org/D86993) and [GCC](https://gcc.gnu.org/onlinedocs/gcc/Standards.html#C-Language) do the same.)
30//! These functions are often provided by the system libc, but can also be provided by the
31//! [compiler-builtins crate](https://crates.io/crates/compiler_builtins).
32//! Note that the library does not guarantee that it will always make these assumptions, so Rust
33//! user code directly calling the C functions should follow the C specification! The advice for
34//! Rust user code is to call the functions provided by this library instead (such as
35//! `ptr::copy`).
36//!
37//! * `rust_begin_panic` - This function takes four arguments, a
38//! `fmt::Arguments`, a `&'static str`, and two `u32`'s. These four arguments
39//! dictate the panic message, the file at which panic was invoked, and the
40//! line and column inside the file. It is up to consumers of this core
41//! library to define this panic function; it is only required to never
42//! return. This requires a `lang` attribute named `panic_impl`.
43//!
44//! * `rust_eh_personality` - is used by the failure mechanisms of the
45//! compiler. This is often mapped to GCC's personality function, but crates
46//! which do not trigger a panic can be assured that this function is never
47//! called. The `lang` attribute is called `eh_personality`.
48
49// Since core defines many fundamental lang items, all tests live in a
50// separate crate, libcoretest (library/core/tests), to avoid bizarre issues.
51//
52// Here we explicitly #[cfg]-out this whole crate when testing. If we don't do
53// this, both the generated test artifact and the linked libtest (which
54// transitively includes core) will both define the same set of lang items,
55// and this will cause the E0152 "found duplicate lang item" error. See
56// discussion in #50466 for details.
57//
58// This cfg won't affect doc tests.
59#![cfg(not(test))]
60//
61#![stable(feature = "core", since = "1.6.0")]
62#![doc(
63 html_playground_url = "https://play.rust-lang.org/",
64 issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
65 test(no_crate_inject, attr(deny(warnings))),
66 test(attr(allow(dead_code, deprecated, unused_variables, unused_mut)))
67)]
68#![doc(rust_logo)]
69#![doc(cfg_hide(
70 not(test),
71 no_fp_fmt_parse,
72 target_pointer_width = "16",
73 target_pointer_width = "32",
74 target_pointer_width = "64",
75 target_has_atomic = "8",
76 target_has_atomic = "16",
77 target_has_atomic = "32",
78 target_has_atomic = "64",
79 target_has_atomic = "ptr",
80 target_has_atomic_equal_alignment = "8",
81 target_has_atomic_equal_alignment = "16",
82 target_has_atomic_equal_alignment = "32",
83 target_has_atomic_equal_alignment = "64",
84 target_has_atomic_equal_alignment = "ptr",
85 target_has_atomic_load_store = "8",
86 target_has_atomic_load_store = "16",
87 target_has_atomic_load_store = "32",
88 target_has_atomic_load_store = "64",
89 target_has_atomic_load_store = "ptr",
90))]
91#![no_core]
92#![rustc_coherence_is_core]
93#![cfg_attr(not(bootstrap), rustc_preserve_ub_checks)]
94//
95// Lints:
96#![deny(rust_2021_incompatible_or_patterns)]
97#![deny(unsafe_op_in_unsafe_fn)]
98#![deny(fuzzy_provenance_casts)]
99#![warn(deprecated_in_future)]
100#![warn(missing_debug_implementations)]
101#![warn(missing_docs)]
102#![allow(explicit_outlives_requirements)]
103#![allow(incomplete_features)]
104#![warn(multiple_supertrait_upcastable)]
105#![allow(internal_features)]
106#![deny(ffi_unwind_calls)]
107// Do not check link redundancy on bootstraping phase
108#![allow(rustdoc::redundant_explicit_links)]
109//
110// Library features:
111// tidy-alphabetical-start
112#![cfg_attr(bootstrap, feature(associated_type_bounds))]
113#![feature(array_ptr_get)]
114#![feature(asm_experimental_arch)]
115#![feature(char_indices_offset)]
116#![feature(const_align_of_val)]
117#![feature(const_align_of_val_raw)]
118#![feature(const_align_offset)]
119#![feature(const_alloc_layout)]
120#![feature(const_arguments_as_str)]
121#![feature(const_array_from_ref)]
122#![feature(const_array_into_iter_constructors)]
123#![feature(const_bigint_helper_methods)]
124#![feature(const_black_box)]
125#![feature(const_cell_into_inner)]
126#![feature(const_char_from_u32_unchecked)]
127#![feature(const_eval_select)]
128#![feature(const_exact_div)]
129#![feature(const_float_bits_conv)]
130#![feature(const_float_classify)]
131#![feature(const_fmt_arguments_new)]
132#![feature(const_hash)]
133#![feature(const_heap)]
134#![feature(const_hint_assert_unchecked)]
135#![feature(const_index_range_slice_index)]
136#![feature(const_int_from_str)]
137#![feature(const_intrinsic_copy)]
138#![feature(const_intrinsic_forget)]
139#![feature(const_ipv4)]
140#![feature(const_ipv6)]
141#![feature(const_likely)]
142#![feature(const_maybe_uninit_as_mut_ptr)]
143#![feature(const_maybe_uninit_assume_init)]
144#![feature(const_maybe_uninit_uninit_array)]
145#![feature(const_nonnull_new)]
146#![feature(const_num_midpoint)]
147#![feature(const_option)]
148#![feature(const_option_ext)]
149#![feature(const_pin)]
150#![feature(const_pointer_is_aligned)]
151#![feature(const_ptr_as_ref)]
152#![feature(const_ptr_is_null)]
153#![feature(const_ptr_sub_ptr)]
154#![feature(const_ptr_write)]
155#![feature(const_raw_ptr_comparison)]
156#![feature(const_replace)]
157#![feature(const_size_of_val)]
158#![feature(const_size_of_val_raw)]
159#![feature(const_slice_from_raw_parts_mut)]
160#![feature(const_slice_from_ref)]
161#![feature(const_slice_index)]
162#![feature(const_slice_split_at_mut)]
163#![feature(const_str_from_utf8_unchecked_mut)]
164#![feature(const_strict_overflow_ops)]
165#![feature(const_swap)]
166#![feature(const_try)]
167#![feature(const_type_id)]
168#![feature(const_type_name)]
169#![feature(const_typed_swap)]
170#![feature(const_ub_checks)]
171#![feature(const_unicode_case_lookup)]
172#![feature(const_unsafecell_get_mut)]
173#![feature(const_waker)]
174#![feature(coverage_attribute)]
175#![feature(duration_consts_float)]
176#![feature(internal_impls_macro)]
177#![feature(ip)]
178#![feature(ip_bits)]
179#![feature(is_ascii_octdigit)]
180#![feature(isqrt)]
181#![feature(link_cfg)]
182#![feature(maybe_uninit_uninit_array)]
183#![feature(non_null_convenience)]
184#![feature(offset_of_enum)]
185#![feature(offset_of_nested)]
186#![feature(panic_internals)]
187#![feature(ptr_alignment_type)]
188#![feature(ptr_metadata)]
189#![feature(set_ptr_value)]
190#![feature(slice_ptr_get)]
191#![feature(split_at_checked)]
192#![feature(str_internals)]
193#![feature(str_split_inclusive_remainder)]
194#![feature(str_split_remainder)]
195#![feature(strict_provenance)]
196#![feature(unchecked_shifts)]
197#![feature(utf16_extra)]
198#![feature(utf16_extra_const)]
199#![feature(variant_count)]
200// tidy-alphabetical-end
201//
202// Language features:
203// tidy-alphabetical-start
204#![cfg_attr(bootstrap, feature(inline_const))]
205#![feature(abi_unadjusted)]
206#![feature(adt_const_params)]
207#![feature(allow_internal_unsafe)]
208#![feature(allow_internal_unstable)]
209#![feature(asm_const)]
210#![feature(auto_traits)]
211#![feature(c_unwind)]
212#![feature(cfg_sanitize)]
213#![feature(cfg_target_has_atomic)]
214#![feature(cfg_target_has_atomic_equal_alignment)]
215#![feature(const_closures)]
216#![feature(const_fn_floating_point_arithmetic)]
217#![feature(const_for)]
218#![feature(const_mut_refs)]
219#![feature(const_precise_live_drops)]
220#![feature(const_refs_to_cell)]
221#![feature(const_trait_impl)]
222#![feature(decl_macro)]
223#![feature(deprecated_suggestion)]
224#![feature(doc_cfg)]
225#![feature(doc_cfg_hide)]
226#![feature(doc_notable_trait)]
227#![feature(effects)]
228#![feature(extern_types)]
229#![feature(f128)]
230#![feature(f16)]
231#![feature(freeze_impls)]
232#![feature(fundamental)]
233#![feature(generic_arg_infer)]
234#![feature(if_let_guard)]
235#![feature(intra_doc_pointers)]
236#![feature(intrinsics)]
237#![feature(lang_items)]
238#![feature(let_chains)]
239#![feature(link_llvm_intrinsics)]
240#![feature(macro_metavar_expr)]
241#![feature(min_exhaustive_patterns)]
242#![feature(min_specialization)]
243#![feature(multiple_supertrait_upcastable)]
244#![feature(must_not_suspend)]
245#![feature(negative_impls)]
246#![feature(never_type)]
247#![feature(no_core)]
248#![feature(no_sanitize)]
249#![feature(prelude_import)]
250#![feature(repr_simd)]
251#![feature(rustc_allow_const_fn_unstable)]
252#![feature(rustc_attrs)]
253#![feature(rustdoc_internals)]
254#![feature(simd_ffi)]
255#![feature(staged_api)]
256#![feature(stmt_expr_attributes)]
257#![feature(target_feature_11)]
258#![feature(trait_alias)]
259#![feature(transparent_unions)]
260#![feature(try_blocks)]
261#![feature(unboxed_closures)]
262#![feature(unsized_fn_params)]
263#![feature(with_negative_coherence)]
264// tidy-alphabetical-end
265//
266// Target features:
267// tidy-alphabetical-start
268#![feature(arm_target_feature)]
269#![feature(avx512_target_feature)]
270#![feature(hexagon_target_feature)]
271#![feature(loongarch_target_feature)]
272#![feature(mips_target_feature)]
273#![feature(powerpc_target_feature)]
274#![feature(riscv_target_feature)]
275#![feature(rtm_target_feature)]
276#![feature(sse4a_target_feature)]
277#![feature(tbm_target_feature)]
278#![feature(wasm_target_feature)]
279// tidy-alphabetical-end
280
281// allow using `core::` in intra-doc links
282#[allow(unused_extern_crates)]
283extern crate self as core;
284
285#[prelude_import]
286#[allow(unused)]
287use prelude::rust_2021::*;
288
289#[cfg(not(test))] // See #65860
290#[macro_use]
291mod macros;
292
293// We don't export this through #[macro_export] for now, to avoid breakage.
294// See https://github.com/rust-lang/rust/issues/82913
295#[cfg(not(test))]
296#[unstable(feature = "assert_matches", issue = "82775")]
297/// Unstable module containing the unstable `assert_matches` macro.
298pub mod assert_matches {
299 #[unstable(feature = "assert_matches", issue = "82775")]
300 pub use crate::macros::{assert_matches, debug_assert_matches};
301}
302
303#[unstable(feature = "cfg_match", issue = "115585")]
304pub use crate::macros::cfg_match;
305
306#[macro_use]
307mod internal_macros;
308
309#[path = "num/shells/int_macros.rs"]
310#[macro_use]
311mod int_macros;
312
313#[rustc_diagnostic_item = "i128_legacy_mod"]
314#[path = "num/shells/i128.rs"]
315pub mod i128;
316#[rustc_diagnostic_item = "i16_legacy_mod"]
317#[path = "num/shells/i16.rs"]
318pub mod i16;
319#[rustc_diagnostic_item = "i32_legacy_mod"]
320#[path = "num/shells/i32.rs"]
321pub mod i32;
322#[rustc_diagnostic_item = "i64_legacy_mod"]
323#[path = "num/shells/i64.rs"]
324pub mod i64;
325#[rustc_diagnostic_item = "i8_legacy_mod"]
326#[path = "num/shells/i8.rs"]
327pub mod i8;
328#[rustc_diagnostic_item = "isize_legacy_mod"]
329#[path = "num/shells/isize.rs"]
330pub mod isize;
331
332#[rustc_diagnostic_item = "u128_legacy_mod"]
333#[path = "num/shells/u128.rs"]
334pub mod u128;
335#[rustc_diagnostic_item = "u16_legacy_mod"]
336#[path = "num/shells/u16.rs"]
337pub mod u16;
338#[rustc_diagnostic_item = "u32_legacy_mod"]
339#[path = "num/shells/u32.rs"]
340pub mod u32;
341#[rustc_diagnostic_item = "u64_legacy_mod"]
342#[path = "num/shells/u64.rs"]
343pub mod u64;
344#[rustc_diagnostic_item = "u8_legacy_mod"]
345#[path = "num/shells/u8.rs"]
346pub mod u8;
347#[rustc_diagnostic_item = "usize_legacy_mod"]
348#[path = "num/shells/usize.rs"]
349pub mod usize;
350
351#[path = "num/f128.rs"]
352pub mod f128;
353#[path = "num/f16.rs"]
354pub mod f16;
355#[path = "num/f32.rs"]
356pub mod f32;
357#[path = "num/f64.rs"]
358pub mod f64;
359
360#[macro_use]
361pub mod num;
362
363/* The core prelude, not as all-encompassing as the std prelude */
364
365pub mod prelude;
366
367/* Core modules for ownership management */
368
369pub mod hint;
370pub mod intrinsics;
371pub mod mem;
372pub mod ptr;
373mod ub_checks;
374
375/* Core language traits */
376
377pub mod borrow;
378pub mod clone;
379pub mod cmp;
380pub mod convert;
381pub mod default;
382pub mod error;
383pub mod marker;
384pub mod ops;
385
386/* Core types and methods on primitives */
387
388pub mod any;
389pub mod array;
390pub mod ascii;
391pub mod asserting;
392#[unstable(feature = "async_iterator", issue = "79024")]
393pub mod async_iter;
394pub mod cell;
395pub mod char;
396pub mod ffi;
397#[unstable(feature = "core_io_borrowed_buf", issue = "117693")]
398pub mod io;
399pub mod iter;
400pub mod net;
401pub mod option;
402pub mod panic;
403pub mod panicking;
404#[cfg(not(bootstrap))]
405#[unstable(feature = "core_pattern_types", issue = "none")]
406pub mod pat;
407pub mod pin;
408pub mod result;
409pub mod sync;
410
411pub mod fmt;
412pub mod hash;
413pub mod slice;
414pub mod str;
415pub mod time;
416
417pub mod unicode;
418
419/* Async */
420pub mod future;
421pub mod task;
422
423/* Heap memory allocator trait */
424#[allow(missing_docs)]
425pub mod alloc;
426
427// note: does not need to be public
428mod bool;
429mod escape;
430mod tuple;
431mod unit;
432
433#[stable(feature = "core_primitive", since = "1.43.0")]
434pub mod primitive;
435
436// Pull in the `core_arch` crate directly into core. The contents of
437// `core_arch` are in a different repository: rust-lang/stdarch.
438//
439// `core_arch` depends on core, but the contents of this module are
440// set up in such a way that directly pulling it here works such that the
441// crate uses the this crate as its core.
442#[path = "../../stdarch/crates/core_arch/src/mod.rs"]
443#[allow(
444 missing_docs,
445 missing_debug_implementations,
446 dead_code,
447 unused_imports,
448 unsafe_op_in_unsafe_fn,
449 ambiguous_glob_reexports,
450 deprecated_in_future
451)]
452#[allow(rustdoc::bare_urls)]
453mod core_arch;
454
455#[stable(feature = "simd_arch", since = "1.27.0")]
456pub mod arch;
457
458// Pull in the `core_simd` crate directly into core. The contents of
459// `core_simd` are in a different repository: rust-lang/portable-simd.
460//
461// `core_simd` depends on core, but the contents of this module are
462// set up in such a way that directly pulling it here works such that the
463// crate uses this crate as its core.
464#[path = "../../portable-simd/crates/core_simd/src/mod.rs"]
465#[allow(missing_debug_implementations, dead_code, unsafe_op_in_unsafe_fn)]
466#[allow(rustdoc::bare_urls)]
467#[unstable(feature = "portable_simd", issue = "86656")]
468mod core_simd;
469
470#[unstable(feature = "portable_simd", issue = "86656")]
471pub mod simd {
472 #![doc = include_str!("../../portable-simd/crates/core_simd/src/core_simd_docs.md")]
473
474 #[unstable(feature = "portable_simd", issue = "86656")]
475 pub use crate::core_simd::simd::*;
476}
477
478include!("primitive_docs.rs");
479