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