]> git.lizzy.rs Git - rust.git/blob - library/core/src/lib.rs
Auto merge of #80267 - 0urobor0s:ouro/61592, r=jyn514
[rust.git] / library / core / src / 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 #![allow(explicit_outlives_requirements)]
65 #![allow(incomplete_features)]
66 #![feature(rustc_allow_const_fn_unstable)]
67 #![feature(allow_internal_unstable)]
68 #![feature(arbitrary_self_types)]
69 #![feature(asm)]
70 #![feature(cfg_target_has_atomic)]
71 #![feature(const_heap)]
72 #![feature(const_alloc_layout)]
73 #![feature(const_assert_type)]
74 #![feature(const_discriminant)]
75 #![feature(const_cell_into_inner)]
76 #![feature(const_intrinsic_copy)]
77 #![feature(const_checked_int_methods)]
78 #![feature(const_euclidean_int_methods)]
79 #![feature(const_float_classify)]
80 #![feature(const_float_bits_conv)]
81 #![feature(const_overflowing_int_methods)]
82 #![feature(const_int_unchecked_arith)]
83 #![feature(const_mut_refs)]
84 #![feature(const_cttz)]
85 #![feature(const_panic)]
86 #![feature(const_pin)]
87 #![feature(const_fn)]
88 #![feature(const_fn_union)]
89 #![feature(const_impl_trait)]
90 #![feature(const_fn_floating_point_arithmetic)]
91 #![feature(const_fn_fn_ptr_basics)]
92 #![feature(const_generics)]
93 #![feature(const_option)]
94 #![feature(const_precise_live_drops)]
95 #![feature(const_ptr_offset)]
96 #![feature(const_ptr_offset_from)]
97 #![feature(const_ptr_read)]
98 #![feature(const_raw_ptr_comparison)]
99 #![feature(const_raw_ptr_deref)]
100 #![feature(const_slice_from_raw_parts)]
101 #![feature(const_slice_ptr_len)]
102 #![feature(const_size_of_val)]
103 #![feature(const_align_of_val)]
104 #![feature(const_type_id)]
105 #![feature(const_type_name)]
106 #![feature(const_likely)]
107 #![feature(const_unreachable_unchecked)]
108 #![feature(const_maybe_uninit_assume_init)]
109 #![feature(const_maybe_uninit_as_ptr)]
110 #![feature(custom_inner_attributes)]
111 #![feature(decl_macro)]
112 #![feature(doc_cfg)]
113 #![feature(doc_spotlight)]
114 #![feature(duration_consts_2)]
115 #![feature(duration_saturating_ops)]
116 #![feature(extended_key_value_attributes)]
117 #![feature(extern_types)]
118 #![feature(fundamental)]
119 #![feature(intrinsics)]
120 #![feature(lang_items)]
121 #![feature(link_llvm_intrinsics)]
122 #![feature(llvm_asm)]
123 #![feature(negative_impls)]
124 #![feature(never_type)]
125 #![feature(nll)]
126 #![feature(exhaustive_patterns)]
127 #![feature(no_core)]
128 #![feature(auto_traits)]
129 #![feature(or_patterns)]
130 #![feature(prelude_import)]
131 #![feature(repr_simd, platform_intrinsics)]
132 #![feature(rustc_attrs)]
133 #![feature(simd_ffi)]
134 #![feature(min_specialization)]
135 #![feature(staged_api)]
136 #![feature(std_internals)]
137 #![feature(stmt_expr_attributes)]
138 #![feature(str_split_as_str)]
139 #![feature(str_split_inclusive_as_str)]
140 #![feature(transparent_unions)]
141 #![feature(try_blocks)]
142 #![feature(unboxed_closures)]
143 #![feature(unsized_fn_params)]
144 #![feature(unwind_attributes)]
145 #![feature(variant_count)]
146 #![feature(tbm_target_feature)]
147 #![feature(sse4a_target_feature)]
148 #![feature(arm_target_feature)]
149 #![feature(powerpc_target_feature)]
150 #![feature(mips_target_feature)]
151 #![feature(aarch64_target_feature)]
152 #![feature(wasm_target_feature)]
153 #![feature(avx512_target_feature)]
154 #![feature(cmpxchg16b_target_feature)]
155 #![feature(rtm_target_feature)]
156 #![feature(f16c_target_feature)]
157 #![feature(hexagon_target_feature)]
158 #![feature(const_fn_transmute)]
159 #![feature(abi_unadjusted)]
160 #![feature(adx_target_feature)]
161 #![feature(external_doc)]
162 #![feature(associated_type_bounds)]
163 #![feature(const_caller_location)]
164 #![feature(slice_ptr_get)]
165 #![feature(no_niche)] // rust-lang/rust#68303
166 #![feature(unsafe_block_in_unsafe_fn)]
167 #![feature(int_error_matching)]
168 #![deny(unsafe_op_in_unsafe_fn)]
169
170 #[prelude_import]
171 #[allow(unused)]
172 use prelude::v1::*;
173
174 #[cfg(not(test))] // See #65860
175 #[macro_use]
176 mod macros;
177
178 #[macro_use]
179 mod internal_macros;
180
181 #[path = "num/shells/int_macros.rs"]
182 #[macro_use]
183 mod int_macros;
184
185 #[path = "num/shells/i128.rs"]
186 pub mod i128;
187 #[path = "num/shells/i16.rs"]
188 pub mod i16;
189 #[path = "num/shells/i32.rs"]
190 pub mod i32;
191 #[path = "num/shells/i64.rs"]
192 pub mod i64;
193 #[path = "num/shells/i8.rs"]
194 pub mod i8;
195 #[path = "num/shells/isize.rs"]
196 pub mod isize;
197
198 #[path = "num/shells/u128.rs"]
199 pub mod u128;
200 #[path = "num/shells/u16.rs"]
201 pub mod u16;
202 #[path = "num/shells/u32.rs"]
203 pub mod u32;
204 #[path = "num/shells/u64.rs"]
205 pub mod u64;
206 #[path = "num/shells/u8.rs"]
207 pub mod u8;
208 #[path = "num/shells/usize.rs"]
209 pub mod usize;
210
211 #[path = "num/f32.rs"]
212 pub mod f32;
213 #[path = "num/f64.rs"]
214 pub mod f64;
215
216 #[macro_use]
217 pub mod num;
218
219 /* The libcore prelude, not as all-encompassing as the libstd prelude */
220
221 pub mod prelude;
222
223 /* Core modules for ownership management */
224
225 pub mod hint;
226 pub mod intrinsics;
227 pub mod mem;
228 pub mod ptr;
229
230 /* Core language traits */
231
232 pub mod borrow;
233 pub mod clone;
234 pub mod cmp;
235 pub mod convert;
236 pub mod default;
237 pub mod marker;
238 pub mod ops;
239
240 /* Core types and methods on primitives */
241
242 pub mod any;
243 pub mod array;
244 pub mod ascii;
245 pub mod cell;
246 pub mod char;
247 pub mod ffi;
248 pub mod iter;
249 #[unstable(feature = "once_cell", issue = "74465")]
250 pub mod lazy;
251 pub mod option;
252 pub mod panic;
253 pub mod panicking;
254 pub mod pin;
255 pub mod raw;
256 pub mod result;
257 pub mod sync;
258
259 pub mod fmt;
260 pub mod hash;
261 pub mod slice;
262 pub mod str;
263 pub mod time;
264
265 pub mod unicode;
266
267 /* Async */
268 pub mod future;
269 pub mod task;
270
271 /* Heap memory allocator trait */
272 #[allow(missing_docs)]
273 pub mod alloc;
274
275 // note: does not need to be public
276 mod bool;
277 mod tuple;
278 mod unit;
279
280 #[stable(feature = "core_primitive", since = "1.43.0")]
281 pub mod primitive;
282
283 // Pull in the `core_arch` crate directly into libcore. The contents of
284 // `core_arch` are in a different repository: rust-lang/stdarch.
285 //
286 // `core_arch` depends on libcore, but the contents of this module are
287 // set up in such a way that directly pulling it here works such that the
288 // crate uses the this crate as its libcore.
289 #[path = "../../stdarch/crates/core_arch/src/mod.rs"]
290 #[allow(
291     missing_docs,
292     missing_debug_implementations,
293     dead_code,
294     unused_imports,
295     unsafe_op_in_unsafe_fn
296 )]
297 #[allow(non_autolinks)]
298 // FIXME: This annotation should be moved into rust-lang/stdarch after clashing_extern_declarations is
299 // merged. It currently cannot because bootstrap fails as the lint hasn't been defined yet.
300 #[allow(clashing_extern_declarations)]
301 #[unstable(feature = "stdsimd", issue = "48556")]
302 mod core_arch;
303
304 #[stable(feature = "simd_arch", since = "1.27.0")]
305 pub use core_arch::arch;