rust/library/core/src/lib.rs

287 lines
8.4 KiB
Rust
Raw Normal View History

2014-05-22 11:44:54 -05:00
//! # The Rust Core Library
2014-05-12 23:22:35 -05:00
//!
//! The Rust Core Library is the dependency-free[^free] foundation of [The
2014-05-19 23:53:00 -05:00
//! Rust Standard Library](../std/index.html). It is the portable glue
//! between the language and its libraries, defining the intrinsic and
//! primitive building blocks of all Rust code. It links to no
2014-05-20 13:39:40 -05:00
//! upstream libraries, no system libraries, and no libc.
2014-05-19 23:53:00 -05:00
//!
//! [^free]: Strictly speaking, there are some symbols which are needed but
2015-11-18 04:35:29 -06:00
//! they aren't always necessary.
//!
2014-05-19 23:53:00 -05:00
//! The core library is *minimal*: it isn't even aware of heap allocation,
//! nor does it provide concurrency or I/O. These things require
2014-05-20 13:39:40 -05:00
//! platform integration, and this library is platform-agnostic.
2014-05-19 23:53:00 -05:00
//!
//! # How to use the core library
//!
//! Please note that all of these details are currently not considered stable.
//!
2014-05-20 12:40:14 -05:00
// FIXME: Fill me in with more detail when the interface settles
2014-05-19 23:53:00 -05:00
//! This library is built on the assumption of a few existing symbols:
2014-05-12 23:22:35 -05:00
//!
//! * `memcpy`, `memcmp`, `memset` - These are core memory routines which are
//! often generated by LLVM. Additionally, this library can make explicit
2014-05-19 10:51:16 -05:00
//! calls to these functions. Their signatures are the same as found in C.
//! These functions are often provided by the system libc, but can also be
//! provided by the [compiler-builtins crate](https://crates.io/crates/compiler_builtins).
2014-05-12 23:22:35 -05:00
//!
2017-06-27 19:41:24 -05:00
//! * `rust_begin_panic` - This function takes four arguments, a
//! `fmt::Arguments`, a `&'static str`, and two `u32`'s. These four arguments
//! dictate the panic message, the file at which panic was invoked, and the
2017-06-26 21:26:52 -05:00
//! line and column inside the file. It is up to consumers of this core
//! library to define this panic function; it is only required to never
2018-04-30 03:57:11 -05:00
//! return. This requires a `lang` attribute named `panic_impl`.
//!
//! * `rust_eh_personality` - is used by the failure mechanisms of the
//! compiler. This is often mapped to GCC's personality function, but crates
//! which do not trigger a panic can be assured that this function is never
//! called. The `lang` attribute is called `eh_personality`.
// Since libcore defines many fundamental lang items, all tests live in a
// separate crate, libcoretest, to avoid bizarre issues.
2018-05-05 14:29:19 -05:00
//
// Here we explicitly #[cfg]-out this whole crate when testing. If we don't do
// this, both the generated test artifact and the linked libtest (which
// transitively includes libcore) will both define the same set of lang items,
// and this will cause the E0152 "found duplicate lang item" error. See
2018-05-05 14:29:19 -05:00
// discussion in #50466 for details.
//
// This cfg won't affect doc tests.
#![cfg(not(test))]
std: Stabilize APIs for the 1.6 release This commit is the standard API stabilization commit for the 1.6 release cycle. The list of issues and APIs below have all been through their cycle-long FCP and the libs team decisions are listed below Stabilized APIs * `Read::read_exact` * `ErrorKind::UnexpectedEof` (renamed from `UnexpectedEOF`) * libcore -- this was a bit of a nuanced stabilization, the crate itself is now marked as `#[stable]` and the methods appearing via traits for primitives like `char` and `str` are now also marked as stable. Note that the extension traits themeselves are marked as unstable as they're imported via the prelude. The `try!` macro was also moved from the standard library into libcore to have the same interface. Otherwise the functions all have copied stability from the standard library now. * The `#![no_std]` attribute * `fs::DirBuilder` * `fs::DirBuilder::new` * `fs::DirBuilder::recursive` * `fs::DirBuilder::create` * `os::unix::fs::DirBuilderExt` * `os::unix::fs::DirBuilderExt::mode` * `vec::Drain` * `vec::Vec::drain` * `string::Drain` * `string::String::drain` * `vec_deque::Drain` * `vec_deque::VecDeque::drain` * `collections::hash_map::Drain` * `collections::hash_map::HashMap::drain` * `collections::hash_set::Drain` * `collections::hash_set::HashSet::drain` * `collections::binary_heap::Drain` * `collections::binary_heap::BinaryHeap::drain` * `Vec::extend_from_slice` (renamed from `push_all`) * `Mutex::get_mut` * `Mutex::into_inner` * `RwLock::get_mut` * `RwLock::into_inner` * `Iterator::min_by_key` (renamed from `min_by`) * `Iterator::max_by_key` (renamed from `max_by`) Deprecated APIs * `ErrorKind::UnexpectedEOF` (renamed to `UnexpectedEof`) * `OsString::from_bytes` * `OsStr::to_cstring` * `OsStr::to_bytes` * `fs::walk_dir` and `fs::WalkDir` * `path::Components::peek` * `slice::bytes::MutableByteVector` * `slice::bytes::copy_memory` * `Vec::push_all` (renamed to `extend_from_slice`) * `Duration::span` * `IpAddr` * `SocketAddr::ip` * `Read::tee` * `io::Tee` * `Write::broadcast` * `io::Broadcast` * `Iterator::min_by` (renamed to `min_by_key`) * `Iterator::max_by` (renamed to `max_by_key`) * `net::lookup_addr` New APIs (still unstable) * `<[T]>::sort_by_key` (added to mirror `min_by_key`) Closes #27585 Closes #27704 Closes #27707 Closes #27710 Closes #27711 Closes #27727 Closes #27740 Closes #27744 Closes #27799 Closes #27801 cc #27801 (doesn't close as `Chars` is still unstable) Closes #28968
2015-12-02 19:31:49 -06:00
#![stable(feature = "core", since = "1.6.0")]
2019-12-22 16:42:04 -06:00
#![doc(
html_root_url = "https://doc.rust-lang.org/nightly/",
html_playground_url = "https://play.rust-lang.org/",
issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
test(no_crate_inject, attr(deny(warnings))),
test(attr(allow(dead_code, deprecated, unused_variables, unused_mut)))
)]
#![no_core]
#![warn(deprecated_in_future)]
#![warn(missing_docs)]
#![warn(missing_debug_implementations)]
2019-04-14 21:23:21 -05:00
#![allow(explicit_outlives_requirements)]
2019-08-11 11:55:14 -05:00
#![allow(incomplete_features)]
#![feature(allow_internal_unstable)]
2018-05-22 19:07:51 -05:00
#![feature(arbitrary_self_types)]
#![feature(asm)]
2017-03-17 09:05:44 -05:00
#![feature(cfg_target_has_atomic)]
#![feature(const_alloc_layout)]
2020-03-08 08:24:32 -05:00
#![feature(const_discriminant)]
2020-02-04 13:46:03 -06:00
#![feature(const_checked_int_methods)]
#![feature(const_euclidean_int_methods)]
#![feature(const_float_classify)]
#![feature(const_float_bits_conv)]
2020-02-04 13:46:03 -06:00
#![feature(const_overflowing_int_methods)]
#![feature(const_int_unchecked_arith)]
2020-02-08 18:32:30 -06:00
#![feature(const_int_pow)]
#![feature(constctlz)]
2019-12-26 19:59:55 -06:00
#![feature(const_panic)]
#![feature(const_fn_union)]
#![feature(const_generics)]
2020-07-01 08:07:23 -05:00
#![feature(const_option)]
#![feature(const_precise_live_drops)]
#![feature(const_ptr_offset)]
2019-12-18 11:00:59 -06:00
#![feature(const_ptr_offset_from)]
2020-07-16 08:12:59 -05:00
#![feature(const_raw_ptr_comparison)]
#![feature(const_slice_from_raw_parts)]
#![feature(const_slice_ptr_len)]
2020-07-29 16:56:58 -05:00
#![feature(const_size_of_val)]
#![feature(const_align_of_val)]
2019-12-18 11:00:59 -06:00
#![feature(const_type_name)]
#![feature(const_likely)]
2020-07-17 14:57:13 -05:00
#![feature(const_unreachable_unchecked)]
#![feature(custom_inner_attributes)]
#![feature(decl_macro)]
#![feature(doc_cfg)]
2020-08-26 03:17:31 -05:00
#![feature(doc_spotlight)]
#![feature(duration_consts_2)]
2020-08-30 12:31:34 -05:00
#![feature(duration_saturating_ops)]
2018-04-02 04:26:16 -05:00
#![feature(extern_types)]
#![feature(fundamental)]
#![feature(intrinsics)]
#![feature(lang_items)]
#![feature(link_llvm_intrinsics)]
#![feature(llvm_asm)]
2020-04-22 14:45:35 -05:00
#![feature(negative_impls)]
#![feature(never_type)]
#![feature(nll)]
#![feature(exhaustive_patterns)]
#![feature(no_core)]
#![feature(optin_builtin_traits)]
#![feature(or_patterns)]
2017-03-17 09:05:44 -05:00
#![feature(prelude_import)]
#![feature(repr_simd, platform_intrinsics)]
#![feature(rustc_attrs)]
#![feature(simd_ffi)]
2020-08-17 13:34:44 -05:00
#![feature(min_specialization)]
#![feature(staged_api)]
#![feature(std_internals)]
#![feature(stmt_expr_attributes)]
2019-07-04 09:05:50 -05:00
#![feature(transparent_unions)]
#![feature(unboxed_closures)]
#![feature(unsized_locals)]
2017-03-17 09:05:44 -05:00
#![feature(untagged_unions)]
#![feature(unwind_attributes)]
2020-07-16 08:12:59 -05:00
#![feature(variant_count)]
2020-08-20 06:35:00 -05:00
#![cfg_attr(bootstrap, feature(doc_alias))]
2018-05-10 13:02:19 -05:00
#![feature(tbm_target_feature)]
#![feature(sse4a_target_feature)]
#![feature(arm_target_feature)]
#![feature(powerpc_target_feature)]
#![feature(mips_target_feature)]
#![feature(aarch64_target_feature)]
#![feature(wasm_target_feature)]
#![feature(avx512_target_feature)]
2019-01-19 17:25:06 -06:00
#![feature(cmpxchg16b_target_feature)]
2019-07-15 06:57:34 -05:00
#![feature(rtm_target_feature)]
#![feature(f16c_target_feature)]
#![feature(hexagon_target_feature)]
2020-07-16 08:12:59 -05:00
#![feature(const_fn_transmute)]
2019-01-07 09:20:25 -06:00
#![feature(abi_unadjusted)]
2019-01-19 17:25:06 -06:00
#![feature(adx_target_feature)]
2019-02-11 08:29:25 -06:00
#![feature(external_doc)]
#![feature(associated_type_bounds)]
#![feature(const_caller_location)]
#![feature(slice_ptr_get)]
2020-03-15 13:43:25 -05:00
#![feature(no_niche)] // rust-lang/rust#68303
2020-06-21 17:54:46 -05:00
#![feature(unsafe_block_in_unsafe_fn)]
#![deny(unsafe_op_in_unsafe_fn)]
2016-08-22 05:02:28 -05:00
#[prelude_import]
#[allow(unused)]
use prelude::v1::*;
#[cfg(not(test))] // See #65860
#[macro_use]
mod macros;
2016-10-23 08:27:49 -05:00
#[macro_use]
mod internal_macros;
#[path = "num/shells/int_macros.rs"]
#[macro_use]
mod int_macros;
#[path = "num/shells/i128.rs"]
2019-12-22 16:42:04 -06:00
pub mod i128;
#[path = "num/shells/i16.rs"]
2019-12-22 16:42:04 -06:00
pub mod i16;
#[path = "num/shells/i32.rs"]
2019-12-22 16:42:04 -06:00
pub mod i32;
#[path = "num/shells/i64.rs"]
2019-12-22 16:42:04 -06:00
pub mod i64;
#[path = "num/shells/i8.rs"]
2019-12-22 16:42:04 -06:00
pub mod i8;
#[path = "num/shells/isize.rs"]
2019-12-22 16:42:04 -06:00
pub mod isize;
#[path = "num/shells/u128.rs"]
2019-12-22 16:42:04 -06:00
pub mod u128;
#[path = "num/shells/u16.rs"]
2019-12-22 16:42:04 -06:00
pub mod u16;
#[path = "num/shells/u32.rs"]
2019-12-22 16:42:04 -06:00
pub mod u32;
#[path = "num/shells/u64.rs"]
2019-12-22 16:42:04 -06:00
pub mod u64;
#[path = "num/shells/u8.rs"]
2019-12-22 16:42:04 -06:00
pub mod u8;
#[path = "num/shells/usize.rs"]
2019-12-22 16:42:04 -06:00
pub mod usize;
2019-12-22 16:42:04 -06:00
#[path = "num/f32.rs"]
pub mod f32;
#[path = "num/f64.rs"]
pub mod f64;
#[macro_use]
pub mod num;
/* The libcore prelude, not as all-encompassing as the libstd prelude */
pub mod prelude;
2014-04-30 22:04:56 -05:00
/* Core modules for ownership management */
2019-12-22 16:42:04 -06:00
pub mod hint;
2014-04-30 22:04:56 -05:00
pub mod intrinsics;
2014-04-30 22:13:05 -05:00
pub mod mem;
2014-04-30 22:17:50 -05:00
pub mod ptr;
2014-04-30 22:22:55 -05:00
/* Core language traits */
2019-12-22 16:42:04 -06:00
pub mod borrow;
pub mod clone;
pub mod cmp;
2019-12-22 16:42:04 -06:00
pub mod convert;
2014-04-30 22:46:51 -05:00
pub mod default;
2019-12-22 16:42:04 -06:00
pub mod marker;
pub mod ops;
2014-04-30 22:33:08 -05:00
/* Core types and methods on primitives */
2014-04-30 22:36:58 -05:00
pub mod any;
pub mod array;
pub mod ascii;
2014-05-01 13:19:56 -05:00
pub mod cell;
pub mod char;
2019-12-22 16:42:04 -06:00
pub mod ffi;
pub mod iter;
2020-07-17 19:09:47 -05:00
#[unstable(feature = "once_cell", issue = "74465")]
pub mod lazy;
2019-12-22 16:42:04 -06:00
pub mod option;
pub mod panic;
pub mod panicking;
pub mod pin;
2014-04-30 22:38:31 -05:00
pub mod raw;
pub mod result;
2019-12-22 16:42:04 -06:00
pub mod sync;
2019-12-22 16:42:04 -06:00
pub mod fmt;
pub mod hash;
2019-12-22 16:42:04 -06:00
pub mod slice;
pub mod str;
2017-12-11 12:42:01 -06:00
pub mod time;
pub mod unicode;
/* Async */
pub mod future;
pub mod task;
/* Heap memory allocator trait */
#[allow(missing_docs)]
pub mod alloc;
// note: does not need to be public
mod bool;
mod tuple;
mod unit;
2020-02-24 01:59:39 -06:00
#[stable(feature = "core_primitive", since = "1.43.0")]
pub mod primitive;
2019-01-21 11:42:04 -06:00
// Pull in the `core_arch` crate directly into libcore. The contents of
2019-07-15 06:53:44 -05:00
// `core_arch` are in a different repository: rust-lang/stdarch.
2019-01-21 11:42:04 -06:00
//
// `core_arch` depends on libcore, but the contents of this module are
// set up in such a way that directly pulling it here works such that the
// crate uses the this crate as its libcore.
2020-06-11 21:31:49 -05:00
#[path = "../../stdarch/crates/core_arch/src/mod.rs"]
#[allow(
missing_docs,
missing_debug_implementations,
dead_code,
unused_imports,
unsafe_op_in_unsafe_fn
)]
// FIXME: This annotation should be moved into rust-lang/stdarch after clashing_extern_declarations is
// merged. It currently cannot because bootstrap fails as the lint hasn't been defined yet.
2020-07-16 08:12:59 -05:00
#[allow(clashing_extern_declarations)]
#[unstable(feature = "stdsimd", issue = "48556")]
2019-01-21 11:42:04 -06:00
mod core_arch;
#[stable(feature = "simd_arch", since = "1.27.0")]
2019-01-21 11:42:04 -06:00
pub use core_arch::arch;