]> git.lizzy.rs Git - rust.git/blob - src/libcore/lib.rs
06727d8292d367e422f89d87542a82413d80cc0e
[rust.git] / src / libcore / lib.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! # The Rust Core Library
12 //!
13 //! The Rust Core Library is the dependency-free[^free] foundation of [The
14 //! Rust Standard Library](../std/index.html). It is the portable glue
15 //! between the language and its libraries, defining the intrinsic and
16 //! primitive building blocks of all Rust code. It links to no
17 //! upstream libraries, no system libraries, and no libc.
18 //!
19 //! [^free]: Strictly speaking, there are some symbols which are needed but
20 //!          they aren't always necessary.
21 //!
22 //! The core library is *minimal*: it isn't even aware of heap allocation,
23 //! nor does it provide concurrency or I/O. These things require
24 //! platform integration, and this library is platform-agnostic.
25 //!
26 //! # How to use the core library
27 //!
28 //! Please note that all of these details are currently not considered stable.
29 //!
30 // FIXME: Fill me in with more detail when the interface settles
31 //! This library is built on the assumption of a few existing symbols:
32 //!
33 //! * `memcpy`, `memcmp`, `memset` - These are core memory routines which are
34 //!   often generated by LLVM. Additionally, this library can make explicit
35 //!   calls to these functions. Their signatures are the same as found in C.
36 //!   These functions are often provided by the system libc, but can also be
37 //!   provided by the [rlibc crate](https://crates.io/crates/rlibc).
38 //!
39 //! * `rust_begin_panic` - This function takes four arguments, a
40 //!   `fmt::Arguments`, a `&'static str`, and two `u32`'s. These four arguments
41 //!   dictate the panic message, the file at which panic was invoked, and the
42 //!   line and column inside the file. It is up to consumers of this core
43 //!   library to define this panic function; it is only required to never
44 //!   return. This requires a `lang` attribute named `panic_impl`.
45 //!
46 //! * `rust_eh_personality` - is used by the failure mechanisms of the
47 //!    compiler. This is often mapped to GCC's personality function, but crates
48 //!    which do not trigger a panic can be assured that this function is never
49 //!    called. The `lang` attribute is called `eh_personality`.
50
51 // Since libcore defines many fundamental lang items, all tests live in a
52 // separate crate, libcoretest, to avoid bizarre issues.
53 //
54 // Here we explicitly #[cfg]-out this whole crate when testing. If we don't do
55 // this, both the generated test artifact and the linked libtest (which
56 // transitively includes libcore) will both define the same set of lang items,
57 // and this will cause the E0152 "duplicate lang item found" error. See
58 // discussion in #50466 for details.
59 //
60 // This cfg won't affect doc tests.
61 #![cfg(not(test))]
62
63 #![stable(feature = "core", since = "1.6.0")]
64 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
65        html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
66        html_root_url = "https://doc.rust-lang.org/nightly/",
67        html_playground_url = "https://play.rust-lang.org/",
68        issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
69        test(no_crate_inject, attr(deny(warnings))),
70        test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))))]
71
72 #![no_core]
73 #![deny(missing_docs)]
74 #![deny(missing_debug_implementations)]
75
76 #![feature(allow_internal_unstable)]
77 #![feature(arbitrary_self_types)]
78 #![feature(asm)]
79 #![feature(associated_type_defaults)]
80 #![feature(cfg_target_has_atomic)]
81 #![feature(concat_idents)]
82 #![feature(const_fn)]
83 #![feature(const_int_ops)]
84 #![feature(const_fn_union)]
85 #![feature(const_manually_drop_new)]
86 #![feature(custom_attribute)]
87 #![feature(doc_cfg)]
88 #![feature(doc_spotlight)]
89 #![feature(extern_types)]
90 #![feature(fundamental)]
91 #![cfg_attr(stage0, feature(impl_header_lifetime_elision))]
92 #![feature(intrinsics)]
93 #![feature(lang_items)]
94 #![feature(link_llvm_intrinsics)]
95 #![feature(never_type)]
96 #![feature(nll)]
97 #![feature(exhaustive_patterns)]
98 #![feature(macro_at_most_once_rep)]
99 #![feature(no_core)]
100 #![feature(on_unimplemented)]
101 #![feature(optin_builtin_traits)]
102 #![feature(prelude_import)]
103 #![feature(repr_simd, platform_intrinsics)]
104 #![feature(rustc_attrs)]
105 #![feature(rustc_const_unstable)]
106 #![feature(simd_ffi)]
107 #![feature(specialization)]
108 #![feature(staged_api)]
109 #![feature(stmt_expr_attributes)]
110 #![feature(unboxed_closures)]
111 #![feature(untagged_unions)]
112 #![feature(unwind_attributes)]
113 #![feature(doc_alias)]
114 #![feature(mmx_target_feature)]
115 #![feature(tbm_target_feature)]
116 #![feature(sse4a_target_feature)]
117 #![feature(arm_target_feature)]
118 #![feature(powerpc_target_feature)]
119 #![feature(mips_target_feature)]
120 #![feature(aarch64_target_feature)]
121 #![feature(wasm_target_feature)]
122 #![feature(const_slice_len)]
123 #![feature(const_str_as_bytes)]
124 #![feature(const_str_len)]
125 #![feature(const_let)]
126 #![feature(const_int_rotate)]
127 #![feature(const_int_wrapping)]
128 #![feature(const_int_sign)]
129 #![feature(const_int_conversion)]
130 #![feature(const_transmute)]
131 #![feature(reverse_bits)]
132 #![feature(non_exhaustive)]
133
134 #[prelude_import]
135 #[allow(unused)]
136 use prelude::v1::*;
137
138 #[macro_use]
139 mod macros;
140
141 #[macro_use]
142 mod internal_macros;
143
144 #[path = "num/int_macros.rs"]
145 #[macro_use]
146 mod int_macros;
147
148 #[path = "num/uint_macros.rs"]
149 #[macro_use]
150 mod uint_macros;
151
152 #[path = "num/isize.rs"] pub mod isize;
153 #[path = "num/i8.rs"]    pub mod i8;
154 #[path = "num/i16.rs"]   pub mod i16;
155 #[path = "num/i32.rs"]   pub mod i32;
156 #[path = "num/i64.rs"]   pub mod i64;
157 #[path = "num/i128.rs"]  pub mod i128;
158
159 #[path = "num/usize.rs"] pub mod usize;
160 #[path = "num/u8.rs"]    pub mod u8;
161 #[path = "num/u16.rs"]   pub mod u16;
162 #[path = "num/u32.rs"]   pub mod u32;
163 #[path = "num/u64.rs"]   pub mod u64;
164 #[path = "num/u128.rs"]  pub mod u128;
165
166 #[path = "num/f32.rs"]   pub mod f32;
167 #[path = "num/f64.rs"]   pub mod f64;
168
169 #[macro_use]
170 pub mod num;
171
172 /* The libcore prelude, not as all-encompassing as the libstd prelude */
173
174 pub mod prelude;
175
176 /* Core modules for ownership management */
177
178 pub mod intrinsics;
179 pub mod mem;
180 pub mod ptr;
181 pub mod hint;
182
183 /* Core language traits */
184
185 pub mod marker;
186 pub mod ops;
187 pub mod cmp;
188 pub mod clone;
189 pub mod default;
190 pub mod convert;
191 pub mod borrow;
192
193 /* Core types and methods on primitives */
194
195 pub mod any;
196 pub mod array;
197 pub mod ascii;
198 pub mod sync;
199 pub mod cell;
200 pub mod char;
201 pub mod panic;
202 pub mod panicking;
203 pub mod pin;
204 pub mod iter;
205 pub mod option;
206 pub mod raw;
207 pub mod result;
208 pub mod ffi;
209
210 pub mod slice;
211 pub mod str;
212 pub mod hash;
213 pub mod fmt;
214 pub mod time;
215
216 pub mod unicode;
217
218 /* Async */
219 pub mod future;
220 pub mod task;
221
222 /* Heap memory allocator trait */
223 #[allow(missing_docs)]
224 pub mod alloc;
225
226 // note: does not need to be public
227 mod iter_private;
228 mod nonzero;
229 mod tuple;
230 mod unit;
231
232 // Pull in the the `coresimd` crate directly into libcore. This is where all the
233 // architecture-specific (and vendor-specific) intrinsics are defined. AKA
234 // things like SIMD and such. Note that the actual source for all this lies in a
235 // different repository, rust-lang-nursery/stdsimd. That's why the setup here is
236 // a bit wonky.
237 #[allow(unused_macros)]
238 macro_rules! test_v16 { ($item:item) => {}; }
239 #[allow(unused_macros)]
240 macro_rules! test_v32 { ($item:item) => {}; }
241 #[allow(unused_macros)]
242 macro_rules! test_v64 { ($item:item) => {}; }
243 #[allow(unused_macros)]
244 macro_rules! test_v128 { ($item:item) => {}; }
245 #[allow(unused_macros)]
246 macro_rules! test_v256 { ($item:item) => {}; }
247 #[allow(unused_macros)]
248 macro_rules! test_v512 { ($item:item) => {}; }
249 #[allow(unused_macros)]
250 macro_rules! vector_impl { ($([$f:ident, $($args:tt)*]),*) => { $($f!($($args)*);)* } }
251 #[path = "../stdsimd/coresimd/mod.rs"]
252 #[allow(missing_docs, missing_debug_implementations, dead_code, unused_imports)]
253 #[unstable(feature = "stdsimd", issue = "48556")]
254 #[cfg(not(stage0))] // allow changes to how stdsimd works in stage0
255 mod coresimd;
256
257 #[stable(feature = "simd_arch", since = "1.27.0")]
258 #[cfg(not(stage0))]
259 pub use coresimd::arch;