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