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