std/
lib.rs

1#![feature(rustc_private)]
2//! # The Rust Standard Library
3//!
4//! The Rust Standard Library is the foundation of portable Rust software, a
5//! set of minimal and battle-tested shared abstractions for the [broader Rust
6//! ecosystem][crates.io]. It offers core types, like [`Vec<T>`] and
7//! [`Option<T>`], library-defined [operations on language
8//! primitives](#primitives), [standard macros](#macros), [I/O] and
9//! [multithreading], among [many other things][other].
10//!
11//! `std` is available to all Rust crates by default. Therefore, the
12//! standard library can be accessed in [`use`] statements through the path
13//! `std`, as in [`use std::env`].
14//!
15//! # How to read this documentation
16//!
17//! If you already know the name of what you are looking for, the fastest way to
18//! find it is to use the <a href="#" onclick="window.searchState.focus();">search
19//! bar</a> at the top of the page.
20//!
21//! Otherwise, you may want to jump to one of these useful sections:
22//!
23//! * [`std::*` modules](#modules)
24//! * [Primitive types](#primitives)
25//! * [Standard macros](#macros)
26//! * [The Rust Prelude]
27//!
28//! If this is your first time, the documentation for the standard library is
29//! written to be casually perused. Clicking on interesting things should
30//! generally lead you to interesting places. Still, there are important bits
31//! you don't want to miss, so read on for a tour of the standard library and
32//! its documentation!
33//!
34//! Once you are familiar with the contents of the standard library you may
35//! begin to find the verbosity of the prose distracting. At this stage in your
36//! development you may want to press the
37//! "<svg style="width:0.75rem;height:0.75rem" viewBox="0 0 12 12" stroke="currentColor" fill="none"><path d="M2,2l4,4l4,-4M2,6l4,4l4,-4"/></svg>&nbsp;Summary"
38//! button near the top of the page to collapse it into a more skimmable view.
39//!
40//! While you are looking at the top of the page, also notice the
41//! "Source" link. Rust's API documentation comes with the source
42//! code and you are encouraged to read it. The standard library source is
43//! generally high quality and a peek behind the curtains is
44//! often enlightening.
45//!
46//! # What is in the standard library documentation?
47//!
48//! First of all, The Rust Standard Library is divided into a number of focused
49//! modules, [all listed further down this page](#modules). These modules are
50//! the bedrock upon which all of Rust is forged, and they have mighty names
51//! like [`std::slice`] and [`std::cmp`]. Modules' documentation typically
52//! includes an overview of the module along with examples, and are a smart
53//! place to start familiarizing yourself with the library.
54//!
55//! Second, implicit methods on [primitive types] are documented here. This can
56//! be a source of confusion for two reasons:
57//!
58//! 1. While primitives are implemented by the compiler, the standard library
59//!    implements methods directly on the primitive types (and it is the only
60//!    library that does so), which are [documented in the section on
61//!    primitives](#primitives).
62//! 2. The standard library exports many modules *with the same name as
63//!    primitive types*. These define additional items related to the primitive
64//!    type, but not the all-important methods.
65//!
66//! So for example there is a [page for the primitive type
67//! `i32`](primitive::i32) that lists all the methods that can be called on
68//! 32-bit integers (very useful), and there is a [page for the module
69//! `std::i32`] that documents the constant values [`MIN`] and [`MAX`] (rarely
70//! useful).
71//!
72//! Note the documentation for the primitives [`str`] and [`[T]`][prim@slice] (also
73//! called 'slice'). Many method calls on [`String`] and [`Vec<T>`] are actually
74//! calls to methods on [`str`] and [`[T]`][prim@slice] respectively, via [deref
75//! coercions][deref-coercions].
76//!
77//! Third, the standard library defines [The Rust Prelude], a small collection
78//! of items - mostly traits - that are imported into every module of every
79//! crate. The traits in the prelude are pervasive, making the prelude
80//! documentation a good entry point to learning about the library.
81//!
82//! And finally, the standard library exports a number of standard macros, and
83//! [lists them on this page](#macros) (technically, not all of the standard
84//! macros are defined by the standard library - some are defined by the
85//! compiler - but they are documented here the same). Like the prelude, the
86//! standard macros are imported by default into all crates.
87//!
88//! # Contributing changes to the documentation
89//!
90//! Check out the Rust contribution guidelines [here](
91//! https://rustc-dev-guide.rust-lang.org/contributing.html#writing-documentation).
92//! The source for this documentation can be found on
93//! [GitHub](https://github.com/rust-lang/rust) in the 'library/std/' directory.
94//! To contribute changes, make sure you read the guidelines first, then submit
95//! pull-requests for your suggested changes.
96//!
97//! Contributions are appreciated! If you see a part of the docs that can be
98//! improved, submit a PR, or chat with us first on [Discord][rust-discord]
99//! #docs.
100//!
101//! # A Tour of The Rust Standard Library
102//!
103//! The rest of this crate documentation is dedicated to pointing out notable
104//! features of The Rust Standard Library.
105//!
106//! ## Containers and collections
107//!
108//! The [`option`] and [`result`] modules define optional and error-handling
109//! types, [`Option<T>`] and [`Result<T, E>`]. The [`iter`] module defines
110//! Rust's iterator trait, [`Iterator`], which works with the [`for`] loop to
111//! access collections.
112//!
113//! The standard library exposes three common ways to deal with contiguous
114//! regions of memory:
115//!
116//! * [`Vec<T>`] - A heap-allocated *vector* that is resizable at runtime.
117//! * [`[T; N]`][prim@array] - An inline *array* with a fixed size at compile time.
118//! * [`[T]`][prim@slice] - A dynamically sized *slice* into any other kind of contiguous
119//!   storage, whether heap-allocated or not.
120//!
121//! Slices can only be handled through some kind of *pointer*, and as such come
122//! in many flavors such as:
123//!
124//! * `&[T]` - *shared slice*
125//! * `&mut [T]` - *mutable slice*
126//! * [`Box<[T]>`][owned slice] - *owned slice*
127//!
128//! [`str`], a UTF-8 string slice, is a primitive type, and the standard library
129//! defines many methods for it. Rust [`str`]s are typically accessed as
130//! immutable references: `&str`. Use the owned [`String`] for building and
131//! mutating strings.
132//!
133//! For converting to strings use the [`format!`] macro, and for converting from
134//! strings use the [`FromStr`] trait.
135//!
136//! Data may be shared by placing it in a reference-counted box or the [`Rc`]
137//! type, and if further contained in a [`Cell`] or [`RefCell`], may be mutated
138//! as well as shared. Likewise, in a concurrent setting it is common to pair an
139//! atomically-reference-counted box, [`Arc`], with a [`Mutex`] to get the same
140//! effect.
141//!
142//! The [`collections`] module defines maps, sets, linked lists and other
143//! typical collection types, including the common [`HashMap<K, V>`].
144//!
145//! ## Platform abstractions and I/O
146//!
147//! Besides basic data types, the standard library is largely concerned with
148//! abstracting over differences in common platforms, most notably Windows and
149//! Unix derivatives.
150//!
151//! Common types of I/O, including [files], [TCP], and [UDP], are defined in
152//! the [`io`], [`fs`], and [`net`] modules.
153//!
154//! The [`thread`] module contains Rust's threading abstractions. [`sync`]
155//! contains further primitive shared memory types, including [`atomic`], [`mpmc`] and
156//! [`mpsc`], which contains the channel types for message passing.
157//!
158//! # Use before and after `main()`
159//!
160//! Many parts of the standard library are expected to work before and after `main()`;
161//! but this is not guaranteed or ensured by tests. It is recommended that you write your own tests
162//! and run them on each platform you wish to support.
163//! This means that use of `std` before/after main, especially of features that interact with the
164//! OS or global state, is exempted from stability and portability guarantees and instead only
165//! provided on a best-effort basis. Nevertheless bug reports are appreciated.
166//!
167//! On the other hand `core` and `alloc` are most likely to work in such environments with
168//! the caveat that any hookable behavior such as panics, oom handling or allocators will also
169//! depend on the compatibility of the hooks.
170//!
171//! Some features may also behave differently outside main, e.g. stdio could become unbuffered,
172//! some panics might turn into aborts, backtraces might not get symbolicated or similar.
173//!
174//! Non-exhaustive list of known limitations:
175//!
176//! - after-main use of thread-locals, which also affects additional features:
177//!   - [`thread::current()`]
178//! - under UNIX, before main, file descriptors 0, 1, and 2 may be unchanged
179//!   (they are guaranteed to be open during main,
180//!    and are opened to /dev/null O_RDWR if they weren't open on program start)
181//!
182//!
183//! [I/O]: io
184//! [`MIN`]: i32::MIN
185//! [`MAX`]: i32::MAX
186//! [page for the module `std::i32`]: crate::i32
187//! [TCP]: net::TcpStream
188//! [The Rust Prelude]: prelude
189//! [UDP]: net::UdpSocket
190//! [`Arc`]: sync::Arc
191//! [owned slice]: boxed
192//! [`Cell`]: cell::Cell
193//! [`FromStr`]: str::FromStr
194//! [`HashMap<K, V>`]: collections::HashMap
195//! [`Mutex`]: sync::Mutex
196//! [`Option<T>`]: option::Option
197//! [`Rc`]: rc::Rc
198//! [`RefCell`]: cell::RefCell
199//! [`Result<T, E>`]: result::Result
200//! [`Vec<T>`]: vec::Vec
201//! [`atomic`]: sync::atomic
202//! [`for`]: ../book/ch03-05-control-flow.html#looping-through-a-collection-with-for
203//! [`str`]: prim@str
204//! [`mpmc`]: sync::mpmc
205//! [`mpsc`]: sync::mpsc
206//! [`std::cmp`]: cmp
207//! [`std::slice`]: mod@slice
208//! [`use std::env`]: env/index.html
209//! [`use`]: ../book/ch07-02-defining-modules-to-control-scope-and-privacy.html
210//! [crates.io]: https://crates.io
211//! [deref-coercions]: ../book/ch15-02-deref.html#implicit-deref-coercions-with-functions-and-methods
212//! [files]: fs::File
213//! [multithreading]: thread
214//! [other]: #what-is-in-the-standard-library-documentation
215//! [primitive types]: ../book/ch03-02-data-types.html
216//! [rust-discord]: https://discord.gg/rust-lang
217//! [array]: prim@array
218//! [slice]: prim@slice
219
220#![cfg_attr(not(restricted_std), stable(feature = "rust1", since = "1.0.0"))]
221#![cfg_attr(
222    restricted_std,
223    unstable(
224        feature = "restricted_std",
225        issue = "none",
226        reason = "You have attempted to use a standard library built for a platform that it doesn't \
227            know how to support. Consider building it for a known environment, disabling it with \
228            `#![no_std]` or overriding this warning by enabling this feature."
229    )
230)]
231#![rustc_preserve_ub_checks]
232#![doc(
233    html_playground_url = "https://play.rust-lang.org/",
234    issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
235    test(no_crate_inject, attr(deny(warnings))),
236    test(attr(allow(dead_code, deprecated, unused_variables, unused_mut)))
237)]
238#![doc(rust_logo)]
239#![doc(cfg_hide(
240    not(test),
241    not(any(test, bootstrap)),
242    no_global_oom_handling,
243    not(no_global_oom_handling)
244))]
245// Don't link to std. We are std.
246#![no_std]
247// Tell the compiler to link to either panic_abort or panic_unwind
248#![needs_panic_runtime]
249//
250// Lints:
251#![warn(deprecated_in_future)]
252#![warn(missing_docs)]
253#![warn(missing_debug_implementations)]
254#![allow(explicit_outlives_requirements)]
255#![allow(unused_lifetimes)]
256#![allow(internal_features)]
257#![deny(fuzzy_provenance_casts)]
258#![deny(unsafe_op_in_unsafe_fn)]
259#![allow(rustdoc::redundant_explicit_links)]
260#![warn(rustdoc::unescaped_backticks)]
261// Ensure that std can be linked against panic_abort despite compiled with `-C panic=unwind`
262#![deny(ffi_unwind_calls)]
263// std may use features in a platform-specific way
264#![allow(unused_features)]
265//
266// Features:
267#![cfg_attr(test, feature(internal_output_capture, print_internals, update_panic_count, rt))]
268#![cfg_attr(
269    all(target_vendor = "fortanix", target_env = "sgx"),
270    feature(slice_index_methods, coerce_unsized, sgx_platform)
271)]
272#![cfg_attr(any(windows, target_os = "uefi"), feature(round_char_boundary))]
273#![cfg_attr(target_family = "wasm", feature(stdarch_wasm_atomic_wait))]
274#![cfg_attr(target_arch = "wasm64", feature(simd_wasm64))]
275//
276// Language features:
277// tidy-alphabetical-start
278
279// stabilization was reverted after it hit beta
280#![feature(alloc_error_handler)]
281#![feature(allocator_internals)]
282#![feature(allow_internal_unsafe)]
283#![feature(allow_internal_unstable)]
284#![feature(asm_experimental_arch)]
285#![feature(autodiff)]
286#![feature(cfg_sanitizer_cfi)]
287#![feature(cfg_target_thread_local)]
288#![feature(cfi_encoding)]
289#![feature(char_max_len)]
290#![feature(concat_idents)]
291#![feature(decl_macro)]
292#![feature(deprecated_suggestion)]
293#![feature(doc_cfg)]
294#![feature(doc_cfg_hide)]
295#![feature(doc_masked)]
296#![feature(doc_notable_trait)]
297#![feature(dropck_eyepatch)]
298#![feature(extended_varargs_abi_support)]
299#![feature(f128)]
300#![feature(f16)]
301#![feature(ffi_const)]
302#![feature(formatting_options)]
303#![feature(if_let_guard)]
304#![feature(intra_doc_pointers)]
305#![feature(iter_advance_by)]
306#![feature(iter_next_chunk)]
307#![feature(lang_items)]
308#![feature(let_chains)]
309#![feature(link_cfg)]
310#![feature(linkage)]
311#![feature(macro_metavar_expr_concat)]
312#![feature(maybe_uninit_fill)]
313#![feature(min_specialization)]
314#![feature(must_not_suspend)]
315#![feature(needs_panic_runtime)]
316#![feature(negative_impls)]
317#![feature(never_type)]
318#![feature(optimize_attribute)]
319#![feature(prelude_import)]
320#![feature(rustc_attrs)]
321#![feature(rustdoc_internals)]
322#![feature(staged_api)]
323#![feature(stmt_expr_attributes)]
324#![feature(strict_provenance_lints)]
325#![feature(thread_local)]
326#![feature(try_blocks)]
327#![feature(try_trait_v2)]
328#![feature(type_alias_impl_trait)]
329// tidy-alphabetical-end
330//
331// Library features (core):
332// tidy-alphabetical-start
333#![feature(array_chunks)]
334#![feature(bstr)]
335#![feature(bstr_internals)]
336#![feature(char_internals)]
337#![feature(clone_to_uninit)]
338#![feature(core_intrinsics)]
339#![feature(core_io_borrowed_buf)]
340#![feature(duration_constants)]
341#![feature(error_generic_member_access)]
342#![feature(error_iter)]
343#![feature(exact_size_is_empty)]
344#![feature(exclusive_wrapper)]
345#![feature(extend_one)]
346#![feature(float_algebraic)]
347#![feature(float_gamma)]
348#![feature(float_minimum_maximum)]
349#![feature(fmt_internals)]
350#![feature(generic_atomic)]
351#![feature(hasher_prefixfree_extras)]
352#![feature(hashmap_internals)]
353#![feature(hint_must_use)]
354#![feature(ip)]
355#![feature(lazy_get)]
356#![feature(maybe_uninit_slice)]
357#![feature(maybe_uninit_write_slice)]
358#![feature(nonnull_provenance)]
359#![feature(panic_can_unwind)]
360#![feature(panic_internals)]
361#![feature(pin_coerce_unsized_trait)]
362#![feature(pointer_is_aligned_to)]
363#![feature(portable_simd)]
364#![feature(ptr_as_uninit)]
365#![feature(ptr_mask)]
366#![feature(random)]
367#![feature(slice_internals)]
368#![feature(slice_ptr_get)]
369#![feature(slice_range)]
370#![feature(std_internals)]
371#![feature(str_internals)]
372#![feature(strict_provenance_atomic_ptr)]
373#![feature(sync_unsafe_cell)]
374#![feature(temporary_niche_types)]
375#![feature(ub_checks)]
376#![feature(used_with_arg)]
377// tidy-alphabetical-end
378//
379// Library features (alloc):
380// tidy-alphabetical-start
381#![feature(alloc_layout_extra)]
382#![feature(allocator_api)]
383#![feature(get_mut_unchecked)]
384#![feature(map_try_insert)]
385#![feature(new_zeroed_alloc)]
386#![feature(slice_concat_trait)]
387#![feature(thin_box)]
388#![feature(try_reserve_kind)]
389#![feature(try_with_capacity)]
390#![feature(unique_rc_arc)]
391#![feature(vec_into_raw_parts)]
392// tidy-alphabetical-end
393//
394// Library features (unwind):
395// tidy-alphabetical-start
396#![feature(panic_unwind)]
397// tidy-alphabetical-end
398//
399// Library features (std_detect):
400// tidy-alphabetical-start
401#![feature(stdarch_internal)]
402// tidy-alphabetical-end
403//
404// Only for re-exporting:
405// tidy-alphabetical-start
406#![feature(assert_matches)]
407#![feature(async_iterator)]
408#![feature(c_variadic)]
409#![feature(cfg_accessible)]
410#![feature(cfg_eval)]
411#![feature(concat_bytes)]
412#![feature(const_format_args)]
413#![feature(custom_test_frameworks)]
414#![feature(edition_panic)]
415#![feature(format_args_nl)]
416#![feature(log_syntax)]
417#![feature(test)]
418#![feature(trace_macros)]
419// tidy-alphabetical-end
420//
421// Only used in tests/benchmarks:
422//
423// Only for const-ness:
424// tidy-alphabetical-start
425#![feature(io_const_error)]
426// tidy-alphabetical-end
427//
428#![default_lib_allocator]
429
430// Explicitly import the prelude. The compiler uses this same unstable attribute
431// to import the prelude implicitly when building crates that depend on std.
432#[prelude_import]
433#[allow(unused)]
434use prelude::rust_2021::*;
435
436// Access to Bencher, etc.
437#[cfg(test)]
438extern crate test;
439
440#[allow(unused_imports)] // macros from `alloc` are not used on all platforms
441#[macro_use]
442extern crate alloc as alloc_crate;
443
444// Many compiler tests depend on libc being pulled in by std
445// so include it here even if it's unused.
446#[doc(masked)]
447#[allow(unused_extern_crates)]
448#[cfg(not(all(windows, target_env = "msvc")))]
449extern crate libc;
450
451// We always need an unwinder currently for backtraces
452#[doc(masked)]
453#[allow(unused_extern_crates)]
454extern crate unwind;
455
456// FIXME: #94122 this extern crate definition only exist here to stop
457// miniz_oxide docs leaking into std docs. Find better way to do it.
458// Remove exclusion from tidy platform check when this removed.
459#[doc(masked)]
460#[allow(unused_extern_crates)]
461#[cfg(all(
462    not(all(windows, target_env = "msvc", not(target_vendor = "uwp"))),
463    feature = "miniz_oxide"
464))]
465extern crate miniz_oxide;
466
467// During testing, this crate is not actually the "real" std library, but rather
468// it links to the real std library, which was compiled from this same source
469// code. So any lang items std defines are conditionally excluded (or else they
470// would generate duplicate lang item errors), and any globals it defines are
471// _not_ the globals used by "real" std. So this import, defined only during
472// testing gives test-std access to real-std lang items and globals. See #2912
473#[cfg(test)]
474extern crate std as realstd;
475
476// The standard macros that are not built-in to the compiler.
477#[macro_use]
478mod macros;
479
480// The runtime entry point and a few unstable public functions used by the
481// compiler
482#[macro_use]
483pub mod rt;
484
485// The Rust prelude
486pub mod prelude;
487
488#[stable(feature = "rust1", since = "1.0.0")]
489pub use core::any;
490#[stable(feature = "core_array", since = "1.35.0")]
491pub use core::array;
492#[unstable(feature = "async_iterator", issue = "79024")]
493pub use core::async_iter;
494#[stable(feature = "rust1", since = "1.0.0")]
495pub use core::cell;
496#[stable(feature = "rust1", since = "1.0.0")]
497pub use core::char;
498#[stable(feature = "rust1", since = "1.0.0")]
499pub use core::clone;
500#[stable(feature = "rust1", since = "1.0.0")]
501pub use core::cmp;
502#[stable(feature = "rust1", since = "1.0.0")]
503pub use core::convert;
504#[stable(feature = "rust1", since = "1.0.0")]
505pub use core::default;
506#[stable(feature = "futures_api", since = "1.36.0")]
507pub use core::future;
508#[stable(feature = "core_hint", since = "1.27.0")]
509pub use core::hint;
510#[stable(feature = "rust1", since = "1.0.0")]
511#[allow(deprecated, deprecated_in_future)]
512pub use core::i8;
513#[stable(feature = "rust1", since = "1.0.0")]
514#[allow(deprecated, deprecated_in_future)]
515pub use core::i16;
516#[stable(feature = "rust1", since = "1.0.0")]
517#[allow(deprecated, deprecated_in_future)]
518pub use core::i32;
519#[stable(feature = "rust1", since = "1.0.0")]
520#[allow(deprecated, deprecated_in_future)]
521pub use core::i64;
522#[stable(feature = "i128", since = "1.26.0")]
523#[allow(deprecated, deprecated_in_future)]
524pub use core::i128;
525#[stable(feature = "rust1", since = "1.0.0")]
526pub use core::intrinsics;
527#[stable(feature = "rust1", since = "1.0.0")]
528#[allow(deprecated, deprecated_in_future)]
529pub use core::isize;
530#[stable(feature = "rust1", since = "1.0.0")]
531pub use core::iter;
532#[stable(feature = "rust1", since = "1.0.0")]
533pub use core::marker;
534#[stable(feature = "rust1", since = "1.0.0")]
535pub use core::mem;
536#[stable(feature = "rust1", since = "1.0.0")]
537pub use core::ops;
538#[stable(feature = "rust1", since = "1.0.0")]
539pub use core::option;
540#[stable(feature = "pin", since = "1.33.0")]
541pub use core::pin;
542#[stable(feature = "rust1", since = "1.0.0")]
543pub use core::ptr;
544#[unstable(feature = "new_range_api", issue = "125687")]
545pub use core::range;
546#[stable(feature = "rust1", since = "1.0.0")]
547pub use core::result;
548#[stable(feature = "rust1", since = "1.0.0")]
549#[allow(deprecated, deprecated_in_future)]
550pub use core::u8;
551#[stable(feature = "rust1", since = "1.0.0")]
552#[allow(deprecated, deprecated_in_future)]
553pub use core::u16;
554#[stable(feature = "rust1", since = "1.0.0")]
555#[allow(deprecated, deprecated_in_future)]
556pub use core::u32;
557#[stable(feature = "rust1", since = "1.0.0")]
558#[allow(deprecated, deprecated_in_future)]
559pub use core::u64;
560#[stable(feature = "i128", since = "1.26.0")]
561#[allow(deprecated, deprecated_in_future)]
562pub use core::u128;
563#[unstable(feature = "unsafe_binders", issue = "130516")]
564pub use core::unsafe_binder;
565#[stable(feature = "rust1", since = "1.0.0")]
566#[allow(deprecated, deprecated_in_future)]
567pub use core::usize;
568
569#[stable(feature = "rust1", since = "1.0.0")]
570pub use alloc_crate::borrow;
571#[stable(feature = "rust1", since = "1.0.0")]
572pub use alloc_crate::boxed;
573#[stable(feature = "rust1", since = "1.0.0")]
574pub use alloc_crate::fmt;
575#[stable(feature = "rust1", since = "1.0.0")]
576pub use alloc_crate::format;
577#[stable(feature = "rust1", since = "1.0.0")]
578pub use alloc_crate::rc;
579#[stable(feature = "rust1", since = "1.0.0")]
580pub use alloc_crate::slice;
581#[stable(feature = "rust1", since = "1.0.0")]
582pub use alloc_crate::str;
583#[stable(feature = "rust1", since = "1.0.0")]
584pub use alloc_crate::string;
585#[stable(feature = "rust1", since = "1.0.0")]
586pub use alloc_crate::vec;
587
588#[unstable(feature = "f128", issue = "116909")]
589pub mod f128;
590#[unstable(feature = "f16", issue = "116909")]
591pub mod f16;
592pub mod f32;
593pub mod f64;
594
595#[macro_use]
596pub mod thread;
597pub mod ascii;
598pub mod backtrace;
599#[unstable(feature = "bstr", issue = "134915")]
600pub mod bstr;
601pub mod collections;
602pub mod env;
603pub mod error;
604pub mod ffi;
605pub mod fs;
606pub mod hash;
607pub mod io;
608pub mod net;
609pub mod num;
610pub mod os;
611pub mod panic;
612#[unstable(feature = "pattern_type_macro", issue = "123646")]
613pub mod pat;
614pub mod path;
615pub mod process;
616#[unstable(feature = "random", issue = "130703")]
617pub mod random;
618pub mod sync;
619pub mod time;
620
621// Pull in `std_float` crate  into std. The contents of
622// `std_float` are in a different repository: rust-lang/portable-simd.
623#[path = "../../portable-simd/crates/std_float/src/lib.rs"]
624#[allow(missing_debug_implementations, dead_code, unsafe_op_in_unsafe_fn)]
625#[allow(rustdoc::bare_urls)]
626#[unstable(feature = "portable_simd", issue = "86656")]
627mod std_float;
628
629#[unstable(feature = "portable_simd", issue = "86656")]
630pub mod simd {
631    #![doc = include_str!("../../portable-simd/crates/core_simd/src/core_simd_docs.md")]
632
633    #[doc(inline)]
634    pub use core::simd::*;
635
636    #[doc(inline)]
637    pub use crate::std_float::StdFloat;
638}
639#[unstable(feature = "autodiff", issue = "124509")]
640/// This module provides support for automatic differentiation.
641pub mod autodiff {
642    /// This macro handles automatic differentiation.
643    pub use core::autodiff::autodiff;
644}
645#[stable(feature = "futures_api", since = "1.36.0")]
646pub mod task {
647    //! Types and Traits for working with asynchronous tasks.
648
649    #[doc(inline)]
650    #[stable(feature = "wake_trait", since = "1.51.0")]
651    pub use alloc::task::*;
652    #[doc(inline)]
653    #[stable(feature = "futures_api", since = "1.36.0")]
654    pub use core::task::*;
655}
656
657#[doc = include_str!("../../stdarch/crates/core_arch/src/core_arch_docs.md")]
658#[stable(feature = "simd_arch", since = "1.27.0")]
659pub mod arch {
660    #[stable(feature = "simd_arch", since = "1.27.0")]
661    // The `no_inline`-attribute is required to make the documentation of all
662    // targets available.
663    // See https://github.com/rust-lang/rust/pull/57808#issuecomment-457390549 for
664    // more information.
665    #[doc(no_inline)] // Note (#82861): required for correct documentation
666    pub use core::arch::*;
667
668    #[stable(feature = "simd_aarch64", since = "1.60.0")]
669    pub use std_detect::is_aarch64_feature_detected;
670    #[unstable(feature = "stdarch_arm_feature_detection", issue = "111190")]
671    pub use std_detect::is_arm_feature_detected;
672    #[unstable(feature = "is_loongarch_feature_detected", issue = "117425")]
673    pub use std_detect::is_loongarch_feature_detected;
674    #[unstable(feature = "is_riscv_feature_detected", issue = "111192")]
675    pub use std_detect::is_riscv_feature_detected;
676    #[unstable(feature = "stdarch_s390x_feature_detection", issue = "135413")]
677    pub use std_detect::is_s390x_feature_detected;
678    #[stable(feature = "simd_x86", since = "1.27.0")]
679    pub use std_detect::is_x86_feature_detected;
680    #[unstable(feature = "stdarch_mips_feature_detection", issue = "111188")]
681    pub use std_detect::{is_mips_feature_detected, is_mips64_feature_detected};
682    #[unstable(feature = "stdarch_powerpc_feature_detection", issue = "111191")]
683    pub use std_detect::{is_powerpc_feature_detected, is_powerpc64_feature_detected};
684}
685
686// This was stabilized in the crate root so we have to keep it there.
687#[stable(feature = "simd_x86", since = "1.27.0")]
688pub use std_detect::is_x86_feature_detected;
689
690// Platform-abstraction modules
691mod sys;
692mod sys_common;
693
694pub mod alloc;
695
696// Private support modules
697mod panicking;
698
699#[path = "../../backtrace/src/lib.rs"]
700#[allow(dead_code, unused_attributes, fuzzy_provenance_casts, unsafe_op_in_unsafe_fn)]
701mod backtrace_rs;
702
703#[unstable(feature = "cfg_match", issue = "115585")]
704pub use core::cfg_match;
705#[unstable(
706    feature = "concat_bytes",
707    issue = "87555",
708    reason = "`concat_bytes` is not stable enough for use and is subject to change"
709)]
710pub use core::concat_bytes;
711#[stable(feature = "matches_macro", since = "1.42.0")]
712#[allow(deprecated, deprecated_in_future)]
713pub use core::matches;
714#[stable(feature = "core_primitive", since = "1.43.0")]
715pub use core::primitive;
716#[stable(feature = "todo_macro", since = "1.40.0")]
717#[allow(deprecated, deprecated_in_future)]
718pub use core::todo;
719// Re-export built-in macros defined through core.
720#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
721#[allow(deprecated)]
722#[cfg_attr(bootstrap, allow(deprecated_in_future))]
723pub use core::{
724    assert, assert_matches, cfg, column, compile_error, concat, concat_idents, const_format_args,
725    env, file, format_args, format_args_nl, include, include_bytes, include_str, line, log_syntax,
726    module_path, option_env, stringify, trace_macros,
727};
728// Re-export macros defined in core.
729#[stable(feature = "rust1", since = "1.0.0")]
730#[allow(deprecated, deprecated_in_future)]
731pub use core::{
732    assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, r#try, unimplemented,
733    unreachable, write, writeln,
734};
735
736// Include a number of private modules that exist solely to provide
737// the rustdoc documentation for primitive types. Using `include!`
738// because rustdoc only looks for these modules at the crate level.
739include!("../../core/src/primitive_docs.rs");
740
741// Include a number of private modules that exist solely to provide
742// the rustdoc documentation for the existing keywords. Using `include!`
743// because rustdoc only looks for these modules at the crate level.
744include!("keyword_docs.rs");
745
746// This is required to avoid an unstable error when `restricted-std` is not
747// enabled. The use of #![feature(restricted_std)] in rustc-std-workspace-std
748// is unconditional, so the unstable feature needs to be defined somewhere.
749#[unstable(feature = "restricted_std", issue = "none")]
750mod __restricted_std_workaround {}
751
752mod sealed {
753    /// This trait being unreachable from outside the crate
754    /// prevents outside implementations of our extension traits.
755    /// This allows adding more trait methods in the future.
756    #[unstable(feature = "sealed", issue = "none")]
757    pub trait Sealed {}
758}
759
760#[cfg(test)]
761#[allow(dead_code)] // Not used in all configurations.
762pub(crate) mod test_helpers;