]> git.lizzy.rs Git - rust.git/blob - library/core/src/lib.rs
Merge commit 'f4850f7292efa33759b4f7f9b7621268979e9914' into clippyup
[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`, `strlen` - 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 #![rustc_coherence_is_core]
88 //
89 // Lints:
90 #![deny(rust_2021_incompatible_or_patterns)]
91 #![deny(unsafe_op_in_unsafe_fn)]
92 #![deny(fuzzy_provenance_casts)]
93 #![warn(deprecated_in_future)]
94 #![warn(missing_debug_implementations)]
95 #![warn(missing_docs)]
96 #![allow(explicit_outlives_requirements)]
97 #![allow(incomplete_features)]
98 //
99 // Library features:
100 #![feature(const_align_offset)]
101 #![feature(const_align_of_val)]
102 #![feature(const_arguments_as_str)]
103 #![feature(const_array_into_iter_constructors)]
104 #![feature(const_bigint_helper_methods)]
105 #![feature(const_black_box)]
106 #![feature(const_caller_location)]
107 #![feature(const_cell_into_inner)]
108 #![feature(const_char_from_u32_unchecked)]
109 #![feature(const_clone)]
110 #![feature(const_cmp)]
111 #![feature(const_discriminant)]
112 #![feature(const_eval_select)]
113 #![feature(const_exact_div)]
114 #![feature(const_float_bits_conv)]
115 #![feature(const_float_classify)]
116 #![feature(const_fmt_arguments_new)]
117 #![feature(const_hash)]
118 #![feature(const_heap)]
119 #![feature(const_convert)]
120 #![feature(const_index_range_slice_index)]
121 #![feature(const_inherent_unchecked_arith)]
122 #![feature(const_int_unchecked_arith)]
123 #![feature(const_intrinsic_forget)]
124 #![feature(const_likely)]
125 #![feature(const_maybe_uninit_uninit_array)]
126 #![feature(const_maybe_uninit_as_mut_ptr)]
127 #![feature(const_maybe_uninit_assume_init)]
128 #![feature(const_nonnull_new)]
129 #![feature(const_num_from_num)]
130 #![feature(const_ops)]
131 #![feature(const_option)]
132 #![feature(const_option_ext)]
133 #![feature(const_pin)]
134 #![feature(const_pointer_is_aligned)]
135 #![feature(const_ptr_sub_ptr)]
136 #![feature(const_replace)]
137 #![feature(const_result_drop)]
138 #![feature(const_ptr_as_ref)]
139 #![feature(const_ptr_is_null)]
140 #![feature(const_ptr_read)]
141 #![feature(const_ptr_write)]
142 #![feature(const_raw_ptr_comparison)]
143 #![feature(const_size_of_val)]
144 #![feature(const_slice_from_raw_parts_mut)]
145 #![feature(const_slice_ptr_len)]
146 #![feature(const_slice_split_at_mut)]
147 #![feature(const_str_from_utf8_unchecked_mut)]
148 #![feature(const_swap)]
149 #![feature(const_trait_impl)]
150 #![feature(const_try)]
151 #![feature(const_type_id)]
152 #![feature(const_type_name)]
153 #![feature(const_default_impls)]
154 #![feature(const_unicode_case_lookup)]
155 #![feature(const_unsafecell_get_mut)]
156 #![feature(const_waker)]
157 #![feature(core_panic)]
158 #![feature(duration_consts_float)]
159 #![feature(maybe_uninit_uninit_array)]
160 #![feature(ptr_alignment_type)]
161 #![feature(ptr_metadata)]
162 #![feature(set_ptr_value)]
163 #![feature(slice_ptr_get)]
164 #![feature(slice_split_at_unchecked)]
165 #![feature(str_internals)]
166 #![feature(strict_provenance)]
167 #![feature(utf16_extra)]
168 #![feature(utf16_extra_const)]
169 #![feature(variant_count)]
170 #![feature(const_array_from_ref)]
171 #![feature(const_slice_from_ref)]
172 #![feature(const_slice_index)]
173 #![feature(const_is_char_boundary)]
174 #![feature(const_cstr_methods)]
175 #![feature(is_ascii_octdigit)]
176 //
177 // Language features:
178 #![feature(abi_unadjusted)]
179 #![feature(adt_const_params)]
180 #![feature(allow_internal_unsafe)]
181 #![feature(allow_internal_unstable)]
182 #![feature(associated_type_bounds)]
183 #![feature(auto_traits)]
184 #![feature(c_unwind)]
185 #![feature(cfg_sanitize)]
186 #![feature(cfg_target_has_atomic)]
187 #![feature(cfg_target_has_atomic_equal_alignment)]
188 #![feature(const_fn_floating_point_arithmetic)]
189 #![feature(const_mut_refs)]
190 #![feature(const_precise_live_drops)]
191 #![feature(const_refs_to_cell)]
192 #![feature(decl_macro)]
193 #![feature(deprecated_suggestion)]
194 #![cfg_attr(not(bootstrap), feature(derive_const))]
195 #![feature(doc_cfg)]
196 #![feature(doc_notable_trait)]
197 #![feature(rustdoc_internals)]
198 #![feature(exhaustive_patterns)]
199 #![feature(doc_cfg_hide)]
200 #![feature(extern_types)]
201 #![feature(fundamental)]
202 #![feature(if_let_guard)]
203 #![feature(inline_const)]
204 #![feature(intra_doc_pointers)]
205 #![feature(intrinsics)]
206 #![feature(lang_items)]
207 #![feature(link_llvm_intrinsics)]
208 #![feature(macro_metavar_expr)]
209 #![feature(min_specialization)]
210 #![feature(must_not_suspend)]
211 #![feature(negative_impls)]
212 #![feature(never_type)]
213 #![feature(no_core)]
214 #![feature(no_coverage)] // rust-lang/rust#84605
215 #![feature(platform_intrinsics)]
216 #![feature(prelude_import)]
217 #![feature(repr_simd)]
218 #![feature(rustc_allow_const_fn_unstable)]
219 #![feature(rustc_attrs)]
220 #![feature(simd_ffi)]
221 #![feature(staged_api)]
222 #![feature(stmt_expr_attributes)]
223 #![feature(target_feature_11)]
224 #![feature(trait_alias)]
225 #![feature(transparent_unions)]
226 #![feature(try_blocks)]
227 #![feature(unboxed_closures)]
228 #![feature(unsized_fn_params)]
229 #![feature(asm_const)]
230 #![feature(const_transmute_copy)]
231 //
232 // Target features:
233 #![feature(arm_target_feature)]
234 #![feature(avx512_target_feature)]
235 #![feature(cmpxchg16b_target_feature)]
236 #![feature(f16c_target_feature)]
237 #![feature(hexagon_target_feature)]
238 #![feature(mips_target_feature)]
239 #![feature(powerpc_target_feature)]
240 #![feature(riscv_target_feature)]
241 #![feature(rtm_target_feature)]
242 #![feature(sse4a_target_feature)]
243 #![feature(tbm_target_feature)]
244 #![feature(wasm_target_feature)]
245
246 // allow using `core::` in intra-doc links
247 #[allow(unused_extern_crates)]
248 extern crate self as core;
249
250 #[prelude_import]
251 #[allow(unused)]
252 use prelude::v1::*;
253
254 #[cfg(not(test))] // See #65860
255 #[macro_use]
256 mod macros;
257
258 // We don't export this through #[macro_export] for now, to avoid breakage.
259 // See https://github.com/rust-lang/rust/issues/82913
260 #[cfg(not(test))]
261 #[unstable(feature = "assert_matches", issue = "82775")]
262 /// Unstable module containing the unstable `assert_matches` macro.
263 pub mod assert_matches {
264     #[unstable(feature = "assert_matches", issue = "82775")]
265     pub use crate::macros::{assert_matches, debug_assert_matches};
266 }
267
268 #[macro_use]
269 mod internal_macros;
270
271 #[path = "num/shells/int_macros.rs"]
272 #[macro_use]
273 mod int_macros;
274
275 #[path = "num/shells/i128.rs"]
276 pub mod i128;
277 #[path = "num/shells/i16.rs"]
278 pub mod i16;
279 #[path = "num/shells/i32.rs"]
280 pub mod i32;
281 #[path = "num/shells/i64.rs"]
282 pub mod i64;
283 #[path = "num/shells/i8.rs"]
284 pub mod i8;
285 #[path = "num/shells/isize.rs"]
286 pub mod isize;
287
288 #[path = "num/shells/u128.rs"]
289 pub mod u128;
290 #[path = "num/shells/u16.rs"]
291 pub mod u16;
292 #[path = "num/shells/u32.rs"]
293 pub mod u32;
294 #[path = "num/shells/u64.rs"]
295 pub mod u64;
296 #[path = "num/shells/u8.rs"]
297 pub mod u8;
298 #[path = "num/shells/usize.rs"]
299 pub mod usize;
300
301 #[path = "num/f32.rs"]
302 pub mod f32;
303 #[path = "num/f64.rs"]
304 pub mod f64;
305
306 #[macro_use]
307 pub mod num;
308
309 /* The libcore prelude, not as all-encompassing as the libstd prelude */
310
311 pub mod prelude;
312
313 /* Core modules for ownership management */
314
315 pub mod hint;
316 pub mod intrinsics;
317 pub mod mem;
318 pub mod ptr;
319
320 /* Core language traits */
321
322 pub mod borrow;
323 pub mod clone;
324 pub mod cmp;
325 pub mod convert;
326 pub mod default;
327 pub mod error;
328 pub mod marker;
329 pub mod ops;
330
331 /* Core types and methods on primitives */
332
333 pub mod any;
334 pub mod array;
335 pub mod ascii;
336 pub mod asserting;
337 #[unstable(feature = "async_iterator", issue = "79024")]
338 pub mod async_iter;
339 pub mod cell;
340 pub mod char;
341 pub mod ffi;
342 pub mod iter;
343 pub mod option;
344 pub mod panic;
345 pub mod panicking;
346 pub mod pin;
347 pub mod result;
348 pub mod sync;
349
350 pub mod fmt;
351 pub mod hash;
352 pub mod slice;
353 pub mod str;
354 pub mod time;
355
356 pub mod unicode;
357
358 /* Async */
359 pub mod future;
360 pub mod task;
361
362 /* Heap memory allocator trait */
363 #[allow(missing_docs)]
364 pub mod alloc;
365
366 // note: does not need to be public
367 mod bool;
368 mod tuple;
369 mod unit;
370
371 mod const_closure;
372
373 #[stable(feature = "core_primitive", since = "1.43.0")]
374 pub mod primitive;
375
376 // Pull in the `core_arch` crate directly into libcore. The contents of
377 // `core_arch` are in a different repository: rust-lang/stdarch.
378 //
379 // `core_arch` depends on libcore, but the contents of this module are
380 // set up in such a way that directly pulling it here works such that the
381 // crate uses the this crate as its libcore.
382 #[path = "../../stdarch/crates/core_arch/src/mod.rs"]
383 #[allow(
384     missing_docs,
385     missing_debug_implementations,
386     dead_code,
387     unused_imports,
388     unsafe_op_in_unsafe_fn
389 )]
390 #[allow(rustdoc::bare_urls)]
391 // FIXME: This annotation should be moved into rust-lang/stdarch after clashing_extern_declarations is
392 // merged. It currently cannot because bootstrap fails as the lint hasn't been defined yet.
393 #[allow(clashing_extern_declarations)]
394 #[unstable(feature = "stdsimd", issue = "48556")]
395 mod core_arch;
396
397 #[stable(feature = "simd_arch", since = "1.27.0")]
398 pub mod arch;
399
400 // Pull in the `core_simd` crate directly into libcore. The contents of
401 // `core_simd` are in a different repository: rust-lang/portable-simd.
402 //
403 // `core_simd` depends on libcore, but the contents of this module are
404 // set up in such a way that directly pulling it here works such that the
405 // crate uses this crate as its libcore.
406 #[path = "../../portable-simd/crates/core_simd/src/mod.rs"]
407 #[allow(missing_debug_implementations, dead_code, unsafe_op_in_unsafe_fn, unused_unsafe)]
408 #[allow(rustdoc::bare_urls)]
409 #[unstable(feature = "portable_simd", issue = "86656")]
410 mod core_simd;
411
412 #[doc = include_str!("../../portable-simd/crates/core_simd/src/core_simd_docs.md")]
413 #[unstable(feature = "portable_simd", issue = "86656")]
414 pub mod simd {
415     #[unstable(feature = "portable_simd", issue = "86656")]
416     pub use crate::core_simd::simd::*;
417 }
418
419 include!("primitive_docs.rs");