Skip to main content

std/
lib.rs

1//! # The Rust Standard Library
2//!
3//! The Rust Standard Library is the foundation of portable Rust software, a
4//! set of minimal and battle-tested shared abstractions for the [broader Rust
5//! ecosystem][crates.io]. It offers core types, like [`Vec<T>`] and
6//! [`Option<T>`], library-defined [operations on language
7//! primitives](#primitives), [standard macros](#macros), [I/O] and
8//! [multithreading], among [many other things][other].
9//!
10//! `std` is available to all Rust crates by default. Therefore, the
11//! standard library can be accessed in [`use`] statements through the path
12//! `std`, as in [`use std::env`].
13//!
14//! # How to read this documentation
15//!
16//! If you already know the name of what you are looking for, the fastest way to
17//! find it is to use the <a href="#" onclick="window.searchState.focus();">search
18//! button</a> at the top of the page.
19//!
20//! Otherwise, you may want to jump to one of these useful sections:
21//!
22//! * [`std::*` modules](#modules)
23//! * [Primitive types](#primitives)
24//! * [Standard macros](#macros)
25//! * [The Rust Prelude]
26//!
27//! If this is your first time, the documentation for the standard library is
28//! written to be casually perused. Clicking on interesting things should
29//! generally lead you to interesting places. Still, there are important bits
30//! you don't want to miss, so read on for a tour of the standard library and
31//! its documentation!
32//!
33//! Once you are familiar with the contents of the standard library you may
34//! begin to find the verbosity of the prose distracting. At this stage in your
35//! development you may want to press the
36//! "<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"
37//! button near the top of the page to collapse it into a more skimmable view.
38//!
39//! While you are looking at the top of the page, also notice the
40//! "Source" link. Rust's API documentation comes with the source
41//! code and you are encouraged to read it. The standard library source is
42//! generally high quality and a peek behind the curtains is
43//! often enlightening.
44//!
45//! # What is in the standard library documentation?
46//!
47//! First of all, The Rust Standard Library is divided into a number of focused
48//! modules, [all listed further down this page](#modules). These modules are
49//! the bedrock upon which all of Rust is forged, and they have mighty names
50//! like [`std::slice`] and [`std::cmp`]. Modules' documentation typically
51//! includes an overview of the module along with examples, and are a smart
52//! place to start familiarizing yourself with the library.
53//!
54//! Second, implicit methods on [primitive types] are documented here. This can
55//! be a source of confusion for two reasons:
56//!
57//! 1. While primitives are implemented by the compiler, the standard library
58//!    implements methods directly on the primitive types (and it is the only
59//!    library that does so), which are [documented in the section on
60//!    primitives](#primitives).
61//! 2. The standard library exports many modules *with the same name as
62//!    primitive types*. These define additional items related to the primitive
63//!    type, but not the all-important methods.
64//!
65//! So for example there is a [page for the primitive type
66//! `char`](primitive::char) that lists all the methods that can be called on
67//! characters (very useful), and there is a [page for the module
68//! `std::char`](crate::char) that documents iterator and error types created by these methods
69//! (rarely useful).
70//!
71//! Note the documentation for the primitives [`str`] and [`[T]`][prim@slice] (also
72//! called 'slice'). Many method calls on [`String`] and [`Vec<T>`] are actually
73//! calls to methods on [`str`] and [`[T]`][prim@slice] respectively, via [deref
74//! coercions][deref-coercions].
75//!
76//! Third, the standard library defines [The Rust Prelude], a small collection
77//! of items - mostly traits - that are imported into every module of every
78//! crate. The traits in the prelude are pervasive, making the prelude
79//! documentation a good entry point to learning about the library.
80//!
81//! And finally, the standard library exports a number of standard macros, and
82//! [lists them on this page](#macros) (technically, not all of the standard
83//! macros are defined by the standard library - some are defined by the
84//! compiler - but they are documented here the same). Like the prelude, the
85//! standard macros are imported by default into all crates.
86//!
87//! # Contributing changes to the documentation
88//!
89//! Check out the Rust contribution guidelines [here](
90//! https://rustc-dev-guide.rust-lang.org/contributing.html#writing-documentation).
91//! The source for this documentation can be found on
92//! [GitHub](https://github.com/rust-lang/rust) in the 'library/std/' directory.
93//! To contribute changes, make sure you read the guidelines first, then submit
94//! pull-requests for your suggested changes.
95//!
96//! Contributions are appreciated! If you see a part of the docs that can be
97//! improved, submit a PR, or chat with us first on [Zulip][t-libs-zulip]
98//! #t-libs.
99//!
100//! # A Tour of The Rust Standard Library
101//!
102//! The rest of this crate documentation is dedicated to pointing out notable
103//! features of The Rust Standard Library.
104//!
105//! ## Containers and collections
106//!
107//! The [`option`] and [`result`] modules define optional and error-handling
108//! types, [`Option<T>`] and [`Result<T, E>`]. The [`iter`] module defines
109//! Rust's iterator trait, [`Iterator`], which works with the [`for`] loop to
110//! access collections.
111//!
112//! The standard library exposes three common ways to deal with contiguous
113//! regions of memory:
114//!
115//! * [`Vec<T>`] - A heap-allocated *vector* that is resizable at runtime.
116//! * [`[T; N]`][prim@array] - An inline *array* with a fixed size at compile time.
117//! * [`[T]`][prim@slice] - A dynamically sized *slice* into any other kind of contiguous
118//!   storage, whether heap-allocated or not.
119//!
120//! Slices can only be handled through some kind of *pointer*, and as such come
121//! in many flavors such as:
122//!
123//! * `&[T]` - *shared slice*
124//! * `&mut [T]` - *mutable slice*
125//! * [`Box<[T]>`][owned slice] - *owned slice*
126//!
127//! [`str`], a UTF-8 string slice, is a primitive type, and the standard library
128//! defines many methods for it. Rust [`str`]s are typically accessed as
129//! immutable references: `&str`. Use the owned [`String`] for building and
130//! mutating strings.
131//!
132//! For converting to strings use the [`format!`] macro, and for converting from
133//! strings use the [`FromStr`] trait.
134//!
135//! Data may be shared by placing it in a reference-counted box or the [`Rc`]
136//! type, and if further contained in a [`Cell`] or [`RefCell`], may be mutated
137//! as well as shared. Likewise, in a concurrent setting it is common to pair an
138//! atomically-reference-counted box, [`Arc`], with a [`Mutex`] to get the same
139//! effect.
140//!
141//! The [`collections`] module defines maps, sets, linked lists and other
142//! typical collection types, including the common [`HashMap<K, V>`].
143//!
144//! ## Platform abstractions and I/O
145//!
146//! Besides basic data types, the standard library is largely concerned with
147//! abstracting over differences in common platforms, most notably Windows and
148//! Unix derivatives.
149//!
150//! Common types of I/O, including [files], [TCP], and [UDP], are defined in
151//! the [`io`], [`fs`], and [`net`] modules.
152//!
153//! The [`thread`] module contains Rust's threading abstractions. [`sync`]
154//! contains further primitive shared memory types, including [`atomic`], [`mpmc`] and
155//! [`mpsc`], which contains the channel types for message passing.
156//!
157//! # Use before and after `main()`
158//!
159//! Many parts of the standard library are expected to work before and after `main()`;
160//! but this is not guaranteed or ensured by tests. It is recommended that you write your own tests
161//! and run them on each platform you wish to support.
162//! This means that use of `std` before/after main, especially of features that interact with the
163//! OS or global state, is exempted from stability and portability guarantees and instead only
164//! provided on a best-effort basis. Nevertheless bug reports are appreciated.
165//!
166//! On the other hand `core` and `alloc` are most likely to work in such environments with
167//! the caveat that any hookable behavior such as panics, oom handling or allocators will also
168//! depend on the compatibility of the hooks.
169//!
170//! Some features may also behave differently outside main, e.g. stdio could become unbuffered,
171//! some panics might turn into aborts, backtraces might not get symbolicated or similar.
172//!
173//! Non-exhaustive list of known limitations:
174//!
175//! - after-main use of thread-locals, which also affects additional features:
176//!   - [`thread::current()`]
177//! - under UNIX, before main, file descriptors 0, 1, and 2 may be unchanged
178//!   (they are guaranteed to be open during main,
179//!    and are opened to /dev/null O_RDWR if they weren't open on program start)
180//!
181//!
182//! [I/O]: io
183//! [TCP]: net::TcpStream
184//! [The Rust Prelude]: prelude
185//! [UDP]: net::UdpSocket
186//! [`Arc`]: sync::Arc
187//! [owned slice]: boxed
188//! [`Cell`]: cell::Cell
189//! [`FromStr`]: str::FromStr
190//! [`HashMap<K, V>`]: collections::HashMap
191//! [`Mutex`]: sync::Mutex
192//! [`Option<T>`]: option::Option
193//! [`Rc`]: rc::Rc
194//! [`RefCell`]: cell::RefCell
195//! [`Result<T, E>`]: result::Result
196//! [`Vec<T>`]: vec::Vec
197//! [`atomic`]: sync::atomic
198//! [`for`]: ../book/ch03-05-control-flow.html#looping-through-a-collection-with-for
199//! [`str`]: prim@str
200//! [`mpmc`]: sync::mpmc
201//! [`mpsc`]: sync::mpsc
202//! [`std::cmp`]: cmp
203//! [`std::slice`]: mod@slice
204//! [`use std::env`]: env/index.html
205//! [`use`]: ../book/ch07-02-defining-modules-to-control-scope-and-privacy.html
206//! [crates.io]: https://crates.io
207//! [deref-coercions]: ../book/ch15-02-deref.html#implicit-deref-coercions-with-functions-and-methods
208//! [files]: fs::File
209//! [multithreading]: thread
210//! [other]: #what-is-in-the-standard-library-documentation
211//! [primitive types]: ../book/ch03-02-data-types.html
212//! [t-libs-zulip]: https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/
213//! [array]: prim@array
214//! [slice]: prim@slice
215
216#![cfg_attr(not(restricted_std), stable(feature = "rust1", since = "1.0.0"))]
217#![cfg_attr(
218    restricted_std,
219    unstable(
220        feature = "restricted_std",
221        issue = "none",
222        reason = "You have attempted to use a standard library built for a platform that it doesn't \
223            know how to support. Consider building it for a known environment, disabling it with \
224            `#![no_std]` or overriding this warning by enabling this feature."
225    )
226)]
227#![rustc_preserve_ub_checks]
228#![doc(
229    html_playground_url = "https://play.rust-lang.org/",
230    issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
231    test(no_crate_inject, attr(deny(warnings))),
232    test(attr(allow(dead_code, deprecated, unused_variables, unused_mut)))
233)]
234#![doc(rust_logo)]
235#![doc(auto_cfg(hide(no_global_oom_handling)))]
236// Don't link to std. We are std.
237#![no_std]
238// Tell the compiler to link to either panic_abort or panic_unwind
239#![needs_panic_runtime]
240//
241// Lints:
242#![warn(deprecated_in_future)]
243#![warn(missing_docs)]
244#![warn(missing_debug_implementations)]
245#![allow(explicit_outlives_requirements)]
246#![allow(unused_lifetimes)]
247#![allow(internal_features)]
248#![deny(fuzzy_provenance_casts)]
249#![deny(unsafe_op_in_unsafe_fn)]
250#![allow(rustdoc::redundant_explicit_links)]
251#![warn(rustdoc::unescaped_backticks)]
252// Ensure that std can be linked against panic_abort despite compiled with `-C panic=unwind`
253#![deny(ffi_unwind_calls)]
254// std may use features in a platform-specific way
255#![allow(unused_features)]
256//
257// Features:
258#![cfg_attr(test, feature(internal_output_capture, print_internals, update_panic_count, rt))]
259#![cfg_attr(
260    all(target_vendor = "fortanix", target_env = "sgx"),
261    feature(slice_index_methods, coerce_unsized, sgx_platform)
262)]
263#![cfg_attr(all(test, target_os = "uefi"), feature(uefi_std))]
264#![cfg_attr(target_family = "wasm", feature(stdarch_wasm_atomic_wait))]
265#![cfg_attr(target_arch = "wasm64", feature(simd_wasm64))]
266//
267// Language features:
268// tidy-alphabetical-start
269#![feature(alloc_error_handler)]
270#![feature(allocator_internals)]
271#![feature(allow_internal_unsafe)]
272#![feature(allow_internal_unstable)]
273#![feature(asm_experimental_arch)]
274#![feature(autodiff)]
275#![feature(cfg_sanitizer_cfi)]
276#![feature(cfg_target_thread_local)]
277#![feature(cfi_encoding)]
278#![feature(const_trait_impl)]
279#![feature(decl_macro)]
280#![feature(deprecated_suggestion)]
281#![feature(doc_cfg)]
282#![feature(doc_masked)]
283#![feature(doc_notable_trait)]
284#![feature(dropck_eyepatch)]
285#![feature(f16)]
286#![feature(f128)]
287#![feature(ffi_const)]
288#![feature(intra_doc_pointers)]
289#![feature(lang_items)]
290#![feature(link_cfg)]
291#![feature(linkage)]
292#![feature(macro_metavar_expr_concat)]
293#![feature(min_specialization)]
294#![feature(must_not_suspend)]
295#![feature(needs_panic_runtime)]
296#![feature(negative_impls)]
297#![feature(never_type)]
298#![feature(optimize_attribute)]
299#![feature(prelude_import)]
300#![feature(rustc_attrs)]
301#![feature(rustdoc_internals)]
302#![feature(staged_api)]
303#![feature(stmt_expr_attributes)]
304#![feature(strict_provenance_lints)]
305#![feature(target_feature_inline_always)]
306#![feature(thread_local)]
307#![feature(try_blocks)]
308#![feature(try_trait_v2)]
309#![feature(type_alias_impl_trait)]
310// tidy-alphabetical-end
311//
312// Library features (core):
313// tidy-alphabetical-start
314#![feature(borrowed_buf_init)]
315#![feature(bstr)]
316#![feature(bstr_internals)]
317#![feature(cast_maybe_uninit)]
318#![feature(char_internals)]
319#![feature(clone_to_uninit)]
320#![feature(const_convert)]
321#![feature(const_default)]
322#![feature(core_float_math)]
323#![feature(core_intrinsics)]
324#![feature(core_io_borrowed_buf)]
325#![feature(cstr_display)]
326#![feature(drop_guard)]
327#![feature(duration_constants)]
328#![feature(error_generic_member_access)]
329#![feature(error_iter)]
330#![feature(exact_size_is_empty)]
331#![feature(exclusive_wrapper)]
332#![feature(extend_one)]
333#![feature(float_algebraic)]
334#![feature(float_gamma)]
335#![feature(float_minimum_maximum)]
336#![feature(fmt_internals)]
337#![feature(fn_ptr_trait)]
338#![feature(formatting_options)]
339#![feature(funnel_shifts)]
340#![feature(generic_atomic)]
341#![feature(hash_map_internals)]
342#![feature(hash_map_macro)]
343#![feature(hasher_prefixfree_extras)]
344#![feature(hashmap_internals)]
345#![feature(hint_must_use)]
346#![feature(int_from_ascii)]
347#![feature(ip)]
348#![feature(iter_advance_by)]
349#![feature(iter_next_chunk)]
350#![feature(maybe_uninit_array_assume_init)]
351#![feature(maybe_uninit_fill)]
352#![feature(panic_can_unwind)]
353#![feature(panic_internals)]
354#![feature(pin_coerce_unsized_trait)]
355#![feature(pointer_is_aligned_to)]
356#![feature(portable_simd)]
357#![feature(ptr_as_uninit)]
358#![feature(ptr_mask)]
359#![feature(random)]
360#![feature(slice_internals)]
361#![feature(slice_ptr_get)]
362#![feature(slice_range)]
363#![feature(slice_split_once)]
364#![feature(std_internals)]
365#![feature(str_internals)]
366#![feature(sync_unsafe_cell)]
367#![feature(temporary_niche_types)]
368#![feature(ub_checks)]
369#![feature(uint_carryless_mul)]
370#![feature(used_with_arg)]
371// tidy-alphabetical-end
372//
373// Library features (alloc):
374// tidy-alphabetical-start
375#![feature(allocator_api)]
376#![feature(clone_from_ref)]
377#![feature(get_mut_unchecked)]
378#![feature(map_try_insert)]
379#![feature(slice_concat_trait)]
380#![feature(thin_box)]
381#![feature(try_reserve_kind)]
382#![feature(try_with_capacity)]
383#![feature(unique_rc_arc)]
384#![feature(wtf8_internals)]
385// tidy-alphabetical-end
386//
387// Library features (unwind):
388// tidy-alphabetical-start
389#![feature(panic_unwind)]
390// tidy-alphabetical-end
391//
392// Library features (std_detect):
393// tidy-alphabetical-start
394#![feature(stdarch_internal)]
395// tidy-alphabetical-end
396//
397// Only for re-exporting:
398// tidy-alphabetical-start
399#![feature(async_iterator)]
400#![feature(c_variadic)]
401#![feature(cfg_accessible)]
402#![feature(cfg_eval)]
403#![feature(concat_bytes)]
404#![feature(const_format_args)]
405#![feature(custom_test_frameworks)]
406#![feature(edition_panic)]
407#![feature(format_args_nl)]
408#![feature(log_syntax)]
409#![feature(test)]
410#![feature(trace_macros)]
411// tidy-alphabetical-end
412//
413// Only used in tests/benchmarks:
414//
415// Only for const-ness:
416// tidy-alphabetical-start
417#![feature(io_const_error)]
418// tidy-alphabetical-end
419//
420#![default_lib_allocator]
421// Removed features
422#![unstable_removed(
423    feature = "concat_idents",
424    reason = "Replaced by the macro_metavar_expr_concat feature",
425    link = "https://github.com/rust-lang/rust/issues/29599#issuecomment-2986866250",
426    since = "1.90.0"
427)]
428
429// The Rust prelude
430// The compiler expects the prelude definition to be defined before its use statement.
431pub mod prelude;
432
433// Explicitly import the prelude. The compiler uses this same unstable attribute
434// to import the prelude implicitly when building crates that depend on std.
435#[prelude_import]
436#[allow(unused)]
437use prelude::rust_2024::*;
438
439// Access to Bencher, etc.
440#[cfg(test)]
441extern crate test;
442
443#[allow(unused_imports)] // macros from `alloc` are not used on all platforms
444#[macro_use]
445extern crate alloc as alloc_crate;
446
447// Many compiler tests depend on libc being pulled in by std
448// so include it here even if it's unused.
449#[doc(masked)]
450#[allow(unused_extern_crates)]
451#[cfg(not(all(windows, target_env = "msvc")))]
452extern crate libc;
453
454// We always need an unwinder currently for backtraces
455#[doc(masked)]
456#[allow(unused_extern_crates)]
457extern crate unwind;
458
459// FIXME: #94122 this extern crate definition only exist here to stop
460// miniz_oxide docs leaking into std docs. Find better way to do it.
461// Remove exclusion from tidy platform check when this removed.
462#[doc(masked)]
463#[allow(unused_extern_crates)]
464#[cfg(all(
465    not(all(windows, target_env = "msvc", not(target_vendor = "uwp"))),
466    feature = "miniz_oxide"
467))]
468extern crate miniz_oxide;
469
470// During testing, this crate is not actually the "real" std library, but rather
471// it links to the real std library, which was compiled from this same source
472// code. So any lang items std defines are conditionally excluded (or else they
473// would generate duplicate lang item errors), and any globals it defines are
474// _not_ the globals used by "real" std. So this import, defined only during
475// testing gives test-std access to real-std lang items and globals. See #2912
476#[cfg(test)]
477extern crate std as realstd;
478
479// The standard macros that are not built-in to the compiler.
480#[macro_use]
481#[doc(hidden)]
482#[unstable(feature = "std_internals", issue = "none")]
483pub mod macros;
484
485// The runtime entry point and a few unstable public functions used by the
486// compiler
487#[macro_use]
488pub mod rt;
489
490#[stable(feature = "rust1", since = "1.0.0")]
491pub use core::any;
492#[stable(feature = "core_array", since = "1.35.0")]
493pub use core::array;
494#[unstable(feature = "async_iterator", issue = "79024")]
495pub use core::async_iter;
496#[stable(feature = "rust1", since = "1.0.0")]
497pub use core::cell;
498#[stable(feature = "rust1", since = "1.0.0")]
499pub use core::char;
500#[stable(feature = "rust1", since = "1.0.0")]
501pub use core::clone;
502#[stable(feature = "rust1", since = "1.0.0")]
503pub use core::cmp;
504#[stable(feature = "rust1", since = "1.0.0")]
505pub use core::convert;
506#[stable(feature = "rust1", since = "1.0.0")]
507pub use core::default;
508#[unstable(feature = "field_projections", issue = "145383")]
509pub use core::field;
510#[stable(feature = "futures_api", since = "1.36.0")]
511pub use core::future;
512#[stable(feature = "core_hint", since = "1.27.0")]
513pub use core::hint;
514#[stable(feature = "rust1", since = "1.0.0")]
515#[allow(deprecated, deprecated_in_future)]
516pub use core::i8;
517#[stable(feature = "rust1", since = "1.0.0")]
518#[allow(deprecated, deprecated_in_future)]
519pub use core::i16;
520#[stable(feature = "rust1", since = "1.0.0")]
521#[allow(deprecated, deprecated_in_future)]
522pub use core::i32;
523#[stable(feature = "rust1", since = "1.0.0")]
524#[allow(deprecated, deprecated_in_future)]
525pub use core::i64;
526#[stable(feature = "i128", since = "1.26.0")]
527#[allow(deprecated, deprecated_in_future)]
528pub use core::i128;
529#[stable(feature = "rust1", since = "1.0.0")]
530pub use core::intrinsics;
531#[stable(feature = "rust1", since = "1.0.0")]
532#[allow(deprecated, deprecated_in_future)]
533pub use core::isize;
534#[stable(feature = "rust1", since = "1.0.0")]
535pub use core::iter;
536#[stable(feature = "rust1", since = "1.0.0")]
537pub use core::marker;
538#[stable(feature = "rust1", since = "1.0.0")]
539pub use core::mem;
540#[stable(feature = "rust1", since = "1.0.0")]
541pub use core::ops;
542#[stable(feature = "rust1", since = "1.0.0")]
543pub use core::option;
544#[stable(feature = "pin", since = "1.33.0")]
545pub use core::pin;
546#[stable(feature = "rust1", since = "1.0.0")]
547pub use core::ptr;
548#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
549pub use core::range;
550#[stable(feature = "rust1", since = "1.0.0")]
551pub use core::result;
552#[stable(feature = "rust1", since = "1.0.0")]
553#[allow(deprecated, deprecated_in_future)]
554pub use core::u8;
555#[stable(feature = "rust1", since = "1.0.0")]
556#[allow(deprecated, deprecated_in_future)]
557pub use core::u16;
558#[stable(feature = "rust1", since = "1.0.0")]
559#[allow(deprecated, deprecated_in_future)]
560pub use core::u32;
561#[stable(feature = "rust1", since = "1.0.0")]
562#[allow(deprecated, deprecated_in_future)]
563pub use core::u64;
564#[stable(feature = "i128", since = "1.26.0")]
565#[allow(deprecated, deprecated_in_future)]
566pub use core::u128;
567#[unstable(feature = "unsafe_binders", issue = "130516")]
568pub use core::unsafe_binder;
569#[stable(feature = "rust1", since = "1.0.0")]
570#[allow(deprecated, deprecated_in_future)]
571pub use core::usize;
572
573#[stable(feature = "rust1", since = "1.0.0")]
574pub use alloc_crate::borrow;
575#[stable(feature = "rust1", since = "1.0.0")]
576pub use alloc_crate::boxed;
577#[stable(feature = "rust1", since = "1.0.0")]
578pub use alloc_crate::fmt;
579#[stable(feature = "rust1", since = "1.0.0")]
580pub use alloc_crate::format;
581#[stable(feature = "rust1", since = "1.0.0")]
582pub use alloc_crate::rc;
583#[stable(feature = "rust1", since = "1.0.0")]
584pub use alloc_crate::slice;
585#[stable(feature = "rust1", since = "1.0.0")]
586pub use alloc_crate::str;
587#[stable(feature = "rust1", since = "1.0.0")]
588pub use alloc_crate::string;
589#[stable(feature = "rust1", since = "1.0.0")]
590pub use alloc_crate::vec;
591
592#[path = "num/f128.rs"]
593pub mod f128;
594#[path = "num/f16.rs"]
595pub mod f16;
596#[path = "num/f32.rs"]
597pub mod f32;
598#[path = "num/f64.rs"]
599pub mod f64;
600
601#[macro_use]
602pub mod thread;
603pub mod ascii;
604pub mod backtrace;
605#[unstable(feature = "bstr", issue = "134915")]
606pub mod bstr;
607pub mod collections;
608pub mod env;
609pub mod error;
610pub mod ffi;
611pub mod fs;
612pub mod hash;
613pub mod io;
614pub mod net;
615pub mod num;
616pub mod os;
617pub mod panic;
618#[unstable(feature = "pattern_type_macro", issue = "123646")]
619pub mod pat;
620pub mod path;
621pub mod process;
622#[unstable(feature = "random", issue = "130703")]
623pub mod random;
624pub mod sync;
625pub mod time;
626
627// Pull in `std_float` crate  into std. The contents of
628// `std_float` are in a different repository: rust-lang/portable-simd.
629#[path = "../../portable-simd/crates/std_float/src/lib.rs"]
630#[allow(missing_debug_implementations, dead_code, unsafe_op_in_unsafe_fn)]
631#[allow(rustdoc::bare_urls)]
632#[unstable(feature = "portable_simd", issue = "86656")]
633mod std_float;
634
635#[unstable(feature = "portable_simd", issue = "86656")]
636pub mod simd {
637    #![doc = "Portable SIMD module.\n\nThis module offers a portable abstraction for SIMD operations\nthat is not bound to any particular hardware architecture.\n\n# What is \"portable\"?\n\nThis module provides a SIMD implementation that is fast and predictable on any target.\n\n### Portable SIMD works on every target\n\nUnlike target-specific SIMD in `std::arch`, portable SIMD compiles for every target.\nIn this regard, it is just like \"regular\" Rust.\n\n### Portable SIMD is consistent between targets\n\nA program using portable SIMD can expect identical behavior on any target.\nIn most regards, [`Simd<T, N>`] can be thought of as a parallelized `[T; N]` and operates like a sequence of `T`.\n\nThis has one notable exception: a handful of older architectures (e.g. `armv7` and `powerpc`) flush [subnormal](`f32::is_subnormal`) `f32` values to zero.\nOn these architectures, subnormal `f32` input values are replaced with zeros, and any operation producing subnormal `f32` values produces zeros instead.\nThis doesn\'t affect most architectures or programs.\n\n### Operations use the best instructions available\n\nOperations provided by this module compile to the best available SIMD instructions.\n\nPortable SIMD is not a low-level vendor library, and operations in portable SIMD _do not_ necessarily map to a single instruction.\nInstead, they map to a reasonable implementation of the operation for the target.\n\nConsistency between targets is not compromised to use faster or fewer instructions.\nIn some cases, `std::arch` will provide a faster function that has slightly different behavior than the `std::simd` equivalent.\nFor example, `_mm_min_ps`[^1] can be slightly faster than [`SimdFloat::simd_min`](`num::SimdFloat::simd_min`), but does not conform to the IEEE standard also used by [`f32::min`].\nWhen necessary, [`Simd<T, N>`] can be converted to the types provided by `std::arch` to make use of target-specific functions.\n\nMany targets simply don\'t have SIMD, or don\'t support SIMD for a particular element type.\nIn those cases, regular scalar operations are generated instead.\n\n[^1]: `_mm_min_ps(x, y)` is equivalent to `x.simd_lt(y).select(x, y)`\n"include_str!("../../portable-simd/crates/core_simd/src/core_simd_docs.md")]
638
639    #[doc(inline)]
640    pub use core::simd::*;
641
642    #[doc(inline)]
643    pub use crate::std_float::StdFloat;
644}
645
646#[unstable(feature = "autodiff", issue = "124509")]
647#[doc = "This module provides support for automatic differentiation. For precise information on\ndifferences between the `autodiff_forward` and `autodiff_reverse` macros and how to\nuse them, see their respective documentation.\n\n## General usage\n\nAutodiff macros can be applied to almost all function definitions, see below for examples.\nThey can be applied to functions accepting structs, arrays, slices, vectors, tuples, and more.\n\nIt is possible to apply multiple autodiff macros to the same function. As an example, this can\nbe helpful to compute the partial derivatives with respect to `x` and `y` independently:\n```rust,ignore (optional component)\n#[autodiff_forward(dsquare1, Dual, Const, Dual)]\n#[autodiff_forward(dsquare2, Const, Dual, Dual)]\n#[autodiff_forward(dsquare3, Active, Active, Active)]\nfn square(x: f64, y: f64) -> f64 {\n  x * x + 2.0 * y\n}\n```\n\nWe also support autodiff on functions with generic parameters:\n```rust,ignore (optional component)\n#[autodiff_forward(generic_derivative, Duplicated, Active)]\nfn generic_f<T: std::ops::Mul<Output = T> + Copy>(x: &T) -> T {\n x * x\n}\n```\n\nor applying autodiff to nested functions:\n```rust,ignore (optional component)\nfn outer(x: f64) -> f64 {\n  #[autodiff_forward(inner_derivative, Dual, Const)]\n  fn inner(y: f64) -> f64 {\n    y * y\n  }\n  inner_derivative(x, 1.0)\n}\n\nfn main() {\n    assert_eq!(outer(3.14), 6.28);\n}\n```\nThe generated function will be available in the same scope as the function differentiated, and\nhave the same private/pub usability.\n\n## Traits and impls\nAutodiff macros can be used in multiple ways in combination with traits:\n```rust,ignore (optional component)\nstruct Foo {\n    a: f64,\n}\n\ntrait MyTrait {\n    #[autodiff_reverse(df, Const, Active, Active)]\n    fn f(&self, x: f64) -> f64;\n}\n\nimpl MyTrait for Foo {\n    fn f(&self, x: f64) -> f64 {\n        x.sin()\n    }\n}\n\nfn main() {\n    let foo = Foo { a: 3.0f64 };\n    assert_eq!(foo.f(2.0), 2.0_f64.sin());\n    assert_eq!(foo.df(2.0, 1.0).1, 2.0_f64.cos());\n}\n```\nIn this case `df` will be the default implementation provided by the library who provided the\ntrait. A user implementing `MyTrait` could then decide to use the default implementation of\n`df`, or overwrite it with a custom implementation as a form of \"custom derivatives\".\n\nOn the other hand, a function generated by either autodiff macro can also be used to implement a\ntrait:\n```rust,ignore (optional component)\nstruct Foo {\n    a: f64,\n}\n\ntrait MyTrait {\n    fn f(&self, x: f64) -> f64;\n    fn df(&self, x: f64, seed: f64) -> (f64, f64);\n}\n\nimpl MyTrait for Foo {\n    #[autodiff_reverse(df, Const, Active, Active)]\n    fn f(&self, x: f64) -> f64 {\n        self.a * 0.25 * (x * x - 1.0 - 2.0 * x.ln())\n    }\n}\n```\n\nSimple `impl` blocks without traits are also supported. Differentiating with respect to the\nimplemented struct will then require the use of a \"shadow struct\" to hold the derivatives of the\nstruct fields:\n\n```rust,ignore (optional component)\nstruct OptProblem {\n    a: f64,\n    b: f64,\n}\n\nimpl OptProblem {\n    #[autodiff_reverse(d_objective, Duplicated, Duplicated, Duplicated)]\n    fn objective(&self, x: &[f64], out: &mut f64) {\n        *out = self.a + x[0].sqrt() * self.b\n    }\n}\nfn main() {\n    let p = OptProblem { a: 1., b: 2. };\n    let mut p_shadow = OptProblem { a: 0., b: 0. };\n    let mut dx = [0.0];\n    let mut out = 0.0;\n    let mut dout = 1.0;\n\n    p.d_objective(&mut p_shadow, &x, &mut dx, &mut out, &mut dout);\n}\n```\n\n## Higher-order derivatives\nFinally, it is possible to generate higher-order derivatives (e.g. Hessian) by applying an\nautodiff macro to a function that is already generated by an autodiff macro, via a thin wrapper.\nThe following example uses Forward mode over Reverse mode\n\n```rust,ignore (optional component)\n#[autodiff_reverse(df, Duplicated, Duplicated)]\nfn f(x: &[f64;2], y: &mut f64) {\n  *y = x[0] * x[0] + x[1] * x[0]\n}\n\n#[autodiff_forward(h, Dual, Dual, Dual, Dual)]\nfn wrapper(x: &[f64;2], dx: &mut [f64;2], y: &mut f64, dy: &mut f64) {\n  df(x, dx, y, dy);\n}\n\nfn main() {\n    let mut y = 0.0;\n    let x = [2.0, 2.0];\n\n    let mut dy = 0.0;\n    let mut dx = [1.0, 0.0];\n\n    let mut bx = [0.0, 0.0];\n    let mut by = 1.0;\n    let mut dbx = [0.0, 0.0];\n    let mut dby = 0.0;\n    h(&x, &mut dx, &mut bx, &mut dbx, &mut y, &mut dy, &mut by, &mut dby);\n    assert_eq!(&dbx, [2.0, 1.0]);\n}\n```\n\n## Current limitations:\n\n- Differentiating a function which accepts a `dyn Trait` is currently not supported.\n- Builds without `lto=\"fat\"` are not yet supported.\n- Builds in debug mode are currently more likely to fail compilation.\n"include_str!("../../core/src/autodiff.md")]
648pub mod autodiff {
649    /// This macro handles automatic differentiation.
650    pub use core::autodiff::{autodiff_forward, autodiff_reverse};
651}
652
653#[stable(feature = "futures_api", since = "1.36.0")]
654pub mod task {
655    //! Types and Traits for working with asynchronous tasks.
656
657    #[doc(inline)]
658    #[stable(feature = "wake_trait", since = "1.51.0")]
659    pub use alloc::task::*;
660    #[doc(inline)]
661    #[stable(feature = "futures_api", since = "1.36.0")]
662    pub use core::task::*;
663}
664
665#[doc = "SIMD and vendor intrinsics module.\n\nThis module is intended to be the gateway to architecture-specific\nintrinsic functions, typically related to SIMD (but not always!). Each\narchitecture that Rust compiles to may contain a submodule here, which\nmeans that this is not a portable module! If you\'re writing a portable\nlibrary take care when using these APIs!\n\nUnder this module you\'ll find an architecture-named module, such as\n`x86_64`. Each `#[cfg(target_arch)]` that Rust can compile to may have a\nmodule entry here, only present on that particular target. For example the\n`i686-pc-windows-msvc` target will have an `x86` module here, whereas\n`x86_64-pc-windows-msvc` has `x86_64`.\n\n[rfc]: https://github.com/rust-lang/rfcs/pull/2325\n[tracked]: https://github.com/rust-lang/rust/issues/48556\n\n# Overview\n\nThis module exposes vendor-specific intrinsics that typically correspond to\na single machine instruction. These intrinsics are not portable: their\navailability is architecture-dependent, and not all machines of that\narchitecture might provide the intrinsic.\n\nThe `arch` module is intended to be a low-level implementation detail for\nhigher-level APIs. Using it correctly can be quite tricky as you need to\nensure at least a few guarantees are upheld:\n\n* The correct architecture\'s module is used. For example the `arm` module\n  isn\'t available on the `x86_64-unknown-linux-gnu` target. This is\n  typically done by ensuring that `#[cfg]` is used appropriately when using\n  this module.\n* The CPU the program is currently running on supports the function being\n  called. For example it is unsafe to call an AVX2 function on a CPU that\n  doesn\'t actually support AVX2.\n\nAs a result of the latter of these guarantees all intrinsics in this module\nare `unsafe` and extra care needs to be taken when calling them!\n\n# CPU Feature Detection\n\nIn order to call these APIs in a safe fashion there\'s a number of\nmechanisms available to ensure that the correct CPU feature is available\nto call an intrinsic. Let\'s consider, for example, the `_mm256_add_epi64`\nintrinsics on the `x86` and `x86_64` architectures. This function requires\nthe AVX2 feature as [documented by Intel][intel-dox] so to correctly call\nthis function we need to (a) guarantee we only call it on `x86`/`x86_64`\nand (b) ensure that the CPU feature is available\n\n[intel-dox]: https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_add_epi64&expand=100\n\n## Static CPU Feature Detection\n\nThe first option available to us is to conditionally compile code via the\n`#[cfg]` attribute. CPU features correspond to the `target_feature` cfg\navailable, and can be used like so:\n\n```ignore\n#[cfg(\n    all(\n        any(target_arch = \"x86\", target_arch = \"x86_64\"),\n        target_feature = \"avx2\"\n    )\n)]\nfn foo() {\n    #[cfg(target_arch = \"x86\")]\n    use std::arch::x86::_mm256_add_epi64;\n    #[cfg(target_arch = \"x86_64\")]\n    use std::arch::x86_64::_mm256_add_epi64;\n\n    unsafe {\n        _mm256_add_epi64(...);\n    }\n}\n```\n\nHere we\'re using `#[cfg(target_feature = \"avx2\")]` to conditionally compile\nthis function into our module. This means that if the `avx2` feature is\n*enabled statically* then we\'ll use the `_mm256_add_epi64` function at\nruntime. The `unsafe` block here can be justified through the usage of\n`#[cfg]` to only compile the code in situations where the safety guarantees\nare upheld.\n\nStatically enabling a feature is typically done with the `-C\ntarget-feature` or `-C target-cpu` flags to the compiler. For example if\nyour local CPU supports AVX2 then you can compile the above function with:\n\n```sh\n$ RUSTFLAGS=\'-C target-cpu=native\' cargo build\n```\n\nOr otherwise you can specifically enable just the AVX2 feature:\n\n```sh\n$ RUSTFLAGS=\'-C target-feature=+avx2\' cargo build\n```\n\nNote that when you compile a binary with a particular feature enabled it\'s\nimportant to ensure that you only run the binary on systems which satisfy\nthe required feature set.\n\n## Dynamic CPU Feature Detection\n\nSometimes statically dispatching isn\'t quite what you want. Instead you\nmight want to build a portable binary that runs across a variety of CPUs,\nbut at runtime it selects the most optimized implementation available. This\nallows you to build a \"least common denominator\" binary which has certain\nsections more optimized for different CPUs.\n\nTaking our previous example from before, we\'re going to compile our binary\n*without* AVX2 support, but we\'d like to enable it for just one function.\nWe can do that in a manner like:\n\n```ignore\nfn foo() {\n    #[cfg(any(target_arch = \"x86\", target_arch = \"x86_64\"))]\n    {\n        if is_x86_feature_detected!(\"avx2\") {\n            return unsafe { foo_avx2() };\n        }\n    }\n\n    // fallback implementation without using AVX2\n}\n\n#[cfg(any(target_arch = \"x86\", target_arch = \"x86_64\"))]\n#[target_feature(enable = \"avx2\")]\nunsafe fn foo_avx2() {\n    #[cfg(target_arch = \"x86\")]\n    use std::arch::x86::_mm256_add_epi64;\n    #[cfg(target_arch = \"x86_64\")]\n    use std::arch::x86_64::_mm256_add_epi64;\n\n    unsafe { _mm256_add_epi64(...); }\n}\n```\n\nThere\'s a couple of components in play here, so let\'s go through them in\ndetail!\n\n* First up we notice the `is_x86_feature_detected!` macro. Provided by\n  the standard library, this macro will perform necessary runtime detection\n  to determine whether the CPU the program is running on supports the\n  specified feature. In this case the macro will expand to a boolean\n  expression evaluating to whether the local CPU has the AVX2 feature or\n  not.\n\n  Note that this macro, like the `arch` module, is platform-specific. For\n  example calling `is_x86_feature_detected!(\"avx2\")` on ARM will be a\n  compile time error. To ensure we don\'t hit this error a statement level\n  `#[cfg]` is used to only compile usage of the macro on `x86`/`x86_64`.\n\n* Next up we see our AVX2-enabled function, `foo_avx2`. This function is\n  decorated with the `#[target_feature]` attribute which enables a CPU\n  feature for just this one function. Using a compiler flag like `-C\n  target-feature=+avx2` will enable AVX2 for the entire program, but using\n  an attribute will only enable it for the one function. Usage of the\n  `#[target_feature]` attribute currently requires the function to also be\n  `unsafe`, as we see here. This is because the function can only be\n  correctly called on systems which have the AVX2 (like the intrinsics\n  themselves).\n\nAnd with all that we should have a working program! This program will run\nacross all machines and it\'ll use the optimized AVX2 implementation on\nmachines where support is detected.\n\n# Ergonomics\n\nIt\'s important to note that using the `arch` module is not the easiest\nthing in the world, so if you\'re curious to try it out you may want to\nbrace yourself for some wordiness!\n\nThe primary purpose of this module is to enable stable crates on crates.io\nto build up much more ergonomic abstractions which end up using SIMD under\nthe hood. Over time these abstractions may also move into the standard\nlibrary itself, but for now this module is tasked with providing the bare\nminimum necessary to use vendor intrinsics on stable Rust.\n\n# Other architectures\n\nThis documentation is only for one particular architecture, you can find\nothers at:\n\n* [`x86`]\n* [`x86_64`]\n* [`arm`]\n* [`aarch64`]\n* [`amdgpu`]\n* [`hexagon`]\n* [`riscv32`]\n* [`riscv64`]\n* [`mips`]\n* [`mips64`]\n* [`powerpc`]\n* [`powerpc64`]\n* [`nvptx`]\n* [`wasm32`]\n* [`loongarch32`]\n* [`loongarch64`]\n* [`s390x`]\n\n[`x86`]: ../../core/arch/x86/index.html\n[`x86_64`]: ../../core/arch/x86_64/index.html\n[`arm`]: ../../core/arch/arm/index.html\n[`aarch64`]: ../../core/arch/aarch64/index.html\n[`amdgpu`]: ../../core/arch/amdgpu/index.html\n[`hexagon`]: ../../core/arch/hexagon/index.html\n[`riscv32`]: ../../core/arch/riscv32/index.html\n[`riscv64`]: ../../core/arch/riscv64/index.html\n[`mips`]: ../../core/arch/mips/index.html\n[`mips64`]: ../../core/arch/mips64/index.html\n[`powerpc`]: ../../core/arch/powerpc/index.html\n[`powerpc64`]: ../../core/arch/powerpc64/index.html\n[`nvptx`]: ../../core/arch/nvptx/index.html\n[`wasm32`]: ../../core/arch/wasm32/index.html\n[`loongarch32`]: ../../core/arch/loongarch32/index.html\n[`loongarch64`]: ../../core/arch/loongarch64/index.html\n[`s390x`]: ../../core/arch/s390x/index.html\n\n# Examples\n\nFirst let\'s take a look at not actually using any intrinsics but instead\nusing LLVM\'s auto-vectorization to produce optimized vectorized code for\nAVX2 and also for the default platform.\n\n```rust\nfn main() {\n    let mut dst = [0];\n    add_quickly(&[1], &[2], &mut dst);\n    assert_eq!(dst[0], 3);\n}\n\nfn add_quickly(a: &[u8], b: &[u8], c: &mut [u8]) {\n    #[cfg(any(target_arch = \"x86\", target_arch = \"x86_64\"))]\n    {\n        // Note that this `unsafe` block is safe because we\'re testing\n        // that the `avx2` feature is indeed available on our CPU.\n        if is_x86_feature_detected!(\"avx2\") {\n            return unsafe { add_quickly_avx2(a, b, c) };\n        }\n    }\n\n    add_quickly_fallback(a, b, c)\n}\n\n#[cfg(any(target_arch = \"x86\", target_arch = \"x86_64\"))]\n#[target_feature(enable = \"avx2\")]\nunsafe fn add_quickly_avx2(a: &[u8], b: &[u8], c: &mut [u8]) {\n    add_quickly_fallback(a, b, c) // the function below is inlined here\n}\n\nfn add_quickly_fallback(a: &[u8], b: &[u8], c: &mut [u8]) {\n    for ((a, b), c) in a.iter().zip(b).zip(c) {\n        *c = *a + *b;\n    }\n}\n```\n\nNext up let\'s take a look at an example of manually using intrinsics. Here\nwe\'ll be using SSE4.1 features to implement hex encoding.\n\n```\nfn main() {\n    let mut dst = [0; 32];\n    hex_encode(b\"\\x01\\x02\\x03\", &mut dst);\n    assert_eq!(&dst[..6], b\"010203\");\n\n    let mut src = [0; 16];\n    for i in 0..16 {\n        src[i] = (i + 1) as u8;\n    }\n    hex_encode(&src, &mut dst);\n    assert_eq!(&dst, b\"0102030405060708090a0b0c0d0e0f10\");\n}\n\npub fn hex_encode(src: &[u8], dst: &mut [u8]) {\n    let len = src.len().checked_mul(2).unwrap();\n    assert!(dst.len() >= len);\n\n    #[cfg(any(target_arch = \"x86\", target_arch = \"x86_64\"))]\n    {\n        if is_x86_feature_detected!(\"sse4.1\") {\n            return unsafe { hex_encode_sse41(src, dst) };\n        }\n    }\n\n    hex_encode_fallback(src, dst)\n}\n\n// translated from\n// <https://github.com/Matherunner/bin2hex-sse/blob/master/base16_sse4.cpp>\n#[target_feature(enable = \"sse4.1\")]\n#[cfg(any(target_arch = \"x86\", target_arch = \"x86_64\"))]\nunsafe fn hex_encode_sse41(mut src: &[u8], dst: &mut [u8]) {\n    #[cfg(target_arch = \"x86\")]\n    use std::arch::x86::*;\n    #[cfg(target_arch = \"x86_64\")]\n    use std::arch::x86_64::*;\n\n    unsafe {\n        let ascii_zero = _mm_set1_epi8(b\'0\' as i8);\n        let nines = _mm_set1_epi8(9);\n        let ascii_a = _mm_set1_epi8((b\'a\' - 9 - 1) as i8);\n        let and4bits = _mm_set1_epi8(0xf);\n\n        let mut i = 0_isize;\n        while src.len() >= 16 {\n            let invec = _mm_loadu_si128(src.as_ptr() as *const _);\n\n            let masked1 = _mm_and_si128(invec, and4bits);\n            let masked2 = _mm_and_si128(_mm_srli_epi64(invec, 4), and4bits);\n\n            // return 0xff corresponding to the elements > 9, or 0x00 otherwise\n            let cmpmask1 = _mm_cmpgt_epi8(masked1, nines);\n            let cmpmask2 = _mm_cmpgt_epi8(masked2, nines);\n\n            // add \'0\' or the offset depending on the masks\n            let masked1 = _mm_add_epi8(\n                masked1,\n                _mm_blendv_epi8(ascii_zero, ascii_a, cmpmask1),\n            );\n            let masked2 = _mm_add_epi8(\n                masked2,\n                _mm_blendv_epi8(ascii_zero, ascii_a, cmpmask2),\n            );\n\n            // interleave masked1 and masked2 bytes\n            let res1 = _mm_unpacklo_epi8(masked2, masked1);\n            let res2 = _mm_unpackhi_epi8(masked2, masked1);\n\n            _mm_storeu_si128(dst.as_mut_ptr().offset(i * 2) as *mut _, res1);\n            _mm_storeu_si128(\n                dst.as_mut_ptr().offset(i * 2 + 16) as *mut _,\n                res2,\n            );\n            src = &src[16..];\n            i += 16;\n        }\n\n        let i = i as usize;\n        hex_encode_fallback(src, &mut dst[i * 2..]);\n    }\n}\n\nfn hex_encode_fallback(src: &[u8], dst: &mut [u8]) {\n    fn hex(byte: u8) -> u8 {\n        static TABLE: &[u8] = b\"0123456789abcdef\";\n        TABLE[byte as usize]\n    }\n\n    for (byte, slots) in src.iter().zip(dst.chunks_mut(2)) {\n        slots[0] = hex((*byte >> 4) & 0xf);\n        slots[1] = hex(*byte & 0xf);\n    }\n}\n```\n"include_str!("../../stdarch/crates/core_arch/src/core_arch_docs.md")]
666#[stable(feature = "simd_arch", since = "1.27.0")]
667pub mod arch {
668    #[stable(feature = "simd_arch", since = "1.27.0")]
669    // The `no_inline`-attribute is required to make the documentation of all
670    // targets available.
671    // See https://github.com/rust-lang/rust/pull/57808#issuecomment-457390549 for
672    // more information.
673    #[doc(no_inline)] // Note (#82861): required for correct documentation
674    pub use core::arch::*;
675
676    #[stable(feature = "simd_aarch64", since = "1.60.0")]
677    pub use std_detect::is_aarch64_feature_detected;
678    #[unstable(feature = "stdarch_arm_feature_detection", issue = "111190")]
679    pub use std_detect::is_arm_feature_detected;
680    #[unstable(feature = "is_loongarch_feature_detected", issue = "117425")]
681    pub use std_detect::is_loongarch_feature_detected;
682    #[unstable(feature = "is_riscv_feature_detected", issue = "111192")]
683    pub use std_detect::is_riscv_feature_detected;
684    #[stable(feature = "stdarch_s390x_feature_detection", since = "1.93.0")]
685    pub use std_detect::is_s390x_feature_detected;
686    #[stable(feature = "simd_x86", since = "1.27.0")]
687    pub use std_detect::is_x86_feature_detected;
688    #[unstable(feature = "stdarch_mips_feature_detection", issue = "111188")]
689    pub use std_detect::{is_mips_feature_detected, is_mips64_feature_detected};
690    #[unstable(feature = "stdarch_powerpc_feature_detection", issue = "111191")]
691    pub use std_detect::{is_powerpc_feature_detected, is_powerpc64_feature_detected};
692}
693
694// This was stabilized in the crate root so we have to keep it there.
695#[stable(feature = "simd_x86", since = "1.27.0")]
696pub use std_detect::is_x86_feature_detected;
697
698mod sys;
699
700pub mod alloc;
701
702// Private support modules
703mod panicking;
704
705#[path = "../../backtrace/src/lib.rs"]
706#[allow(dead_code, unused_attributes, fuzzy_provenance_casts, unsafe_op_in_unsafe_fn)]
707mod backtrace_rs;
708
709#[stable(feature = "cfg_select", since = "1.95.0")]
710pub use core::cfg_select;
711#[unstable(
712    feature = "concat_bytes",
713    issue = "87555",
714    reason = "`concat_bytes` is not stable enough for use and is subject to change"
715)]
716pub use core::concat_bytes;
717#[unstable(feature = "derive_macro_global_path", issue = "154645")]
718pub use core::derive;
719#[stable(feature = "matches_macro", since = "1.42.0")]
720#[allow(deprecated, deprecated_in_future)]
721pub use core::matches;
722#[stable(feature = "core_primitive", since = "1.43.0")]
723pub use core::primitive;
724#[stable(feature = "todo_macro", since = "1.40.0")]
725#[allow(deprecated, deprecated_in_future)]
726pub use core::todo;
727// Re-export built-in macros defined through core.
728#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
729pub use core::{
730    assert, cfg, column, compile_error, concat, const_format_args, env, file, format_args,
731    format_args_nl, include, include_bytes, include_str, line, log_syntax, module_path, option_env,
732    stringify, trace_macros,
733};
734// Re-export macros defined in core.
735#[stable(feature = "rust1", since = "1.0.0")]
736#[allow(deprecated, deprecated_in_future)]
737pub use core::{
738    assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, r#try, unimplemented,
739    unreachable, write, writeln,
740};
741#[stable(feature = "assert_matches", since = "1.95.0")]
742pub use core::{assert_matches, debug_assert_matches};
743
744// Re-export unstable derive macro defined through core.
745#[unstable(feature = "derive_from", issue = "144889")]
746/// Unstable module containing the unstable `From` derive macro.
747pub mod from {
748    #[unstable(feature = "derive_from", issue = "144889")]
749    pub use core::from::From;
750}
751
752// Include a number of private modules that exist solely to provide
753// the rustdoc documentation for primitive types. Using `include!`
754// because rustdoc only looks for these modules at the crate level.
755include!("../../core/src/primitive_docs.rs");
756
757// Include a number of private modules that exist solely to provide
758// the rustdoc documentation for the existing keywords. Using `include!`
759// because rustdoc only looks for these modules at the crate level.
760include!("keyword_docs.rs");
761
762// This is required to avoid an unstable error when `restricted-std` is not
763// enabled. The use of #![feature(restricted_std)] in rustc-std-workspace-std
764// is unconditional, so the unstable feature needs to be defined somewhere.
765#[unstable(feature = "restricted_std", issue = "none")]
766mod __restricted_std_workaround {}
767
768mod sealed {
769    /// This trait being unreachable from outside the crate
770    /// prevents outside implementations of our extension traits.
771    /// This allows adding more trait methods in the future.
772    #[unstable(feature = "sealed", issue = "none")]
773    pub trait Sealed {}
774}
775
776#[cfg(test)]
777#[allow(dead_code)] // Not used in all configurations.
778pub(crate) mod test_helpers;