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