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