]> git.lizzy.rs Git - rust.git/blob - src/libcore/lib.rs
Rollup merge of #69651 - Mark-Simulacrum:black-box-marker, r=eddyb
[rust.git] / src / libcore / lib.rs
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` - 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 libcore defines many fundamental lang items, all tests live in a
42 // separate crate, libcoretest, 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 libcore) 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 #![stable(feature = "core", since = "1.6.0")]
53 #![doc(
54     html_root_url = "https://doc.rust-lang.org/nightly/",
55     html_playground_url = "https://play.rust-lang.org/",
56     issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
57     test(no_crate_inject, attr(deny(warnings))),
58     test(attr(allow(dead_code, deprecated, unused_variables, unused_mut)))
59 )]
60 #![no_core]
61 #![warn(deprecated_in_future)]
62 #![warn(missing_docs)]
63 #![warn(missing_debug_implementations)]
64 #![deny(intra_doc_link_resolution_failure)] // rustdoc is run without -D warnings
65 #![allow(explicit_outlives_requirements)]
66 #![allow(incomplete_features)]
67 #![feature(allow_internal_unstable)]
68 #![feature(arbitrary_self_types)]
69 #![feature(asm)]
70 #![feature(bound_cloned)]
71 #![feature(cfg_target_has_atomic)]
72 #![feature(concat_idents)]
73 #![feature(const_ascii_ctype_on_intrinsics)]
74 #![feature(const_alloc_layout)]
75 #![feature(const_if_match)]
76 #![feature(const_loop)]
77 #![feature(const_checked_int_methods)]
78 #![feature(const_euclidean_int_methods)]
79 #![feature(const_overflowing_int_methods)]
80 #![feature(const_saturating_int_methods)]
81 #![feature(const_int_unchecked_arith)]
82 #![feature(const_int_pow)]
83 #![feature(constctlz)]
84 #![feature(const_panic)]
85 #![feature(const_fn_union)]
86 #![feature(const_generics)]
87 #![feature(const_ptr_offset_from)]
88 #![feature(const_result)]
89 #![feature(const_type_name)]
90 #![feature(custom_inner_attributes)]
91 #![feature(decl_macro)]
92 #![feature(doc_cfg)]
93 #![feature(doc_spotlight)]
94 #![feature(extern_types)]
95 #![feature(fundamental)]
96 #![feature(intrinsics)]
97 #![feature(try_find)]
98 #![feature(is_sorted)]
99 #![feature(lang_items)]
100 #![feature(link_llvm_intrinsics)]
101 #![feature(never_type)]
102 #![feature(nll)]
103 #![feature(exhaustive_patterns)]
104 #![feature(no_core)]
105 #![feature(optin_builtin_traits)]
106 #![feature(prelude_import)]
107 #![feature(repr_simd, platform_intrinsics)]
108 #![feature(rustc_attrs)]
109 #![feature(simd_ffi)]
110 #![feature(specialization)]
111 #![feature(staged_api)]
112 #![feature(std_internals)]
113 #![feature(stmt_expr_attributes)]
114 #![feature(track_caller)]
115 #![feature(transparent_unions)]
116 #![feature(unboxed_closures)]
117 #![feature(unsized_locals)]
118 #![feature(untagged_unions)]
119 #![feature(unwind_attributes)]
120 #![feature(doc_alias)]
121 #![feature(mmx_target_feature)]
122 #![feature(tbm_target_feature)]
123 #![feature(sse4a_target_feature)]
124 #![feature(arm_target_feature)]
125 #![feature(powerpc_target_feature)]
126 #![feature(mips_target_feature)]
127 #![feature(aarch64_target_feature)]
128 #![feature(wasm_target_feature)]
129 #![feature(avx512_target_feature)]
130 #![feature(cmpxchg16b_target_feature)]
131 #![feature(rtm_target_feature)]
132 #![feature(f16c_target_feature)]
133 #![feature(hexagon_target_feature)]
134 #![feature(const_int_conversion)]
135 #![feature(const_transmute)]
136 #![feature(structural_match)]
137 #![feature(abi_unadjusted)]
138 #![feature(adx_target_feature)]
139 #![feature(maybe_uninit_slice)]
140 #![feature(external_doc)]
141 #![feature(associated_type_bounds)]
142 #![feature(const_type_id)]
143 #![feature(const_caller_location)]
144 #![cfg_attr(not(bootstrap), feature(no_niche))] // rust-lang/rust#68303
145
146 #[prelude_import]
147 #[allow(unused)]
148 use prelude::v1::*;
149
150 #[cfg(not(test))] // See #65860
151 #[macro_use]
152 mod macros;
153
154 #[macro_use]
155 mod internal_macros;
156
157 #[path = "num/int_macros.rs"]
158 #[macro_use]
159 mod int_macros;
160
161 #[path = "num/i128.rs"]
162 pub mod i128;
163 #[path = "num/i16.rs"]
164 pub mod i16;
165 #[path = "num/i32.rs"]
166 pub mod i32;
167 #[path = "num/i64.rs"]
168 pub mod i64;
169 #[path = "num/i8.rs"]
170 pub mod i8;
171 #[path = "num/isize.rs"]
172 pub mod isize;
173
174 #[path = "num/u128.rs"]
175 pub mod u128;
176 #[path = "num/u16.rs"]
177 pub mod u16;
178 #[path = "num/u32.rs"]
179 pub mod u32;
180 #[path = "num/u64.rs"]
181 pub mod u64;
182 #[path = "num/u8.rs"]
183 pub mod u8;
184 #[path = "num/usize.rs"]
185 pub mod usize;
186
187 #[path = "num/f32.rs"]
188 pub mod f32;
189 #[path = "num/f64.rs"]
190 pub mod f64;
191
192 #[macro_use]
193 pub mod num;
194
195 /* The libcore prelude, not as all-encompassing as the libstd prelude */
196
197 pub mod prelude;
198
199 /* Core modules for ownership management */
200
201 pub mod hint;
202 pub mod intrinsics;
203 pub mod mem;
204 pub mod ptr;
205
206 /* Core language traits */
207
208 pub mod borrow;
209 #[cfg(not(test))] // See #65860
210 pub mod clone;
211 #[cfg(not(test))] // See #65860
212 pub mod cmp;
213 pub mod convert;
214 #[cfg(not(test))] // See #65860
215 pub mod default;
216 #[cfg(not(test))] // See #65860
217 pub mod marker;
218 pub mod ops;
219
220 /* Core types and methods on primitives */
221
222 pub mod any;
223 #[cfg(not(test))] // See #65860
224 pub mod array;
225 pub mod ascii;
226 pub mod cell;
227 pub mod char;
228 pub mod ffi;
229 #[cfg(not(test))] // See #65860
230 pub mod iter;
231 pub mod option;
232 pub mod panic;
233 pub mod panicking;
234 #[cfg(not(test))] // See #65860
235 pub mod pin;
236 pub mod raw;
237 pub mod result;
238 pub mod sync;
239
240 #[cfg(not(test))] // See #65860
241 pub mod fmt;
242 #[cfg(not(test))] // See #65860
243 pub mod hash;
244 pub mod slice;
245 #[cfg(not(test))] // See #65860
246 pub mod str;
247 pub mod time;
248
249 pub mod unicode;
250
251 /* Async */
252 #[cfg(not(test))] // See #65860
253 pub mod future;
254 pub mod task;
255
256 /* Heap memory allocator trait */
257 #[allow(missing_docs)]
258 pub mod alloc;
259
260 // note: does not need to be public
261 mod bool;
262 mod tuple;
263 mod unit;
264
265 #[stable(feature = "core_primitive", since = "1.43.0")]
266 pub mod primitive;
267
268 // Pull in the `core_arch` crate directly into libcore. The contents of
269 // `core_arch` are in a different repository: rust-lang/stdarch.
270 //
271 // `core_arch` depends on libcore, but the contents of this module are
272 // set up in such a way that directly pulling it here works such that the
273 // crate uses the this crate as its libcore.
274 #[path = "../stdarch/crates/core_arch/src/mod.rs"]
275 #[allow(missing_docs, missing_debug_implementations, dead_code, unused_imports)]
276 #[unstable(feature = "stdsimd", issue = "48556")]
277 mod core_arch;
278
279 #[stable(feature = "simd_arch", since = "1.27.0")]
280 pub use core_arch::arch;