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`, `memmove`, `memset`, `memcmp`, `bcmp`, `strlen` - These are core memory routines |
24 | //! which are generated by Rust codegen backends. Additionally, this library can make explicit |
25 | //! calls to `strlen`. Their signatures are the same as found in C, but there are extra |
26 | //! assumptions about their semantics: For `memcpy`, `memmove`, `memset`, `memcmp`, and `bcmp`, if |
27 | //! the `n` parameter is 0, the function is assumed to not be UB, even if the pointers are NULL or |
28 | //! dangling. (Note that making extra assumptions about these functions is common among compilers: |
29 | //! [clang](https://reviews.llvm.org/D86993) and [GCC](https://gcc.gnu.org/onlinedocs/gcc/Standards.html#C-Language) do the same.) |
30 | //! These functions are often provided by the system libc, but can also be provided by the |
31 | //! [compiler-builtins crate](https://crates.io/crates/compiler_builtins). |
32 | //! Note that the library does not guarantee that it will always make these assumptions, so Rust |
33 | //! user code directly calling the C functions should follow the C specification! The advice for |
34 | //! Rust user code is to call the functions provided by this library instead (such as |
35 | //! `ptr::copy`). |
36 | //! |
37 | //! * `rust_begin_panic` - This function takes four arguments, a |
38 | //! `fmt::Arguments`, a `&'static str`, and two `u32`'s. These four arguments |
39 | //! dictate the panic message, the file at which panic was invoked, and the |
40 | //! line and column inside the file. It is up to consumers of this core |
41 | //! library to define this panic function; it is only required to never |
42 | //! return. This requires a `lang` attribute named `panic_impl`. |
43 | //! |
44 | //! * `rust_eh_personality` - is used by the failure mechanisms of the |
45 | //! compiler. This is often mapped to GCC's personality function, but crates |
46 | //! which do not trigger a panic can be assured that this function is never |
47 | //! called. The `lang` attribute is called `eh_personality`. |
48 | |
49 | // Since core defines many fundamental lang items, all tests live in a |
50 | // separate crate, libcoretest (library/core/tests), to avoid bizarre issues. |
51 | // |
52 | // Here we explicitly #[cfg]-out this whole crate when testing. If we don't do |
53 | // this, both the generated test artifact and the linked libtest (which |
54 | // transitively includes core) will both define the same set of lang items, |
55 | // and this will cause the E0152 "found duplicate lang item" error. See |
56 | // discussion in #50466 for details. |
57 | // |
58 | // This cfg won't affect doc tests. |
59 | #![cfg (not(test))] |
60 | // To run core tests without x.py without ending up with two copies of core, Miri needs to be |
61 | // able to "empty" this crate. See <https://github.com/rust-lang/miri-test-libstd/issues/4>. |
62 | // rustc itself never sets the feature, so this line has no effect there. |
63 | #![cfg (any(not(feature = "miri-test-libstd" ), test, doctest))] |
64 | #![stable (feature = "core" , since = "1.6.0" )] |
65 | #![doc ( |
66 | html_playground_url = "https://play.rust-lang.org/" , |
67 | issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/" , |
68 | test(no_crate_inject, attr(deny(warnings))), |
69 | test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))) |
70 | )] |
71 | #![doc (rust_logo)] |
72 | #![doc (cfg_hide( |
73 | not(test), |
74 | any(not(feature = "miri-test-libstd" ), test, doctest), |
75 | no_fp_fmt_parse, |
76 | target_pointer_width = "16" , |
77 | target_pointer_width = "32" , |
78 | target_pointer_width = "64" , |
79 | target_has_atomic = "8" , |
80 | target_has_atomic = "16" , |
81 | target_has_atomic = "32" , |
82 | target_has_atomic = "64" , |
83 | target_has_atomic = "ptr" , |
84 | target_has_atomic_equal_alignment = "8" , |
85 | target_has_atomic_equal_alignment = "16" , |
86 | target_has_atomic_equal_alignment = "32" , |
87 | target_has_atomic_equal_alignment = "64" , |
88 | target_has_atomic_equal_alignment = "ptr" , |
89 | target_has_atomic_load_store = "8" , |
90 | target_has_atomic_load_store = "16" , |
91 | target_has_atomic_load_store = "32" , |
92 | target_has_atomic_load_store = "64" , |
93 | target_has_atomic_load_store = "ptr" , |
94 | ))] |
95 | #![no_core ] |
96 | #![rustc_coherence_is_core ] |
97 | // |
98 | // Lints: |
99 | #![deny (rust_2021_incompatible_or_patterns)] |
100 | #![deny (unsafe_op_in_unsafe_fn)] |
101 | #![deny (fuzzy_provenance_casts)] |
102 | #![warn (deprecated_in_future)] |
103 | #![warn (missing_debug_implementations)] |
104 | #![warn (missing_docs)] |
105 | #![allow (explicit_outlives_requirements)] |
106 | #![allow (incomplete_features)] |
107 | #![warn (multiple_supertrait_upcastable)] |
108 | #![allow (internal_features)] |
109 | // Do not check link redundancy on bootstraping phase |
110 | #![allow (rustdoc::redundant_explicit_links)] |
111 | // |
112 | // Library features: |
113 | // tidy-alphabetical-start |
114 | #![cfg_attr (not(bootstrap), feature(offset_of_nested))] |
115 | #![feature (char_indices_offset)] |
116 | #![feature (const_align_of_val)] |
117 | #![feature (const_align_of_val_raw)] |
118 | #![feature (const_align_offset)] |
119 | #![feature (const_alloc_layout)] |
120 | #![feature (const_arguments_as_str)] |
121 | #![feature (const_array_from_ref)] |
122 | #![feature (const_array_into_iter_constructors)] |
123 | #![feature (const_bigint_helper_methods)] |
124 | #![feature (const_black_box)] |
125 | #![feature (const_caller_location)] |
126 | #![feature (const_cell_into_inner)] |
127 | #![feature (const_char_from_u32_unchecked)] |
128 | #![feature (const_eval_select)] |
129 | #![feature (const_exact_div)] |
130 | #![feature (const_float_bits_conv)] |
131 | #![feature (const_float_classify)] |
132 | #![feature (const_fmt_arguments_new)] |
133 | #![feature (const_hash)] |
134 | #![feature (const_heap)] |
135 | #![feature (const_hint_assert_unchecked)] |
136 | #![feature (const_index_range_slice_index)] |
137 | #![feature (const_int_unchecked_arith)] |
138 | #![feature (const_intrinsic_forget)] |
139 | #![feature (const_ipv4)] |
140 | #![feature (const_ipv6)] |
141 | #![feature (const_likely)] |
142 | #![feature (const_maybe_uninit_as_mut_ptr)] |
143 | #![feature (const_maybe_uninit_assume_init)] |
144 | #![feature (const_maybe_uninit_uninit_array)] |
145 | #![feature (const_nonnull_new)] |
146 | #![feature (const_num_midpoint)] |
147 | #![feature (const_option)] |
148 | #![feature (const_option_ext)] |
149 | #![feature (const_pin)] |
150 | #![feature (const_pointer_is_aligned)] |
151 | #![feature (const_ptr_as_ref)] |
152 | #![feature (const_ptr_is_null)] |
153 | #![feature (const_ptr_sub_ptr)] |
154 | #![feature (const_ptr_write)] |
155 | #![feature (const_raw_ptr_comparison)] |
156 | #![feature (const_replace)] |
157 | #![feature (const_size_of_val)] |
158 | #![feature (const_size_of_val_raw)] |
159 | #![feature (const_slice_from_raw_parts_mut)] |
160 | #![feature (const_slice_from_ref)] |
161 | #![feature (const_slice_index)] |
162 | #![feature (const_slice_ptr_len)] |
163 | #![feature (const_slice_split_at_mut)] |
164 | #![feature (const_str_from_utf8_unchecked_mut)] |
165 | #![feature (const_strict_overflow_ops)] |
166 | #![feature (const_swap)] |
167 | #![feature (const_try)] |
168 | #![feature (const_type_id)] |
169 | #![feature (const_type_name)] |
170 | #![feature (const_unicode_case_lookup)] |
171 | #![feature (const_unsafecell_get_mut)] |
172 | #![feature (const_waker)] |
173 | #![feature (coverage_attribute)] |
174 | #![feature (duration_consts_float)] |
175 | #![feature (internal_impls_macro)] |
176 | #![feature (ip)] |
177 | #![feature (ip_bits)] |
178 | #![feature (is_ascii_octdigit)] |
179 | #![feature (isqrt)] |
180 | #![feature (maybe_uninit_uninit_array)] |
181 | #![feature (non_null_convenience)] |
182 | #![feature (offset_of_enum)] |
183 | #![feature (panic_internals)] |
184 | #![feature (ptr_alignment_type)] |
185 | #![feature (ptr_metadata)] |
186 | #![feature (set_ptr_value)] |
187 | #![feature (slice_ptr_get)] |
188 | #![feature (slice_split_at_unchecked)] |
189 | #![feature (split_at_checked)] |
190 | #![feature (str_internals)] |
191 | #![feature (str_split_inclusive_remainder)] |
192 | #![feature (str_split_remainder)] |
193 | #![feature (strict_provenance)] |
194 | #![feature (unchecked_math)] |
195 | #![feature (unchecked_shifts)] |
196 | #![feature (utf16_extra)] |
197 | #![feature (utf16_extra_const)] |
198 | #![feature (variant_count)] |
199 | // tidy-alphabetical-end |
200 | // |
201 | // Language features: |
202 | // tidy-alphabetical-start |
203 | #![feature (abi_unadjusted)] |
204 | #![feature (adt_const_params)] |
205 | #![feature (allow_internal_unsafe)] |
206 | #![feature (allow_internal_unstable)] |
207 | #![feature (asm_const)] |
208 | #![feature (associated_type_bounds)] |
209 | #![feature (auto_traits)] |
210 | #![feature (c_unwind)] |
211 | #![feature (cfg_sanitize)] |
212 | #![feature (cfg_target_has_atomic)] |
213 | #![feature (cfg_target_has_atomic_equal_alignment)] |
214 | #![feature (const_closures)] |
215 | #![feature (const_fn_floating_point_arithmetic)] |
216 | #![feature (const_for)] |
217 | #![feature (const_mut_refs)] |
218 | #![feature (const_precise_live_drops)] |
219 | #![feature (const_refs_to_cell)] |
220 | #![feature (const_trait_impl)] |
221 | #![feature (decl_macro)] |
222 | #![feature (deprecated_suggestion)] |
223 | #![feature (diagnostic_namespace)] |
224 | #![feature (doc_cfg)] |
225 | #![feature (doc_cfg_hide)] |
226 | #![feature (doc_notable_trait)] |
227 | #![feature (effects)] |
228 | #![feature (exhaustive_patterns)] |
229 | #![feature (extern_types)] |
230 | #![feature (fundamental)] |
231 | #![feature (generic_arg_infer)] |
232 | #![feature (if_let_guard)] |
233 | #![feature (inline_const)] |
234 | #![feature (intra_doc_pointers)] |
235 | #![feature (intrinsics)] |
236 | #![feature (lang_items)] |
237 | #![feature (let_chains)] |
238 | #![feature (link_llvm_intrinsics)] |
239 | #![feature (macro_metavar_expr)] |
240 | #![feature (min_specialization)] |
241 | #![feature (multiple_supertrait_upcastable)] |
242 | #![feature (must_not_suspend)] |
243 | #![feature (negative_impls)] |
244 | #![feature (never_type)] |
245 | #![feature (no_core)] |
246 | #![feature (no_sanitize)] |
247 | #![feature (platform_intrinsics)] |
248 | #![feature (prelude_import)] |
249 | #![feature (repr_simd)] |
250 | #![feature (rustc_allow_const_fn_unstable)] |
251 | #![feature (rustc_attrs)] |
252 | #![feature (rustdoc_internals)] |
253 | #![feature (simd_ffi)] |
254 | #![feature (staged_api)] |
255 | #![feature (stmt_expr_attributes)] |
256 | #![feature (target_feature_11)] |
257 | #![feature (trait_alias)] |
258 | #![feature (transparent_unions)] |
259 | #![feature (try_blocks)] |
260 | #![feature (unboxed_closures)] |
261 | #![feature (unsized_fn_params)] |
262 | #![feature (with_negative_coherence)] |
263 | // tidy-alphabetical-end |
264 | // |
265 | // Target features: |
266 | // tidy-alphabetical-start |
267 | #![feature (arm_target_feature)] |
268 | #![feature (avx512_target_feature)] |
269 | #![feature (hexagon_target_feature)] |
270 | #![feature (mips_target_feature)] |
271 | #![feature (powerpc_target_feature)] |
272 | #![feature (riscv_target_feature)] |
273 | #![feature (rtm_target_feature)] |
274 | #![feature (sse4a_target_feature)] |
275 | #![feature (tbm_target_feature)] |
276 | #![feature (wasm_target_feature)] |
277 | // tidy-alphabetical-end |
278 | |
279 | // allow using `core::` in intra-doc links |
280 | #[allow (unused_extern_crates)] |
281 | extern crate self as core; |
282 | |
283 | #[prelude_import ] |
284 | #[allow (unused)] |
285 | use prelude::v1::*; |
286 | |
287 | #[cfg (not(test))] // See #65860 |
288 | #[macro_use ] |
289 | mod macros; |
290 | |
291 | // We don't export this through #[macro_export] for now, to avoid breakage. |
292 | // See https://github.com/rust-lang/rust/issues/82913 |
293 | #[cfg (not(test))] |
294 | #[unstable (feature = "assert_matches" , issue = "82775" )] |
295 | /// Unstable module containing the unstable `assert_matches` macro. |
296 | pub mod assert_matches { |
297 | #[unstable (feature = "assert_matches" , issue = "82775" )] |
298 | pub use crate::macros::{assert_matches, debug_assert_matches}; |
299 | } |
300 | |
301 | #[unstable (feature = "cfg_match" , issue = "115585" )] |
302 | pub use crate::macros::cfg_match; |
303 | |
304 | #[macro_use ] |
305 | mod internal_macros; |
306 | |
307 | #[path = "num/shells/int_macros.rs" ] |
308 | #[macro_use ] |
309 | mod int_macros; |
310 | |
311 | #[path = "num/shells/i128.rs" ] |
312 | pub mod i128; |
313 | #[path = "num/shells/i16.rs" ] |
314 | pub mod i16; |
315 | #[path = "num/shells/i32.rs" ] |
316 | pub mod i32; |
317 | #[path = "num/shells/i64.rs" ] |
318 | pub mod i64; |
319 | #[path = "num/shells/i8.rs" ] |
320 | pub mod i8; |
321 | #[path = "num/shells/isize.rs" ] |
322 | pub mod isize; |
323 | |
324 | #[path = "num/shells/u128.rs" ] |
325 | pub mod u128; |
326 | #[path = "num/shells/u16.rs" ] |
327 | pub mod u16; |
328 | #[path = "num/shells/u32.rs" ] |
329 | pub mod u32; |
330 | #[path = "num/shells/u64.rs" ] |
331 | pub mod u64; |
332 | #[path = "num/shells/u8.rs" ] |
333 | pub mod u8; |
334 | #[path = "num/shells/usize.rs" ] |
335 | pub mod usize; |
336 | |
337 | #[path = "num/f32.rs" ] |
338 | pub mod f32; |
339 | #[path = "num/f64.rs" ] |
340 | pub mod f64; |
341 | |
342 | #[macro_use ] |
343 | pub mod num; |
344 | |
345 | /* The core prelude, not as all-encompassing as the std prelude */ |
346 | |
347 | pub mod prelude; |
348 | |
349 | /* Core modules for ownership management */ |
350 | |
351 | pub mod hint; |
352 | pub mod intrinsics; |
353 | pub mod mem; |
354 | pub mod ptr; |
355 | |
356 | /* Core language traits */ |
357 | |
358 | pub mod borrow; |
359 | pub mod clone; |
360 | pub mod cmp; |
361 | pub mod convert; |
362 | pub mod default; |
363 | pub mod error; |
364 | pub mod marker; |
365 | pub mod ops; |
366 | |
367 | /* Core types and methods on primitives */ |
368 | |
369 | pub mod any; |
370 | pub mod array; |
371 | pub mod ascii; |
372 | pub mod asserting; |
373 | #[unstable (feature = "async_iterator" , issue = "79024" )] |
374 | pub mod async_iter; |
375 | pub mod cell; |
376 | pub mod char; |
377 | pub mod ffi; |
378 | #[unstable (feature = "core_io_borrowed_buf" , issue = "117693" )] |
379 | pub mod io; |
380 | pub mod iter; |
381 | pub mod net; |
382 | pub mod option; |
383 | pub mod panic; |
384 | pub mod panicking; |
385 | pub mod pin; |
386 | pub mod result; |
387 | pub mod sync; |
388 | |
389 | pub mod fmt; |
390 | pub mod hash; |
391 | pub mod slice; |
392 | pub mod str; |
393 | pub mod time; |
394 | |
395 | pub mod unicode; |
396 | |
397 | /* Async */ |
398 | pub mod future; |
399 | pub mod task; |
400 | |
401 | /* Heap memory allocator trait */ |
402 | #[allow (missing_docs)] |
403 | pub mod alloc; |
404 | |
405 | // note: does not need to be public |
406 | mod bool; |
407 | mod escape; |
408 | mod tuple; |
409 | mod unit; |
410 | |
411 | #[stable (feature = "core_primitive" , since = "1.43.0" )] |
412 | pub mod primitive; |
413 | |
414 | // Pull in the `core_arch` crate directly into core. The contents of |
415 | // `core_arch` are in a different repository: rust-lang/stdarch. |
416 | // |
417 | // `core_arch` depends on core, but the contents of this module are |
418 | // set up in such a way that directly pulling it here works such that the |
419 | // crate uses the this crate as its core. |
420 | #[path = "../../stdarch/crates/core_arch/src/mod.rs" ] |
421 | #[allow ( |
422 | missing_docs, |
423 | missing_debug_implementations, |
424 | dead_code, |
425 | unused_imports, |
426 | unsafe_op_in_unsafe_fn, |
427 | ambiguous_glob_reexports, |
428 | deprecated_in_future |
429 | )] |
430 | #[allow (rustdoc::bare_urls)] |
431 | // FIXME: This annotation should be moved into rust-lang/stdarch after clashing_extern_declarations is |
432 | // merged. It currently cannot because bootstrap fails as the lint hasn't been defined yet. |
433 | #[allow (clashing_extern_declarations)] |
434 | #[unstable (feature = "stdsimd" , issue = "48556" )] |
435 | mod core_arch; |
436 | |
437 | #[stable (feature = "simd_arch" , since = "1.27.0" )] |
438 | pub mod arch; |
439 | |
440 | // Pull in the `core_simd` crate directly into core. The contents of |
441 | // `core_simd` are in a different repository: rust-lang/portable-simd. |
442 | // |
443 | // `core_simd` depends on core, but the contents of this module are |
444 | // set up in such a way that directly pulling it here works such that the |
445 | // crate uses this crate as its core. |
446 | #[path = "../../portable-simd/crates/core_simd/src/mod.rs" ] |
447 | #[allow (missing_debug_implementations, dead_code, unsafe_op_in_unsafe_fn)] |
448 | #[allow (rustdoc::bare_urls)] |
449 | #[unstable (feature = "portable_simd" , issue = "86656" )] |
450 | mod core_simd; |
451 | |
452 | #[unstable (feature = "portable_simd" , issue = "86656" )] |
453 | pub mod simd { |
454 | #![doc = include_str!("../../portable-simd/crates/core_simd/src/core_simd_docs.md" )] |
455 | |
456 | #[unstable (feature = "portable_simd" , issue = "86656" )] |
457 | pub use crate::core_simd::simd::*; |
458 | } |
459 | |
460 | include!("primitive_docs.rs" ); |
461 | |