]> git.lizzy.rs Git - rust.git/blob - src/libcore/lib.rs
Rollup merge of #57791 - estebank:issue-54582, r=zackmdavis
[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 [rlibc crate](https://crates.io/crates/rlibc).
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 "duplicate lang item found" error. See
48 // discussion in #50466 for details.
49 //
50 // This cfg won't affect doc tests.
51 #![cfg(not(test))]
52
53 #![stable(feature = "core", since = "1.6.0")]
54 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
55        html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
56        html_root_url = "https://doc.rust-lang.org/nightly/",
57        html_playground_url = "https://play.rust-lang.org/",
58        issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
59        test(no_crate_inject, attr(deny(warnings))),
60        test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))))]
61
62 #![no_core]
63 #![deny(missing_docs)]
64 #![deny(intra_doc_link_resolution_failure)]
65 #![deny(missing_debug_implementations)]
66
67 #![feature(allow_internal_unstable)]
68 #![feature(arbitrary_self_types)]
69 #![feature(asm)]
70 #![feature(associated_type_defaults)]
71 #![feature(cfg_target_has_atomic)]
72 #![feature(concat_idents)]
73 #![feature(const_fn)]
74 #![cfg_attr(stage0, feature(const_int_ops))]
75 #![feature(const_fn_union)]
76 #![feature(custom_attribute)]
77 #![feature(doc_cfg)]
78 #![feature(doc_spotlight)]
79 #![feature(extern_types)]
80 #![feature(fundamental)]
81 #![feature(intrinsics)]
82 #![feature(is_sorted)]
83 #![feature(iter_once_with)]
84 #![feature(lang_items)]
85 #![feature(link_llvm_intrinsics)]
86 #![feature(never_type)]
87 #![feature(nll)]
88 #![feature(bind_by_move_pattern_guards)]
89 #![feature(exhaustive_patterns)]
90 #![feature(no_core)]
91 #![feature(on_unimplemented)]
92 #![feature(optin_builtin_traits)]
93 #![feature(prelude_import)]
94 #![feature(repr_simd, platform_intrinsics)]
95 #![feature(rustc_attrs)]
96 #![feature(rustc_const_unstable)]
97 #![feature(simd_ffi)]
98 #![feature(specialization)]
99 #![feature(staged_api)]
100 #![feature(stmt_expr_attributes)]
101 #![feature(unboxed_closures)]
102 #![feature(unsized_locals)]
103 #![feature(untagged_unions)]
104 #![feature(unwind_attributes)]
105 #![feature(doc_alias)]
106 #![feature(mmx_target_feature)]
107 #![feature(tbm_target_feature)]
108 #![feature(sse4a_target_feature)]
109 #![feature(arm_target_feature)]
110 #![feature(powerpc_target_feature)]
111 #![feature(mips_target_feature)]
112 #![feature(aarch64_target_feature)]
113 #![feature(wasm_target_feature)]
114 #![feature(avx512_target_feature)]
115 #![cfg_attr(not(stage0), feature(cmpxchg16b_target_feature))]
116 #![feature(const_slice_len)]
117 #![feature(const_str_as_bytes)]
118 #![feature(const_str_len)]
119 #![cfg_attr(stage0, feature(const_let))]
120 #![cfg_attr(stage0, feature(const_int_rotate))]
121 #![feature(const_int_conversion)]
122 #![feature(const_transmute)]
123 #![feature(reverse_bits)]
124 #![feature(non_exhaustive)]
125 #![feature(structural_match)]
126 #![feature(abi_unadjusted)]
127 #![cfg_attr(not(stage0), feature(adx_target_feature))]
128
129 #[prelude_import]
130 #[allow(unused)]
131 use prelude::v1::*;
132
133 #[macro_use]
134 mod macros;
135
136 #[macro_use]
137 mod internal_macros;
138
139 #[path = "num/int_macros.rs"]
140 #[macro_use]
141 mod int_macros;
142
143 #[path = "num/uint_macros.rs"]
144 #[macro_use]
145 mod uint_macros;
146
147 #[path = "num/isize.rs"] pub mod isize;
148 #[path = "num/i8.rs"]    pub mod i8;
149 #[path = "num/i16.rs"]   pub mod i16;
150 #[path = "num/i32.rs"]   pub mod i32;
151 #[path = "num/i64.rs"]   pub mod i64;
152 #[path = "num/i128.rs"]  pub mod i128;
153
154 #[path = "num/usize.rs"] pub mod usize;
155 #[path = "num/u8.rs"]    pub mod u8;
156 #[path = "num/u16.rs"]   pub mod u16;
157 #[path = "num/u32.rs"]   pub mod u32;
158 #[path = "num/u64.rs"]   pub mod u64;
159 #[path = "num/u128.rs"]  pub mod u128;
160
161 #[path = "num/f32.rs"]   pub mod f32;
162 #[path = "num/f64.rs"]   pub mod f64;
163
164 #[macro_use]
165 pub mod num;
166
167 /* The libcore prelude, not as all-encompassing as the libstd prelude */
168
169 pub mod prelude;
170
171 /* Core modules for ownership management */
172
173 pub mod intrinsics;
174 pub mod mem;
175 pub mod ptr;
176 pub mod hint;
177
178 /* Core language traits */
179
180 pub mod marker;
181 pub mod ops;
182 pub mod cmp;
183 pub mod clone;
184 pub mod default;
185 pub mod convert;
186 pub mod borrow;
187
188 /* Core types and methods on primitives */
189
190 pub mod any;
191 pub mod array;
192 pub mod ascii;
193 pub mod sync;
194 pub mod cell;
195 pub mod char;
196 pub mod panic;
197 pub mod panicking;
198 pub mod pin;
199 pub mod iter;
200 pub mod option;
201 pub mod raw;
202 pub mod result;
203 pub mod ffi;
204
205 pub mod slice;
206 pub mod str;
207 pub mod hash;
208 pub mod fmt;
209 pub mod time;
210
211 pub mod unicode;
212
213 /* Async */
214 pub mod future;
215 pub mod task;
216
217 /* Heap memory allocator trait */
218 #[allow(missing_docs)]
219 pub mod alloc;
220
221 // note: does not need to be public
222 mod iter_private;
223 mod tuple;
224 mod unit;
225
226 // Pull in the `coresimd` crate directly into libcore. This is where all the
227 // architecture-specific (and vendor-specific) intrinsics are defined. AKA
228 // things like SIMD and such. Note that the actual source for all this lies in a
229 // different repository, rust-lang-nursery/stdsimd. That's why the setup here is
230 // a bit wonky.
231 #[allow(unused_macros)]
232 macro_rules! test_v16 { ($item:item) => {}; }
233 #[allow(unused_macros)]
234 macro_rules! test_v32 { ($item:item) => {}; }
235 #[allow(unused_macros)]
236 macro_rules! test_v64 { ($item:item) => {}; }
237 #[allow(unused_macros)]
238 macro_rules! test_v128 { ($item:item) => {}; }
239 #[allow(unused_macros)]
240 macro_rules! test_v256 { ($item:item) => {}; }
241 #[allow(unused_macros)]
242 macro_rules! test_v512 { ($item:item) => {}; }
243 #[allow(unused_macros)]
244 macro_rules! vector_impl { ($([$f:ident, $($args:tt)*]),*) => { $($f!($($args)*);)* } }
245 #[path = "../stdsimd/coresimd/mod.rs"]
246 #[allow(missing_docs, missing_debug_implementations, dead_code, unused_imports)]
247 #[unstable(feature = "stdsimd", issue = "48556")]
248 mod coresimd;
249
250 #[stable(feature = "simd_arch", since = "1.27.0")]
251 pub use coresimd::arch;