]> git.lizzy.rs Git - rust.git/blob - library/core/src/lib.rs
Rollup merge of #92399 - Veeupup:fix_vec_typo, r=Dylan-DPC
[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 // To run libcore tests without x.py without ending up with two copies of libcore, Miri needs to be
53 // able to "empty" this crate. See <https://github.com/rust-lang/miri-test-libstd/issues/4>.
54 // rustc itself never sets the feature, so this line has no affect there.
55 #![cfg(any(not(feature = "miri-test-libstd"), test, doctest))]
56 #![stable(feature = "core", since = "1.6.0")]
57 #![doc(
58     html_playground_url = "https://play.rust-lang.org/",
59     issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
60     test(no_crate_inject, attr(deny(warnings))),
61     test(attr(allow(dead_code, deprecated, unused_variables, unused_mut)))
62 )]
63 #![doc(cfg_hide(
64     not(test),
65     any(not(feature = "miri-test-libstd"), test, doctest),
66     no_fp_fmt_parse,
67     target_pointer_width = "16",
68     target_pointer_width = "32",
69     target_pointer_width = "64",
70     target_has_atomic = "8",
71     target_has_atomic = "16",
72     target_has_atomic = "32",
73     target_has_atomic = "64",
74     target_has_atomic = "ptr",
75     target_has_atomic_equal_alignment = "8",
76     target_has_atomic_equal_alignment = "16",
77     target_has_atomic_equal_alignment = "32",
78     target_has_atomic_equal_alignment = "64",
79     target_has_atomic_equal_alignment = "ptr",
80     target_has_atomic_load_store = "8",
81     target_has_atomic_load_store = "16",
82     target_has_atomic_load_store = "32",
83     target_has_atomic_load_store = "64",
84     target_has_atomic_load_store = "ptr",
85 ))]
86 #![no_core]
87 //
88 // Lints:
89 #![deny(rust_2021_incompatible_or_patterns)]
90 #![deny(unsafe_op_in_unsafe_fn)]
91 #![warn(deprecated_in_future)]
92 #![warn(missing_debug_implementations)]
93 #![warn(missing_docs)]
94 #![allow(explicit_outlives_requirements)]
95 //
96 // Library features for const fns:
97 #![feature(const_align_offset)]
98 #![feature(const_align_of_val)]
99 #![feature(const_alloc_layout)]
100 #![feature(const_arguments_as_str)]
101 #![feature(const_array_into_iter_constructors)]
102 #![feature(const_bigint_helper_methods)]
103 #![feature(const_black_box)]
104 #![feature(const_caller_location)]
105 #![feature(const_cell_into_inner)]
106 #![feature(const_char_convert)]
107 #![feature(const_discriminant)]
108 #![feature(const_eval_select)]
109 #![feature(const_float_bits_conv)]
110 #![feature(const_float_classify)]
111 #![feature(const_fmt_arguments_new)]
112 #![feature(const_heap)]
113 #![feature(const_convert)]
114 #![feature(const_inherent_unchecked_arith)]
115 #![feature(const_int_unchecked_arith)]
116 #![feature(const_intrinsic_copy)]
117 #![feature(const_intrinsic_forget)]
118 #![feature(const_likely)]
119 #![feature(const_maybe_uninit_as_mut_ptr)]
120 #![feature(const_maybe_uninit_assume_init)]
121 #![feature(const_num_from_num)]
122 #![feature(const_ops)]
123 #![feature(const_option)]
124 #![feature(const_option_ext)]
125 #![feature(const_pin)]
126 #![feature(const_replace)]
127 #![feature(const_ptr_is_null)]
128 #![feature(const_ptr_offset)]
129 #![feature(const_ptr_offset_from)]
130 #![feature(const_ptr_read)]
131 #![feature(const_ptr_write)]
132 #![feature(const_raw_ptr_comparison)]
133 #![feature(const_size_of_val)]
134 #![feature(const_slice_from_raw_parts)]
135 #![feature(const_slice_ptr_len)]
136 #![feature(const_str_from_utf8_unchecked_mut)]
137 #![feature(const_swap)]
138 #![feature(const_trait_impl)]
139 #![feature(const_type_id)]
140 #![feature(const_type_name)]
141 #![feature(const_default_impls)]
142 #![feature(core_panic)]
143 #![feature(duration_consts_float)]
144 #![feature(maybe_uninit_uninit_array)]
145 #![feature(ptr_metadata)]
146 #![feature(slice_ptr_get)]
147 #![feature(str_internals)]
148 #![feature(variant_count)]
149 #![feature(const_array_from_ref)]
150 #![feature(const_slice_from_ref)]
151 //
152 // Language features:
153 #![feature(abi_unadjusted)]
154 #![feature(allow_internal_unsafe)]
155 #![feature(allow_internal_unstable)]
156 #![feature(associated_type_bounds)]
157 #![feature(auto_traits)]
158 #![feature(cfg_target_has_atomic)]
159 #![feature(cfg_target_has_atomic_equal_alignment)]
160 #![feature(const_fn_floating_point_arithmetic)]
161 #![feature(const_fn_fn_ptr_basics)]
162 #![feature(const_fn_trait_bound)]
163 #![feature(const_impl_trait)]
164 #![feature(const_mut_refs)]
165 #![feature(const_precise_live_drops)]
166 #![feature(const_refs_to_cell)]
167 #![feature(decl_macro)]
168 #![feature(derive_default_enum)]
169 #![feature(doc_cfg)]
170 #![feature(doc_notable_trait)]
171 #![feature(rustdoc_internals)]
172 #![feature(exhaustive_patterns)]
173 #![feature(doc_cfg_hide)]
174 #![feature(extern_types)]
175 #![feature(fundamental)]
176 #![feature(if_let_guard)]
177 #![feature(intra_doc_pointers)]
178 #![feature(intrinsics)]
179 #![feature(lang_items)]
180 #![feature(link_llvm_intrinsics)]
181 #![feature(min_specialization)]
182 #![feature(mixed_integer_ops)]
183 #![feature(must_not_suspend)]
184 #![feature(negative_impls)]
185 #![feature(never_type)]
186 #![feature(no_core)]
187 #![feature(no_coverage)] // rust-lang/rust#84605
188 #![feature(no_niche)] // rust-lang/rust#68303
189 #![feature(platform_intrinsics)]
190 #![feature(prelude_import)]
191 #![feature(repr_simd)]
192 #![feature(rustc_allow_const_fn_unstable)]
193 #![feature(rustc_attrs)]
194 #![feature(simd_ffi)]
195 #![feature(staged_api)]
196 #![feature(stmt_expr_attributes)]
197 #![feature(trait_alias)]
198 #![feature(transparent_unions)]
199 #![feature(try_blocks)]
200 #![feature(unboxed_closures)]
201 #![feature(unsized_fn_params)]
202 #![feature(asm_const)]
203 //
204 // Target features:
205 #![feature(aarch64_target_feature)]
206 #![feature(adx_target_feature)]
207 #![feature(arm_target_feature)]
208 #![feature(avx512_target_feature)]
209 #![feature(cmpxchg16b_target_feature)]
210 #![feature(f16c_target_feature)]
211 #![feature(hexagon_target_feature)]
212 #![feature(mips_target_feature)]
213 #![feature(powerpc_target_feature)]
214 #![feature(rtm_target_feature)]
215 #![feature(sse4a_target_feature)]
216 #![feature(tbm_target_feature)]
217 #![feature(wasm_target_feature)]
218
219 // allow using `core::` in intra-doc links
220 #[allow(unused_extern_crates)]
221 extern crate self as core;
222
223 #[prelude_import]
224 #[allow(unused)]
225 use prelude::v1::*;
226
227 #[cfg(not(test))] // See #65860
228 #[macro_use]
229 mod macros;
230
231 // We don't export this through #[macro_export] for now, to avoid breakage.
232 // See https://github.com/rust-lang/rust/issues/82913
233 #[cfg(not(test))]
234 #[unstable(feature = "assert_matches", issue = "82775")]
235 /// Unstable module containing the unstable `assert_matches` macro.
236 pub mod assert_matches {
237     #[unstable(feature = "assert_matches", issue = "82775")]
238     pub use crate::macros::{assert_matches, debug_assert_matches};
239 }
240
241 #[macro_use]
242 mod internal_macros;
243
244 #[path = "num/shells/int_macros.rs"]
245 #[macro_use]
246 mod int_macros;
247
248 #[path = "num/shells/i128.rs"]
249 pub mod i128;
250 #[path = "num/shells/i16.rs"]
251 pub mod i16;
252 #[path = "num/shells/i32.rs"]
253 pub mod i32;
254 #[path = "num/shells/i64.rs"]
255 pub mod i64;
256 #[path = "num/shells/i8.rs"]
257 pub mod i8;
258 #[path = "num/shells/isize.rs"]
259 pub mod isize;
260
261 #[path = "num/shells/u128.rs"]
262 pub mod u128;
263 #[path = "num/shells/u16.rs"]
264 pub mod u16;
265 #[path = "num/shells/u32.rs"]
266 pub mod u32;
267 #[path = "num/shells/u64.rs"]
268 pub mod u64;
269 #[path = "num/shells/u8.rs"]
270 pub mod u8;
271 #[path = "num/shells/usize.rs"]
272 pub mod usize;
273
274 #[path = "num/f32.rs"]
275 pub mod f32;
276 #[path = "num/f64.rs"]
277 pub mod f64;
278
279 #[macro_use]
280 pub mod num;
281
282 /* The libcore prelude, not as all-encompassing as the libstd prelude */
283
284 pub mod prelude;
285
286 /* Core modules for ownership management */
287
288 pub mod hint;
289 pub mod intrinsics;
290 pub mod mem;
291 pub mod ptr;
292
293 /* Core language traits */
294
295 pub mod borrow;
296 pub mod clone;
297 pub mod cmp;
298 pub mod convert;
299 pub mod default;
300 pub mod marker;
301 pub mod ops;
302
303 /* Core types and methods on primitives */
304
305 pub mod any;
306 pub mod array;
307 pub mod ascii;
308 #[unstable(feature = "async_iterator", issue = "79024")]
309 pub mod async_iter;
310 pub mod cell;
311 pub mod char;
312 pub mod ffi;
313 pub mod iter;
314 #[unstable(feature = "once_cell", issue = "74465")]
315 pub mod lazy;
316 pub mod option;
317 pub mod panic;
318 pub mod panicking;
319 pub mod pin;
320 pub mod result;
321 pub mod sync;
322
323 pub mod fmt;
324 pub mod hash;
325 pub mod slice;
326 pub mod str;
327 pub mod time;
328
329 pub mod unicode;
330
331 /* Async */
332 pub mod future;
333 pub mod task;
334
335 /* Heap memory allocator trait */
336 #[allow(missing_docs)]
337 pub mod alloc;
338
339 // note: does not need to be public
340 mod bool;
341 mod tuple;
342 mod unit;
343
344 #[stable(feature = "core_primitive", since = "1.43.0")]
345 pub mod primitive;
346
347 // Pull in the `core_arch` crate directly into libcore. The contents of
348 // `core_arch` are in a different repository: rust-lang/stdarch.
349 //
350 // `core_arch` depends on libcore, but the contents of this module are
351 // set up in such a way that directly pulling it here works such that the
352 // crate uses the this crate as its libcore.
353 #[path = "../../stdarch/crates/core_arch/src/mod.rs"]
354 #[allow(
355     missing_docs,
356     missing_debug_implementations,
357     dead_code,
358     unused_imports,
359     unsafe_op_in_unsafe_fn
360 )]
361 #[allow(rustdoc::bare_urls)]
362 // FIXME: This annotation should be moved into rust-lang/stdarch after clashing_extern_declarations is
363 // merged. It currently cannot because bootstrap fails as the lint hasn't been defined yet.
364 #[allow(clashing_extern_declarations)]
365 #[unstable(feature = "stdsimd", issue = "48556")]
366 mod core_arch;
367
368 #[doc = include_str!("../../stdarch/crates/core_arch/src/core_arch_docs.md")]
369 #[stable(feature = "simd_arch", since = "1.27.0")]
370 pub mod arch {
371     #[stable(feature = "simd_arch", since = "1.27.0")]
372     pub use crate::core_arch::arch::*;
373
374     /// Inline assembly.
375     ///
376     /// Refer to [rust by example] for a usage guide and the [reference] for
377     /// detailed information about the syntax and available options.
378     ///
379     /// [rust by example]: https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html
380     /// [reference]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html
381     #[stable(feature = "asm", since = "1.59.0")]
382     #[rustc_builtin_macro]
383     pub macro asm("assembly template", $(operands,)* $(options($(option),*))?) {
384         /* compiler built-in */
385     }
386
387     /// Module-level inline assembly.
388     ///
389     /// Refer to [rust by example] for a usage guide and the [reference] for
390     /// detailed information about the syntax and available options.
391     ///
392     /// [rust by example]: https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html
393     /// [reference]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html
394     #[stable(feature = "global_asm", since = "1.59.0")]
395     #[rustc_builtin_macro]
396     pub macro global_asm("assembly template", $(operands,)* $(options($(option),*))?) {
397         /* compiler built-in */
398     }
399 }
400
401 // Pull in the `core_simd` crate directly into libcore. The contents of
402 // `core_simd` are in a different repository: rust-lang/portable-simd.
403 //
404 // `core_simd` depends on libcore, but the contents of this module are
405 // set up in such a way that directly pulling it here works such that the
406 // crate uses this crate as its libcore.
407 #[path = "../../portable-simd/crates/core_simd/src/mod.rs"]
408 #[allow(missing_debug_implementations, dead_code, unsafe_op_in_unsafe_fn, unused_unsafe)]
409 #[allow(rustdoc::bare_urls)]
410 #[unstable(feature = "portable_simd", issue = "86656")]
411 #[cfg(not(all(miri, doctest)))] // Miri does not support all SIMD intrinsics
412 mod core_simd;
413
414 #[doc = include_str!("../../portable-simd/crates/core_simd/src/core_simd_docs.md")]
415 #[unstable(feature = "portable_simd", issue = "86656")]
416 #[cfg(not(all(miri, doctest)))] // Miri does not support all SIMD intrinsics
417 pub mod simd {
418     #[unstable(feature = "portable_simd", issue = "86656")]
419     pub use crate::core_simd::simd::*;
420 }
421
422 include!("primitive_docs.rs");