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