]> git.proxmox.com Git - rustc.git/blame - library/core/src/lib.rs
New upstream version 1.58.1+dfsg1
[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//!
23//! * `memcpy`, `memcmp`, `memset` - 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
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
JJ
40
41// Since libcore defines many fundamental lang items, all tests live in a
42// separate crate, libcoretest, 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
46// transitively includes libcore) 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))]
136023e0
XL
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))]
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)]
c295e0f8
XL
63#![cfg_attr(
64 not(bootstrap),
65 doc(cfg_hide(
66 not(test),
67 any(not(feature = "miri-test-libstd"), test, doctest),
68 no_fp_fmt_parse,
69 target_pointer_width = "16",
70 target_pointer_width = "32",
71 target_pointer_width = "64",
72 target_has_atomic = "8",
73 target_has_atomic = "16",
74 target_has_atomic = "32",
75 target_has_atomic = "64",
76 target_has_atomic = "ptr",
77 target_has_atomic_equal_alignment = "8",
78 target_has_atomic_equal_alignment = "16",
79 target_has_atomic_equal_alignment = "32",
80 target_has_atomic_equal_alignment = "64",
81 target_has_atomic_equal_alignment = "ptr",
82 target_has_atomic_load_store = "8",
83 target_has_atomic_load_store = "16",
84 target_has_atomic_load_store = "32",
85 target_has_atomic_load_store = "64",
86 target_has_atomic_load_store = "ptr",
87 ))
88)]
e9174d1e 89#![no_core]
94222f64
XL
90//
91// Lints:
92#![deny(rust_2021_incompatible_or_patterns)]
93#![deny(unsafe_op_in_unsafe_fn)]
9fa01778 94#![warn(deprecated_in_future)]
9fa01778 95#![warn(missing_debug_implementations)]
94222f64 96#![warn(missing_docs)]
48663c56 97#![allow(explicit_outlives_requirements)]
94222f64
XL
98//
99// Library features for const fns:
3c0e092e 100#![feature(const_align_offset)]
94222f64 101#![feature(const_align_of_val)]
dfeec247 102#![feature(const_alloc_layout)]
94222f64 103#![feature(const_arguments_as_str)]
fc512014 104#![feature(const_assert_type)]
94222f64
XL
105#![feature(const_bigint_helper_methods)]
106#![feature(const_caller_location)]
29967ef6 107#![feature(const_cell_into_inner)]
3c0e092e 108#![feature(const_char_convert)]
94222f64 109#![feature(const_discriminant)]
3c0e092e 110#![feature(const_eval_select)]
3dfed10e 111#![feature(const_float_bits_conv)]
94222f64 112#![feature(const_float_classify)]
3c0e092e 113#![feature(const_fmt_arguments_new)]
94222f64 114#![feature(const_heap)]
17df50a5 115#![feature(const_inherent_unchecked_arith)]
94222f64
XL
116#![feature(const_int_unchecked_arith)]
117#![feature(const_intrinsic_copy)]
118#![feature(const_intrinsic_forget)]
119#![feature(const_likely)]
120#![feature(const_maybe_uninit_as_ptr)]
121#![feature(const_maybe_uninit_assume_init)]
3c0e092e
XL
122#![feature(const_num_from_num)]
123#![feature(const_ops)]
3dfed10e 124#![feature(const_option)]
94222f64 125#![feature(const_pin)]
c295e0f8 126#![feature(const_replace)]
f9f354fc 127#![feature(const_ptr_offset)]
dfeec247 128#![feature(const_ptr_offset_from)]
5869c6ff 129#![feature(const_ptr_read)]
6a06907d 130#![feature(const_ptr_write)]
3dfed10e 131#![feature(const_raw_ptr_comparison)]
94222f64 132#![feature(const_size_of_val)]
f9f354fc
XL
133#![feature(const_slice_from_raw_parts)]
134#![feature(const_slice_ptr_len)]
3c0e092e 135#![feature(const_str_from_utf8_unchecked_mut)]
6a06907d 136#![feature(const_swap)]
94222f64 137#![feature(const_trait_impl)]
6c58768f 138#![feature(const_type_id)]
dfeec247 139#![feature(const_type_name)]
94222f64 140#![feature(const_default_impls)]
3c0e092e 141#![feature(duration_consts_float)]
94222f64
XL
142#![feature(ptr_metadata)]
143#![feature(slice_ptr_get)]
3c0e092e 144#![feature(str_internals)]
94222f64 145#![feature(variant_count)]
3c0e092e
XL
146#![feature(const_array_from_ref)]
147#![feature(const_slice_from_ref)]
94222f64
XL
148//
149// Language features:
150#![feature(abi_unadjusted)]
151#![feature(allow_internal_unsafe)]
152#![feature(allow_internal_unstable)]
153#![feature(asm)]
154#![feature(associated_type_bounds)]
155#![feature(auto_traits)]
156#![feature(cfg_target_has_atomic)]
157#![feature(const_fn_floating_point_arithmetic)]
158#![feature(const_fn_fn_ptr_basics)]
159#![feature(const_fn_trait_bound)]
94222f64
XL
160#![feature(const_impl_trait)]
161#![feature(const_mut_refs)]
94222f64 162#![feature(const_precise_live_drops)]
3c0e092e 163#![cfg_attr(bootstrap, feature(const_raw_ptr_deref))]
94222f64 164#![feature(const_refs_to_cell)]
416331ca 165#![feature(decl_macro)]
3c0e092e 166#![feature(derive_default_enum)]
0531ce1d 167#![feature(doc_cfg)]
17df50a5 168#![feature(doc_notable_trait)]
3c0e092e
XL
169#![cfg_attr(bootstrap, feature(doc_primitive))]
170#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
94222f64 171#![feature(exhaustive_patterns)]
3c0e092e 172#![feature(doc_cfg_hide)]
83c7162d 173#![feature(extern_types)]
e9174d1e 174#![feature(fundamental)]
94222f64 175#![feature(if_let_guard)]
6a06907d 176#![feature(intra_doc_pointers)]
62682a34
SL
177#![feature(intrinsics)]
178#![feature(lang_items)]
0531ce1d 179#![feature(link_llvm_intrinsics)]
ba9703b0 180#![feature(llvm_asm)]
94222f64 181#![feature(min_specialization)]
c295e0f8 182#![feature(mixed_integer_ops)]
3c0e092e 183#![feature(must_not_suspend)]
f9f354fc 184#![feature(negative_impls)]
cc61c64b 185#![feature(never_type)]
e9174d1e 186#![feature(no_core)]
94222f64
XL
187#![feature(no_coverage)] // rust-lang/rust#84605
188#![feature(no_niche)] // rust-lang/rust#68303
189#![feature(platform_intrinsics)]
cc61c64b 190#![feature(prelude_import)]
94222f64
XL
191#![feature(repr_simd)]
192#![feature(rustc_allow_const_fn_unstable)]
54a0048b 193#![feature(rustc_attrs)]
0531ce1d 194#![feature(simd_ffi)]
e9174d1e 195#![feature(staged_api)]
0531ce1d 196#![feature(stmt_expr_attributes)]
6a06907d 197#![feature(trait_alias)]
416331ca 198#![feature(transparent_unions)]
29967ef6 199#![feature(try_blocks)]
e9174d1e 200#![feature(unboxed_closures)]
fc512014 201#![feature(unsized_fn_params)]
3c0e092e 202#![cfg_attr(not(bootstrap), feature(asm_const))]
94222f64
XL
203//
204// Target features:
94b46f34 205#![feature(aarch64_target_feature)]
94222f64
XL
206#![feature(adx_target_feature)]
207#![feature(arm_target_feature)]
0731742a 208#![feature(avx512_target_feature)]
9fa01778 209#![feature(cmpxchg16b_target_feature)]
416331ca
XL
210#![feature(f16c_target_feature)]
211#![feature(hexagon_target_feature)]
94222f64
XL
212#![feature(mips_target_feature)]
213#![feature(powerpc_target_feature)]
214#![feature(rtm_target_feature)]
215#![feature(sse4a_target_feature)]
216#![feature(tbm_target_feature)]
217#![feature(wasm_target_feature)]
17df50a5
XL
218
219// allow using `core::` in intra-doc links
220#[allow(unused_extern_crates)]
221extern crate self as core;
ea8adc8c 222
9e0c209e
SL
223#[prelude_import]
224#[allow(unused)]
225use prelude::v1::*;
5bcae85e 226
e74abb32 227#[cfg(not(test))] // See #65860
1a4d82fc
JJ
228#[macro_use]
229mod macros;
230
17df50a5
XL
231// We don't export this through #[macro_export] for now, to avoid breakage.
232// See https://github.com/rust-lang/rust/issues/82913
233#[cfg(not(test))]
234#[unstable(feature = "assert_matches", issue = "82775")]
235/// Unstable module containing the unstable `assert_matches` macro.
236pub mod assert_matches {
237 #[unstable(feature = "assert_matches", issue = "82775")]
238 pub use crate::macros::{assert_matches, debug_assert_matches};
239}
240
c30ab7b3
SL
241#[macro_use]
242mod internal_macros;
243
1b1a35ee 244#[path = "num/shells/int_macros.rs"]
1a4d82fc
JJ
245#[macro_use]
246mod int_macros;
247
1b1a35ee 248#[path = "num/shells/i128.rs"]
dfeec247 249pub mod i128;
1b1a35ee 250#[path = "num/shells/i16.rs"]
dfeec247 251pub mod i16;
1b1a35ee 252#[path = "num/shells/i32.rs"]
dfeec247 253pub mod i32;
1b1a35ee 254#[path = "num/shells/i64.rs"]
dfeec247 255pub mod i64;
1b1a35ee 256#[path = "num/shells/i8.rs"]
dfeec247 257pub mod i8;
1b1a35ee 258#[path = "num/shells/isize.rs"]
dfeec247 259pub mod isize;
32a655c1 260
1b1a35ee 261#[path = "num/shells/u128.rs"]
dfeec247 262pub mod u128;
1b1a35ee 263#[path = "num/shells/u16.rs"]
dfeec247 264pub mod u16;
1b1a35ee 265#[path = "num/shells/u32.rs"]
dfeec247 266pub mod u32;
1b1a35ee 267#[path = "num/shells/u64.rs"]
dfeec247 268pub mod u64;
1b1a35ee 269#[path = "num/shells/u8.rs"]
dfeec247 270pub mod u8;
1b1a35ee 271#[path = "num/shells/usize.rs"]
dfeec247 272pub mod usize;
32a655c1 273
dfeec247
XL
274#[path = "num/f32.rs"]
275pub mod f32;
276#[path = "num/f64.rs"]
277pub mod f64;
1a4d82fc 278
9346a6ac 279#[macro_use]
1a4d82fc
JJ
280pub mod num;
281
282/* The libcore prelude, not as all-encompassing as the libstd prelude */
283
284pub mod prelude;
285
286/* Core modules for ownership management */
287
dfeec247 288pub mod hint;
1a4d82fc
JJ
289pub mod intrinsics;
290pub mod mem;
1a4d82fc
JJ
291pub mod ptr;
292
293/* Core language traits */
294
dfeec247 295pub mod borrow;
dfeec247 296pub mod clone;
1a4d82fc 297pub mod cmp;
dfeec247 298pub mod convert;
1a4d82fc 299pub mod default;
dfeec247
XL
300pub mod marker;
301pub mod ops;
1a4d82fc
JJ
302
303/* Core types and methods on primitives */
304
305pub mod any;
c34b1796 306pub mod array;
0531ce1d 307pub mod ascii;
1a4d82fc
JJ
308pub mod cell;
309pub mod char;
dfeec247 310pub mod ffi;
dfeec247 311pub mod iter;
3dfed10e
XL
312#[unstable(feature = "once_cell", issue = "74465")]
313pub mod lazy;
dfeec247 314pub mod option;
0531ce1d 315pub mod panic;
1a4d82fc 316pub mod panicking;
b7449926 317pub mod pin;
1a4d82fc 318pub mod result;
5869c6ff
XL
319#[unstable(feature = "async_stream", issue = "79024")]
320pub mod stream;
dfeec247 321pub mod sync;
e9174d1e 322
dfeec247 323pub mod fmt;
1a4d82fc 324pub mod hash;
dfeec247 325pub mod slice;
dfeec247 326pub mod str;
2c00a5a8 327pub mod time;
85aaf69f 328
83c7162d
XL
329pub mod unicode;
330
94b46f34
XL
331/* Async */
332pub mod future;
333pub mod task;
334
0531ce1d
XL
335/* Heap memory allocator trait */
336#[allow(missing_docs)]
83c7162d
XL
337pub mod alloc;
338
1a4d82fc 339// note: does not need to be public
e1599b0c 340mod bool;
1a4d82fc 341mod tuple;
abe05a73 342mod unit;
0531ce1d 343
74b04a01
XL
344#[stable(feature = "core_primitive", since = "1.43.0")]
345pub mod primitive;
346
9fa01778 347// Pull in the `core_arch` crate directly into libcore. The contents of
416331ca 348// `core_arch` are in a different repository: rust-lang/stdarch.
9fa01778
XL
349//
350// `core_arch` depends on libcore, but the contents of this module are
351// set up in such a way that directly pulling it here works such that the
352// crate uses the this crate as its libcore.
3dfed10e 353#[path = "../../stdarch/crates/core_arch/src/mod.rs"]
f035d41b
XL
354#[allow(
355 missing_docs,
356 missing_debug_implementations,
357 dead_code,
358 unused_imports,
359 unsafe_op_in_unsafe_fn
360)]
17df50a5 361#[allow(rustdoc::bare_urls)]
f035d41b
XL
362// FIXME: This annotation should be moved into rust-lang/stdarch after clashing_extern_declarations is
363// merged. It currently cannot because bootstrap fails as the lint hasn't been defined yet.
3dfed10e 364#[allow(clashing_extern_declarations)]
0531ce1d 365#[unstable(feature = "stdsimd", issue = "48556")]
9fa01778 366mod core_arch;
0531ce1d 367
136023e0 368#[doc = include_str!("../../stdarch/crates/core_arch/src/core_arch_docs.md")]
83c7162d 369#[stable(feature = "simd_arch", since = "1.27.0")]
136023e0
XL
370pub mod arch {
371 #[stable(feature = "simd_arch", since = "1.27.0")]
372 pub use crate::core_arch::arch::*;
373
374 /// Inline assembly.
375 ///
376 /// Read the [unstable book] for the usage.
377 ///
378 /// [unstable book]: ../../unstable-book/library-features/asm.html
379 #[unstable(
380 feature = "asm",
381 issue = "72016",
382 reason = "inline assembly is not stable enough for use and is subject to change"
383 )]
384 #[rustc_builtin_macro]
385 pub macro asm("assembly template", $(operands,)* $(options($(option),*))?) {
386 /* compiler built-in */
387 }
388
389 /// Module-level inline assembly.
390 #[unstable(
391 feature = "global_asm",
392 issue = "35119",
393 reason = "`global_asm!` is not stable enough for use and is subject to change"
394 )]
395 #[rustc_builtin_macro]
396 pub macro global_asm("assembly template", $(operands,)* $(options($(option),*))?) {
397 /* compiler built-in */
398 }
399}
c295e0f8
XL
400
401include!("primitive_docs.rs");