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