]> git.proxmox.com Git - rustc.git/blame - library/core/src/lib.rs
Merge 1.70 into proxmox/bookworm
[rustc.git] / library / core / src / lib.rs
CommitLineData
1a4d82fc
JJ
1//! # The Rust Core Library
2//!
92a42be0 3//! The Rust Core Library is the dependency-free[^free] foundation of [The
1a4d82fc
JJ
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//!
92a42be0
SL
9//! [^free]: Strictly speaking, there are some symbols which are needed but
10//! they aren't always necessary.
11//!
1a4d82fc
JJ
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//!
1a4d82fc
JJ
16//! # How to use the core library
17//!
5bcae85e
SL
18//! Please note that all of these details are currently not considered stable.
19//!
1a4d82fc
JJ
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//!
04454e1e 23//! * `memcpy`, `memcmp`, `memset`, `strlen` - These are core memory routines which are
1a4d82fc
JJ
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
9fa01778 27//! provided by the [compiler-builtins crate](https://crates.io/crates/compiler_builtins).
1a4d82fc 28//!
041b39d2
XL
29//! * `rust_begin_panic` - This function takes four arguments, a
30//! `fmt::Arguments`, a `&'static str`, and two `u32`'s. These four arguments
5bcae85e 31//! dictate the panic message, the file at which panic was invoked, and the
041b39d2
XL
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
94b46f34 34//! return. This requires a `lang` attribute named `panic_impl`.
9e0c209e
SL
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`.
1a4d82fc 40
9c376795
FG
41// Since core defines many fundamental lang items, all tests live in a
42// separate crate, libcoretest (library/core/tests), to avoid bizarre issues.
83c7162d
XL
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
9c376795 46// transitively includes core) will both define the same set of lang items,
dfeec247 47// and this will cause the E0152 "found duplicate lang item" error. See
83c7162d
XL
48// discussion in #50466 for details.
49//
50// This cfg won't affect doc tests.
51#![cfg(not(test))]
9c376795 52// To run core tests without x.py without ending up with two copies of core, Miri needs to be
136023e0
XL
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))]
92a42be0 56#![stable(feature = "core", since = "1.6.0")]
dfeec247 57#![doc(
dfeec247
XL
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)]
5099ac24
FG
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))]
e9174d1e 86#![no_core]
04454e1e 87#![rustc_coherence_is_core]
94222f64
XL
88//
89// Lints:
90#![deny(rust_2021_incompatible_or_patterns)]
91#![deny(unsafe_op_in_unsafe_fn)]
487cf647 92#![deny(fuzzy_provenance_casts)]
9fa01778 93#![warn(deprecated_in_future)]
9fa01778 94#![warn(missing_debug_implementations)]
94222f64 95#![warn(missing_docs)]
48663c56 96#![allow(explicit_outlives_requirements)]
f2b60f7d 97#![allow(incomplete_features)]
353b0b11 98#![warn(multiple_supertrait_upcastable)]
94222f64 99//
5e7ed085 100// Library features:
353b0b11
FG
101// tidy-alphabetical-start
102#![feature(char_indices_offset)]
94222f64 103#![feature(const_align_of_val)]
487cf647 104#![feature(const_align_of_val_raw)]
353b0b11 105#![feature(const_align_offset)]
487cf647 106#![feature(const_alloc_layout)]
94222f64 107#![feature(const_arguments_as_str)]
353b0b11 108#![feature(const_array_from_ref)]
a2a8927a 109#![feature(const_array_into_iter_constructors)]
94222f64 110#![feature(const_bigint_helper_methods)]
a2a8927a 111#![feature(const_black_box)]
94222f64 112#![feature(const_caller_location)]
29967ef6 113#![feature(const_cell_into_inner)]
487cf647 114#![feature(const_char_from_u32_unchecked)]
5e7ed085 115#![feature(const_clone)]
064997fb 116#![feature(const_cmp)]
353b0b11
FG
117#![feature(const_convert)]
118#![feature(const_cstr_methods)]
119#![feature(const_default_impls)]
94222f64 120#![feature(const_discriminant)]
3c0e092e 121#![feature(const_eval_select)]
487cf647 122#![feature(const_exact_div)]
3dfed10e 123#![feature(const_float_bits_conv)]
94222f64 124#![feature(const_float_classify)]
3c0e092e 125#![feature(const_fmt_arguments_new)]
487cf647 126#![feature(const_hash)]
94222f64 127#![feature(const_heap)]
2b03887a 128#![feature(const_index_range_slice_index)]
17df50a5 129#![feature(const_inherent_unchecked_arith)]
94222f64 130#![feature(const_int_unchecked_arith)]
94222f64 131#![feature(const_intrinsic_forget)]
9ffffee4
FG
132#![feature(const_ipv4)]
133#![feature(const_ipv6)]
353b0b11 134#![feature(const_is_char_boundary)]
94222f64 135#![feature(const_likely)]
a2a8927a 136#![feature(const_maybe_uninit_as_mut_ptr)]
94222f64 137#![feature(const_maybe_uninit_assume_init)]
353b0b11 138#![feature(const_maybe_uninit_uninit_array)]
04454e1e 139#![feature(const_nonnull_new)]
3c0e092e
XL
140#![feature(const_num_from_num)]
141#![feature(const_ops)]
3dfed10e 142#![feature(const_option)]
a2a8927a 143#![feature(const_option_ext)]
94222f64 144#![feature(const_pin)]
9ffffee4 145#![feature(const_pointer_byte_offsets)]
487cf647 146#![feature(const_pointer_is_aligned)]
04454e1e 147#![feature(const_ptr_as_ref)]
a2a8927a 148#![feature(const_ptr_is_null)]
5869c6ff 149#![feature(const_ptr_read)]
353b0b11 150#![feature(const_ptr_sub_ptr)]
6a06907d 151#![feature(const_ptr_write)]
3dfed10e 152#![feature(const_raw_ptr_comparison)]
353b0b11
FG
153#![feature(const_replace)]
154#![feature(const_result_drop)]
94222f64 155#![feature(const_size_of_val)]
487cf647 156#![feature(const_size_of_val_raw)]
064997fb 157#![feature(const_slice_from_raw_parts_mut)]
353b0b11
FG
158#![feature(const_slice_from_ref)]
159#![feature(const_slice_index)]
f9f354fc 160#![feature(const_slice_ptr_len)]
2b03887a 161#![feature(const_slice_split_at_mut)]
3c0e092e 162#![feature(const_str_from_utf8_unchecked_mut)]
6a06907d 163#![feature(const_swap)]
94222f64 164#![feature(const_trait_impl)]
353b0b11 165#![feature(const_transmute_copy)]
2b03887a 166#![feature(const_try)]
6c58768f 167#![feature(const_type_id)]
dfeec247 168#![feature(const_type_name)]
f2b60f7d 169#![feature(const_unicode_case_lookup)]
04454e1e 170#![feature(const_unsafecell_get_mut)]
2b03887a 171#![feature(const_waker)]
a2a8927a 172#![feature(core_panic)]
3c0e092e 173#![feature(duration_consts_float)]
353b0b11
FG
174#![feature(ip)]
175#![feature(is_ascii_octdigit)]
a2a8927a 176#![feature(maybe_uninit_uninit_array)]
2b03887a 177#![feature(ptr_alignment_type)]
94222f64 178#![feature(ptr_metadata)]
487cf647 179#![feature(set_ptr_value)]
94222f64 180#![feature(slice_ptr_get)]
f2b60f7d 181#![feature(slice_split_at_unchecked)]
3c0e092e 182#![feature(str_internals)]
9c376795 183#![feature(str_split_inclusive_remainder)]
353b0b11 184#![feature(str_split_remainder)]
487cf647 185#![feature(strict_provenance)]
5e7ed085
FG
186#![feature(utf16_extra)]
187#![feature(utf16_extra_const)]
94222f64 188#![feature(variant_count)]
353b0b11 189// tidy-alphabetical-end
94222f64
XL
190//
191// Language features:
353b0b11 192// tidy-alphabetical-start
94222f64 193#![feature(abi_unadjusted)]
f2b60f7d 194#![feature(adt_const_params)]
94222f64
XL
195#![feature(allow_internal_unsafe)]
196#![feature(allow_internal_unstable)]
353b0b11 197#![feature(asm_const)]
94222f64
XL
198#![feature(associated_type_bounds)]
199#![feature(auto_traits)]
2b03887a 200#![feature(c_unwind)]
064997fb 201#![feature(cfg_sanitize)]
94222f64 202#![feature(cfg_target_has_atomic)]
5e7ed085 203#![feature(cfg_target_has_atomic_equal_alignment)]
9ffffee4 204#![feature(const_closures)]
94222f64 205#![feature(const_fn_floating_point_arithmetic)]
9ffffee4 206#![feature(const_for)]
94222f64 207#![feature(const_mut_refs)]
94222f64 208#![feature(const_precise_live_drops)]
94222f64 209#![feature(const_refs_to_cell)]
416331ca 210#![feature(decl_macro)]
04454e1e 211#![feature(deprecated_suggestion)]
9c376795 212#![feature(derive_const)]
0531ce1d 213#![feature(doc_cfg)]
353b0b11 214#![feature(doc_cfg_hide)]
17df50a5 215#![feature(doc_notable_trait)]
94222f64 216#![feature(exhaustive_patterns)]
83c7162d 217#![feature(extern_types)]
e9174d1e 218#![feature(fundamental)]
353b0b11 219#![feature(generic_arg_infer)]
94222f64 220#![feature(if_let_guard)]
2b03887a 221#![feature(inline_const)]
6a06907d 222#![feature(intra_doc_pointers)]
62682a34
SL
223#![feature(intrinsics)]
224#![feature(lang_items)]
0531ce1d 225#![feature(link_llvm_intrinsics)]
04454e1e 226#![feature(macro_metavar_expr)]
94222f64 227#![feature(min_specialization)]
353b0b11 228#![feature(multiple_supertrait_upcastable)]
3c0e092e 229#![feature(must_not_suspend)]
f9f354fc 230#![feature(negative_impls)]
cc61c64b 231#![feature(never_type)]
e9174d1e 232#![feature(no_core)]
94222f64 233#![feature(no_coverage)] // rust-lang/rust#84605
94222f64 234#![feature(platform_intrinsics)]
cc61c64b 235#![feature(prelude_import)]
94222f64
XL
236#![feature(repr_simd)]
237#![feature(rustc_allow_const_fn_unstable)]
54a0048b 238#![feature(rustc_attrs)]
353b0b11 239#![feature(rustdoc_internals)]
0531ce1d 240#![feature(simd_ffi)]
e9174d1e 241#![feature(staged_api)]
0531ce1d 242#![feature(stmt_expr_attributes)]
2b03887a 243#![feature(target_feature_11)]
6a06907d 244#![feature(trait_alias)]
416331ca 245#![feature(transparent_unions)]
29967ef6 246#![feature(try_blocks)]
e9174d1e 247#![feature(unboxed_closures)]
fc512014 248#![feature(unsized_fn_params)]
353b0b11 249// tidy-alphabetical-end
94222f64
XL
250//
251// Target features:
353b0b11 252// tidy-alphabetical-start
94222f64 253#![feature(arm_target_feature)]
0731742a 254#![feature(avx512_target_feature)]
416331ca 255#![feature(hexagon_target_feature)]
94222f64
XL
256#![feature(mips_target_feature)]
257#![feature(powerpc_target_feature)]
2b03887a 258#![feature(riscv_target_feature)]
94222f64
XL
259#![feature(rtm_target_feature)]
260#![feature(sse4a_target_feature)]
261#![feature(tbm_target_feature)]
262#![feature(wasm_target_feature)]
353b0b11 263// tidy-alphabetical-end
17df50a5
XL
264
265// allow using `core::` in intra-doc links
266#[allow(unused_extern_crates)]
267extern crate self as core;
ea8adc8c 268
9e0c209e
SL
269#[prelude_import]
270#[allow(unused)]
271use prelude::v1::*;
5bcae85e 272
e74abb32 273#[cfg(not(test))] // See #65860
1a4d82fc
JJ
274#[macro_use]
275mod macros;
276
17df50a5
XL
277// We don't export this through #[macro_export] for now, to avoid breakage.
278// See https://github.com/rust-lang/rust/issues/82913
279#[cfg(not(test))]
280#[unstable(feature = "assert_matches", issue = "82775")]
281/// Unstable module containing the unstable `assert_matches` macro.
282pub mod assert_matches {
283 #[unstable(feature = "assert_matches", issue = "82775")]
284 pub use crate::macros::{assert_matches, debug_assert_matches};
285}
286
c30ab7b3
SL
287#[macro_use]
288mod internal_macros;
289
1b1a35ee 290#[path = "num/shells/int_macros.rs"]
1a4d82fc
JJ
291#[macro_use]
292mod int_macros;
293
1b1a35ee 294#[path = "num/shells/i128.rs"]
dfeec247 295pub mod i128;
1b1a35ee 296#[path = "num/shells/i16.rs"]
dfeec247 297pub mod i16;
1b1a35ee 298#[path = "num/shells/i32.rs"]
dfeec247 299pub mod i32;
1b1a35ee 300#[path = "num/shells/i64.rs"]
dfeec247 301pub mod i64;
1b1a35ee 302#[path = "num/shells/i8.rs"]
dfeec247 303pub mod i8;
1b1a35ee 304#[path = "num/shells/isize.rs"]
dfeec247 305pub mod isize;
32a655c1 306
1b1a35ee 307#[path = "num/shells/u128.rs"]
dfeec247 308pub mod u128;
1b1a35ee 309#[path = "num/shells/u16.rs"]
dfeec247 310pub mod u16;
1b1a35ee 311#[path = "num/shells/u32.rs"]
dfeec247 312pub mod u32;
1b1a35ee 313#[path = "num/shells/u64.rs"]
dfeec247 314pub mod u64;
1b1a35ee 315#[path = "num/shells/u8.rs"]
dfeec247 316pub mod u8;
1b1a35ee 317#[path = "num/shells/usize.rs"]
dfeec247 318pub mod usize;
32a655c1 319
dfeec247
XL
320#[path = "num/f32.rs"]
321pub mod f32;
322#[path = "num/f64.rs"]
323pub mod f64;
1a4d82fc 324
9346a6ac 325#[macro_use]
1a4d82fc
JJ
326pub mod num;
327
9c376795 328/* The core prelude, not as all-encompassing as the std prelude */
1a4d82fc
JJ
329
330pub mod prelude;
331
332/* Core modules for ownership management */
333
dfeec247 334pub mod hint;
1a4d82fc
JJ
335pub mod intrinsics;
336pub mod mem;
1a4d82fc
JJ
337pub mod ptr;
338
339/* Core language traits */
340
dfeec247 341pub mod borrow;
dfeec247 342pub mod clone;
1a4d82fc 343pub mod cmp;
dfeec247 344pub mod convert;
1a4d82fc 345pub mod default;
f2b60f7d 346pub mod error;
dfeec247
XL
347pub mod marker;
348pub mod ops;
1a4d82fc
JJ
349
350/* Core types and methods on primitives */
351
352pub mod any;
c34b1796 353pub mod array;
0531ce1d 354pub mod ascii;
923072b8 355pub mod asserting;
5099ac24
FG
356#[unstable(feature = "async_iterator", issue = "79024")]
357pub mod async_iter;
1a4d82fc
JJ
358pub mod cell;
359pub mod char;
dfeec247 360pub mod ffi;
dfeec247 361pub mod iter;
9ffffee4 362pub mod net;
dfeec247 363pub mod option;
0531ce1d 364pub mod panic;
1a4d82fc 365pub mod panicking;
b7449926 366pub mod pin;
1a4d82fc 367pub mod result;
dfeec247 368pub mod sync;
e9174d1e 369
dfeec247 370pub mod fmt;
1a4d82fc 371pub mod hash;
dfeec247 372pub mod slice;
dfeec247 373pub mod str;
2c00a5a8 374pub mod time;
85aaf69f 375
83c7162d
XL
376pub mod unicode;
377
94b46f34
XL
378/* Async */
379pub mod future;
380pub mod task;
381
0531ce1d
XL
382/* Heap memory allocator trait */
383#[allow(missing_docs)]
83c7162d
XL
384pub mod alloc;
385
1a4d82fc 386// note: does not need to be public
e1599b0c 387mod bool;
1a4d82fc 388mod tuple;
abe05a73 389mod unit;
0531ce1d 390
74b04a01
XL
391#[stable(feature = "core_primitive", since = "1.43.0")]
392pub mod primitive;
393
9c376795 394// Pull in the `core_arch` crate directly into core. The contents of
416331ca 395// `core_arch` are in a different repository: rust-lang/stdarch.
9fa01778 396//
9c376795 397// `core_arch` depends on core, but the contents of this module are
9fa01778 398// set up in such a way that directly pulling it here works such that the
9c376795 399// crate uses the this crate as its core.
3dfed10e 400#[path = "../../stdarch/crates/core_arch/src/mod.rs"]
f035d41b
XL
401#[allow(
402 missing_docs,
403 missing_debug_implementations,
404 dead_code,
405 unused_imports,
406 unsafe_op_in_unsafe_fn
407)]
17df50a5 408#[allow(rustdoc::bare_urls)]
f035d41b
XL
409// FIXME: This annotation should be moved into rust-lang/stdarch after clashing_extern_declarations is
410// merged. It currently cannot because bootstrap fails as the lint hasn't been defined yet.
3dfed10e 411#[allow(clashing_extern_declarations)]
0531ce1d 412#[unstable(feature = "stdsimd", issue = "48556")]
9fa01778 413mod core_arch;
0531ce1d 414
83c7162d 415#[stable(feature = "simd_arch", since = "1.27.0")]
487cf647 416pub mod arch;
c295e0f8 417
9c376795 418// Pull in the `core_simd` crate directly into core. The contents of
a2a8927a
XL
419// `core_simd` are in a different repository: rust-lang/portable-simd.
420//
9c376795 421// `core_simd` depends on core, but the contents of this module are
a2a8927a 422// set up in such a way that directly pulling it here works such that the
9c376795 423// crate uses this crate as its core.
a2a8927a
XL
424#[path = "../../portable-simd/crates/core_simd/src/mod.rs"]
425#[allow(missing_debug_implementations, dead_code, unsafe_op_in_unsafe_fn, unused_unsafe)]
426#[allow(rustdoc::bare_urls)]
427#[unstable(feature = "portable_simd", issue = "86656")]
a2a8927a
XL
428mod core_simd;
429
430#[doc = include_str!("../../portable-simd/crates/core_simd/src/core_simd_docs.md")]
431#[unstable(feature = "portable_simd", issue = "86656")]
a2a8927a
XL
432pub mod simd {
433 #[unstable(feature = "portable_simd", issue = "86656")]
434 pub use crate::core_simd::simd::*;
435}
436
c295e0f8 437include!("primitive_docs.rs");