Skip to main content

core/
lib.rs

1//! **You are viewing the documentation of the Rust core library as a part of
2//! the Fortanix Rust EDP.** There are no changes compared to the normal the
3//! core library.
4//!
5//! ---
6//!
7//! # The Rust Core Library
8//!
9//! The Rust Core Library is the dependency-free[^free] foundation of [The
10//! Rust Standard Library](../std/index.html). It is the portable glue
11//! between the language and its libraries, defining the intrinsic and
12//! primitive building blocks of all Rust code. It links to no
13//! upstream libraries, no system libraries, and no libc.
14//!
15//! [^free]: Strictly speaking, there are some symbols which are needed but
16//!          they aren't always necessary.
17//!
18//! The core library is *minimal*: it isn't even aware of heap allocation,
19//! nor does it provide concurrency or I/O. These things require
20//! platform integration, and this library is platform-agnostic.
21//!
22//! # How to use the core library
23//!
24//! Please note that all of these details are currently not considered stable.
25//!
26// FIXME: Fill me in with more detail when the interface settles
27//! This library is built on the assumption of a few existing symbols:
28//!
29//! * `memcpy`, `memmove`, `memset`, `memcmp`, `bcmp`, `strlen` - These are core memory routines
30//!   which are generated by Rust codegen backends. Additionally, this library can make explicit
31//!   calls to `strlen`. Their signatures are the same as found in C, but there are extra
32//!   assumptions about their semantics: For `memcpy`, `memmove`, `memset`, `memcmp`, and `bcmp`, if
33//!   the `n` parameter is 0, the function is assumed to not be UB, even if the pointers are NULL or
34//!   dangling. (Note that making extra assumptions about these functions is common among compilers:
35//!   [clang](https://reviews.llvm.org/D86993) and [GCC](https://gcc.gnu.org/onlinedocs/gcc/Standards.html#C-Language) do the same.)
36//!   These functions are often provided by the system libc, but can also be provided by the
37//!   [compiler-builtins crate](https://crates.io/crates/compiler_builtins).
38//!   Note that the library does not guarantee that it will always make these assumptions, so Rust
39//!   user code directly calling the C functions should follow the C specification! The advice for
40//!   Rust user code is to call the functions provided by this library instead (such as
41//!   `ptr::copy`).
42//!
43//! * Panic handler - This function takes one argument, a `&panic::PanicInfo`. It is up to consumers of this core
44//!   library to define this panic function; it is only required to never
45//!   return. You should mark your implementation using `#[panic_handler]`.
46//!
47//! * `rust_eh_personality` - is used by the failure mechanisms of the
48//!   compiler. This is often mapped to GCC's personality function, but crates
49//!   which do not trigger a panic can be assured that this function is never
50//!   called. The `lang` attribute is called `eh_personality`.
51
52#![stable(feature = "core", since = "1.6.0")]
53#![doc(
54    html_root_url = "https://edp.fortanix.com/docs/api/",
55    html_logo_url = "https://edp.fortanix.com/img/docs/edp-logo.svg",
56    html_favicon_url = "https://edp.fortanix.com/favicon.ico",
57    html_playground_url = "https://play.rust-lang.org/",
58    issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
59    test(no_crate_inject, attr(deny(warnings))),
60    test(attr(allow(dead_code, deprecated, unused_variables, unused_mut, duplicate_features)))
61)]
62#![doc(rust_logo)]
63#![doc(auto_cfg(
64    hide(no_fp_fmt_parse),
65    hide(target_pointer_width, values("16", "32", "64")),
66    hide(
67        target_has_atomic,
68        target_has_atomic_primitive_alignment,
69        target_has_atomic_load_store,
70        values("8", "16", "32", "64", "ptr"),
71    ),
72))]
73#![no_core]
74#![rustc_coherence_is_core]
75#![rustc_preserve_ub_checks]
76//
77// Lints:
78#![deny(rust_2021_incompatible_or_patterns)]
79#![deny(unsafe_op_in_unsafe_fn)]
80#![deny(implicit_provenance_casts)]
81#![warn(deprecated_in_future)]
82#![warn(missing_debug_implementations)]
83#![warn(missing_docs)]
84#![allow(explicit_outlives_requirements)]
85#![allow(incomplete_features)]
86#![warn(multiple_supertrait_upcastable)]
87#![allow(internal_features)]
88#![allow(unused_features)]
89#![deny(ffi_unwind_calls)]
90#![warn(unreachable_pub)]
91// Do not check link redundancy on bootstrapping phase
92#![allow(rustdoc::redundant_explicit_links)]
93#![warn(rustdoc::unescaped_backticks)]
94//
95// Library features:
96// tidy-alphabetical-start
97#![feature(asm_experimental_arch)]
98#![feature(byte_str_internals)]
99#![feature(cfg_target_has_reliable_f16_f128)]
100#![feature(const_cmp)]
101#![feature(const_destruct)]
102#![feature(const_eval_select)]
103#![feature(const_select_unpredictable)]
104#![feature(core_intrinsics)]
105#![feature(coverage_attribute)]
106#![feature(disjoint_bitor)]
107#![feature(io_const_error)]
108#![feature(offset_of_enum)]
109#![feature(panic_internals)]
110#![feature(pattern_type_macro)]
111#![feature(ub_checks)]
112// tidy-alphabetical-end
113//
114// Language features:
115// tidy-alphabetical-start
116#![feature(adt_const_params)]
117#![feature(allow_internal_unsafe)]
118#![feature(allow_internal_unstable)]
119#![feature(arbitrary_self_types_pointers)]
120#![feature(auto_traits)]
121#![feature(cfg_sanitize)]
122#![feature(cfg_target_has_atomic)]
123#![feature(cfg_ub_checks)]
124#![feature(const_closures)]
125#![feature(const_precise_live_drops)]
126#![feature(const_trait_impl)]
127#![feature(decl_macro)]
128#![feature(deprecated_suggestion)]
129#![feature(derive_const)]
130#![feature(diagnostic_on_const)]
131#![feature(diagnostic_on_unmatched_args)]
132#![feature(diagnostic_opaque)]
133#![feature(doc_cfg)]
134#![feature(doc_notable_trait)]
135#![feature(extern_types)]
136#![feature(f16)]
137#![feature(f128)]
138#![feature(field_projections)]
139#![feature(final_associated_functions)]
140#![feature(forced_keywords)]
141#![feature(freeze_impls)]
142#![feature(fundamental)]
143#![feature(impl_restriction)]
144#![feature(intra_doc_pointers)]
145#![feature(intrinsics)]
146#![feature(lang_items)]
147#![feature(link_cfg)]
148#![feature(link_llvm_intrinsics)]
149#![feature(macro_metavar_expr)]
150#![feature(macro_metavar_expr_concat)]
151#![feature(marker_trait_attr)]
152#![feature(min_specialization)]
153#![feature(multiple_supertrait_upcastable)]
154#![feature(must_not_suspend)]
155#![feature(negative_impls)]
156#![feature(no_core)]
157#![feature(pattern_types)]
158#![feature(pin_macro_internals)]
159#![feature(prelude_import)]
160#![feature(register_tool)]
161#![feature(repr_simd)]
162#![feature(rustc_attrs)]
163#![feature(rustdoc_internals)]
164#![feature(simd_ffi)]
165#![feature(splat)]
166#![feature(staged_api)]
167#![feature(stmt_expr_attributes)]
168#![feature(strict_provenance_lints)]
169#![feature(trait_alias)]
170#![feature(transparent_unions)]
171#![feature(try_blocks)]
172#![feature(uint_carryless_mul)]
173#![feature(unboxed_closures)]
174#![feature(unsized_fn_params)]
175#![feature(with_negative_coherence)]
176// tidy-alphabetical-end
177//
178// Target features:
179// tidy-alphabetical-start
180#![feature(aarch64_unstable_target_feature)]
181#![feature(arm_target_feature)]
182#![feature(avx10_target_feature)]
183#![feature(clflushopt_target_feature)]
184#![feature(hexagon_target_feature)]
185#![feature(loongarch_target_feature)]
186#![feature(mips_target_feature)]
187#![feature(movrs_target_feature)]
188#![feature(nvptx_target_feature)]
189#![feature(powerpc_target_feature)]
190#![feature(riscv_target_feature)]
191#![feature(rtm_target_feature)]
192#![feature(s390x_target_feature)]
193#![feature(wasm_target_feature)]
194#![feature(x86_amx_intrinsics)]
195// tidy-alphabetical-end
196
197// tidy-alphabetical-start
198#![register_tool(lint)]
199// tidy-alphabetical-end
200
201// tidy-alphabetical-start
202#![expect(clippy::partialeq_ne_impl, reason = "we need to implement ne for a lot of core types")]
203// tidy-alphabetical-end
204
205// allow using `core::` in intra-doc links
206#[allow(unused_extern_crates)]
207extern crate self as core;
208
209/* The core prelude, not as all-encompassing as the std prelude */
210// The compiler expects the prelude definition to be defined before it's use statement.
211pub mod prelude;
212
213#[prelude_import]
214#[allow(unused)]
215use prelude::rust_2024::*;
216
217#[macro_use]
218mod macros;
219
220#[stable(feature = "assert_matches", since = "1.96.0")]
221pub use crate::macros::{assert_matches, debug_assert_matches};
222
223#[unstable(feature = "derive_from", issue = "144889")]
224/// Unstable module containing the unstable `From` derive macro.
225pub mod from {
226    #[unstable(feature = "derive_from", issue = "144889")]
227    pub use crate::macros::builtin::From;
228}
229
230// We don't export this through #[macro_export] for now, to avoid breakage.
231#[unstable(feature = "autodiff", issue = "124509")]
232#[doc = include_str!("../../core/src/autodiff.md")]
233pub mod autodiff {
234    #[unstable(feature = "autodiff", issue = "124509")]
235    pub use crate::macros::builtin::{autodiff_forward, autodiff_reverse};
236}
237
238#[unstable(feature = "gpu_offload", issue = "131513")]
239#[doc = include_str!("../../core/src/offload.md")]
240pub mod offload;
241
242#[unstable(feature = "contracts", issue = "128044")]
243pub mod contracts;
244
245#[allow(clippy::useless_attribute)]
246#[expect(
247    ineffective_unstable_reexports,
248    reason = "accepted as stable after accidental stabilization in 1.96, see #154645"
249)]
250#[unstable(feature = "derive_macro_global_path", issue = "154645")]
251pub use crate::macros::builtin::derive;
252#[stable(feature = "cfg_select", since = "1.95.0")]
253pub use crate::macros::cfg_select;
254
255#[macro_use]
256mod internal_macros;
257
258#[path = "num/shells/legacy_int_modules.rs"]
259mod legacy_int_modules;
260#[stable(feature = "rust1", since = "1.0.0")]
261#[allow(deprecated, clippy::legacy_numeric_constants)]
262pub use legacy_int_modules::{i8, i16, i32, i64, isize, u8, u16, u32, u64, usize};
263#[stable(feature = "i128", since = "1.26.0")]
264#[allow(deprecated, clippy::legacy_numeric_constants)]
265pub use legacy_int_modules::{i128, u128};
266
267#[macro_use]
268pub mod num;
269
270#[path = "num/f128.rs"]
271pub mod f128;
272#[path = "num/f16.rs"]
273pub mod f16;
274#[path = "num/f32.rs"]
275pub mod f32;
276#[path = "num/f64.rs"]
277pub mod f64;
278
279/* Core modules for ownership management */
280
281pub mod hint;
282pub mod intrinsics;
283pub mod mem;
284#[unstable(feature = "profiling_marker_api", issue = "148197")]
285pub mod profiling;
286pub mod ptr;
287#[unstable(feature = "ub_checks", issue = "none")]
288pub mod ub_checks;
289
290/* Core language traits */
291
292pub mod borrow;
293pub mod clone;
294pub mod cmp;
295pub mod convert;
296pub mod default;
297pub mod error;
298#[unstable(feature = "field_projections", issue = "145383")]
299pub mod field;
300pub mod index;
301pub mod marker;
302pub mod ops;
303
304/* Core types and methods on primitives */
305
306pub mod any;
307pub mod array;
308pub mod ascii;
309pub mod asserting;
310#[unstable(feature = "async_iterator", issue = "79024")]
311pub mod async_iter;
312#[unstable(feature = "byte_str", issue = "134915")]
313pub mod byte_str;
314pub mod cell;
315pub mod char;
316pub mod ffi;
317#[unstable(feature = "core_io", issue = "154046")]
318pub mod io;
319pub mod iter;
320pub mod net;
321pub mod option;
322pub mod os;
323pub mod panic;
324pub mod panicking;
325#[unstable(feature = "pattern_type_macro", issue = "123646")]
326pub mod pat;
327pub mod pin;
328#[unstable(feature = "abort_immediate", issue = "154601")]
329pub mod process;
330#[unstable(feature = "random", issue = "130703")]
331pub mod random;
332#[stable(feature = "new_range_inclusive_api", since = "1.95.0")]
333pub mod range;
334pub mod result;
335pub mod sync;
336#[unstable(feature = "unsafe_binders", issue = "130516")]
337pub mod unsafe_binder;
338
339pub mod fmt;
340pub mod hash;
341pub mod slice;
342pub mod str;
343pub mod time;
344
345pub mod wtf8;
346
347pub mod unicode;
348
349/* Async */
350pub mod future;
351pub mod task;
352
353/* Heap memory allocator trait */
354#[allow(missing_docs)]
355pub mod alloc;
356
357// note: does not need to be public
358mod bool;
359mod escape;
360mod tuple;
361mod unit;
362#[unstable(feature = "view_type_macro", issue = "155938")]
363pub mod view;
364
365#[stable(feature = "core_primitive", since = "1.43.0")]
366pub mod primitive;
367
368// Pull in the `core_arch` crate directly into core. The contents of
369// `core_arch` are in a different repository: rust-lang/stdarch.
370//
371// `core_arch` depends on core, but the contents of this module are
372// set up in such a way that directly pulling it here works such that the
373// crate uses the this crate as its core.
374#[path = "../../stdarch/crates/core_arch/src/mod.rs"]
375#[allow(
376    missing_docs,
377    missing_debug_implementations,
378    dead_code,
379    unused_imports,
380    unsafe_op_in_unsafe_fn,
381    ambiguous_glob_reexports,
382    unreachable_pub,
383    // FIXME: stdach is a submodule so clippy lints should be fixed (and ideally enforced) there
384    clippy::all,
385)]
386#[allow(rustdoc::bare_urls)]
387mod core_arch;
388
389#[stable(feature = "simd_arch", since = "1.27.0")]
390pub mod arch;
391
392// Pull in the `core_simd` crate directly into core. The contents of
393// `core_simd` are in a different repository: rust-lang/portable-simd.
394//
395// `core_simd` depends on core, but the contents of this module are
396// set up in such a way that directly pulling it here works such that the
397// crate uses this crate as its core.
398#[path = "../../portable-simd/crates/core_simd/src/mod.rs"]
399#[allow(missing_debug_implementations, dead_code, unsafe_op_in_unsafe_fn)]
400#[allow(rustdoc::bare_urls)]
401#[unstable(feature = "portable_simd", issue = "86656")]
402mod core_simd;
403
404#[unstable(feature = "portable_simd", issue = "86656")]
405pub mod simd {
406    #![doc = include_str!("../../portable-simd/crates/core_simd/src/core_simd_docs.md")]
407
408    #[unstable(feature = "portable_simd", issue = "86656")]
409    pub use crate::core_simd::simd::*;
410}
411
412// Include private modules that exist solely to provide rustdoc
413// documentation for built-in attributes. Using `include!` because rustdoc
414// only looks for these modules at the crate level.
415include!("attribute_docs.rs");
416
417// Include a number of private modules that exist solely to provide
418// the rustdoc documentation for the existing keywords. Using `include!`
419// because rustdoc only looks for these modules at the crate level.
420include!("keyword_docs.rs");
421
422// Include a number of private modules that exist solely to provide
423// the rustdoc documentation for primitive types. Using `include!`
424// because rustdoc only looks for these modules at the crate level.
425include!("primitive_docs.rs");