414414//
415415#![ default_lib_allocator]
416416
417+ // We want to be able to `cargo miri test` this crate, but that's tricky.
418+ // We use the `miri-test` feature to indicate that we're running `cargo miri test`, and
419+ // with that feature we turn this crate into a re-export of the sysroot crate. We only do this when
420+ // building the crate that will become a dependency, not when doing the actual (doc)test build.
421+ // See `core/src/lib.rs` for more information.
422+ #[ cfg( not( any( not( feature = "miri-test" ) , test, doctest) ) ) ]
423+ extern crate std as realstd;
424+ #[ cfg( not( any( not( feature = "miri-test" ) , test, doctest) ) ) ]
425+ #[ stable( feature = "miri_test_libstd" , since = "1.0.0" ) ]
426+ pub use realstd:: * ;
427+
428+ // Otherwise, we build the crate as usual. To avoid having to repeat the same `cfg` so many times,
429+ // we `include!("lib_.rs")` with the main crate contents, and `cfg` the `include!`. However, some
430+ // macro-related things can't be behind the `include!` so we have to repeat the `cfg` for them.
431+
417432// Explicitly import the prelude. The compiler uses this same unstable attribute
418433// to import the prelude implicitly when building crates that depend on std.
434+ #[ cfg( not( all( feature = "miri-test" , not( any( test, doctest) ) ) ) ) ]
419435#[ prelude_import]
420436#[ allow( unused) ]
421437use prelude:: rust_2021:: * ;
@@ -424,14 +440,17 @@ use prelude::rust_2021::*;
424440#[ cfg( test) ]
425441extern crate test;
426442
443+ #[ cfg( not( all( feature = "miri-test" , not( any( test, doctest) ) ) ) ) ]
427444#[ allow( unused_imports) ] // macros from `alloc` are not used on all platforms
428445#[ macro_use]
429446extern crate alloc as alloc_crate;
447+ #[ cfg( not( all( feature = "miri-test" , not( any( test, doctest) ) ) ) ) ]
430448#[ doc( masked) ]
431449#[ allow( unused_extern_crates) ]
432450extern crate libc;
433451
434452// We always need an unwinder currently for backtraces
453+ #[ cfg( not( all( feature = "miri-test" , not( any( test, doctest) ) ) ) ) ]
435454#[ doc( masked) ]
436455#[ allow( unused_extern_crates) ]
437456extern crate unwind;
@@ -441,6 +460,7 @@ extern crate unwind;
441460// Remove exclusion from tidy platform check when this removed.
442461#[ doc( masked) ]
443462#[ allow( unused_extern_crates) ]
463+ #[ cfg( not( all( feature = "miri-test" , not( any( test, doctest) ) ) ) ) ]
444464#[ cfg( all(
445465 not( all( windows, target_env = "msvc" , not( target_vendor = "uwp" ) ) ) ,
446466 feature = "miniz_oxide"
@@ -457,286 +477,23 @@ extern crate miniz_oxide;
457477extern crate std as realstd;
458478
459479// The standard macros that are not built-in to the compiler.
480+ #[ cfg( not( all( feature = "miri-test" , not( any( test, doctest) ) ) ) ) ]
460481#[ macro_use]
461482mod macros;
462483
463484// The runtime entry point and a few unstable public functions used by the
464485// compiler
486+ #[ cfg( not( all( feature = "miri-test" , not( any( test, doctest) ) ) ) ) ]
465487#[ macro_use]
466488pub mod rt;
467489
468490// The Rust prelude
491+ #[ cfg( not( all( feature = "miri-test" , not( any( test, doctest) ) ) ) ) ]
469492pub mod prelude;
470493
471- // Public module declarations and re-exports
472- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
473- pub use alloc_crate:: borrow;
474- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
475- pub use alloc_crate:: boxed;
476- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
477- pub use alloc_crate:: fmt;
478- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
479- pub use alloc_crate:: format;
480- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
481- pub use alloc_crate:: rc;
482- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
483- pub use alloc_crate:: slice;
484- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
485- pub use alloc_crate:: str;
486- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
487- pub use alloc_crate:: string;
488- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
489- pub use alloc_crate:: vec;
490- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
491- pub use core:: any;
492- #[ stable( feature = "core_array" , since = "1.36.0" ) ]
493- pub use core:: array;
494- #[ unstable( feature = "async_iterator" , issue = "79024" ) ]
495- pub use core:: async_iter;
496- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
497- pub use core:: cell;
498- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
499- pub use core:: char;
500- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
501- pub use core:: clone;
502- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
503- pub use core:: cmp;
504- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
505- pub use core:: convert;
506- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
507- pub use core:: default;
508- #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
509- pub use core:: future;
510- #[ stable( feature = "core_hint" , since = "1.27.0" ) ]
511- pub use core:: hint;
512- #[ stable( feature = "i128" , since = "1.26.0" ) ]
513- #[ allow( deprecated, deprecated_in_future) ]
514- pub use core:: i128;
515- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
516- #[ allow( deprecated, deprecated_in_future) ]
517- pub use core:: i16;
518- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
519- #[ allow( deprecated, deprecated_in_future) ]
520- pub use core:: i32;
521- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
522- #[ allow( deprecated, deprecated_in_future) ]
523- pub use core:: i64;
524- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
525- #[ allow( deprecated, deprecated_in_future) ]
526- pub use core:: i8;
527- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
528- pub use core:: intrinsics;
529- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
530- #[ allow( deprecated, deprecated_in_future) ]
531- pub use core:: isize;
532- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
533- pub use core:: iter;
534- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
535- pub use core:: marker;
536- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
537- pub use core:: mem;
538- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
539- pub use core:: ops;
540- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
541- pub use core:: option;
542- #[ stable( feature = "pin" , since = "1.33.0" ) ]
543- pub use core:: pin;
544- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
545- pub use core:: ptr;
546- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
547- pub use core:: result;
548- #[ stable( feature = "i128" , since = "1.26.0" ) ]
549- #[ allow( deprecated, deprecated_in_future) ]
550- pub use core:: u128;
551- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
552- #[ allow( deprecated, deprecated_in_future) ]
553- pub use core:: u16;
554- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
555- #[ allow( deprecated, deprecated_in_future) ]
556- pub use core:: u32;
557- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
558- #[ allow( deprecated, deprecated_in_future) ]
559- pub use core:: u64;
560- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
561- #[ allow( deprecated, deprecated_in_future) ]
562- pub use core:: u8;
563- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
564- #[ allow( deprecated, deprecated_in_future) ]
565- pub use core:: usize;
566-
567- pub mod f32;
568- pub mod f64;
569-
494+ #[ cfg( not( all( feature = "miri-test" , not( any( test, doctest) ) ) ) ) ]
570495#[ macro_use]
571496pub mod thread;
572- pub mod ascii;
573- pub mod backtrace;
574- pub mod collections;
575- pub mod env;
576- pub mod error;
577- pub mod ffi;
578- pub mod fs;
579- pub mod hash;
580- pub mod io;
581- pub mod net;
582- pub mod num;
583- pub mod os;
584- pub mod panic;
585- pub mod path;
586- pub mod process;
587- pub mod sync;
588- pub mod time;
589-
590- // Pull in `std_float` crate into std. The contents of
591- // `std_float` are in a different repository: rust-lang/portable-simd.
592- #[ path = "../../portable-simd/crates/std_float/src/lib.rs" ]
593- #[ allow( missing_debug_implementations, dead_code, unsafe_op_in_unsafe_fn) ]
594- #[ allow( rustdoc:: bare_urls) ]
595- #[ unstable( feature = "portable_simd" , issue = "86656" ) ]
596- mod std_float;
597-
598- #[ unstable( feature = "portable_simd" , issue = "86656" ) ]
599- pub mod simd {
600- #![ doc = include_str ! ( "../../portable-simd/crates/core_simd/src/core_simd_docs.md" ) ]
601-
602- #[ doc( inline) ]
603- pub use crate :: std_float:: StdFloat ;
604- #[ doc( inline) ]
605- pub use core:: simd:: * ;
606- }
607-
608- #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
609- pub mod task {
610- //! Types and Traits for working with asynchronous tasks.
611-
612- #[ doc( inline) ]
613- #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
614- pub use core:: task:: * ;
615-
616- #[ doc( inline) ]
617- #[ stable( feature = "wake_trait" , since = "1.51.0" ) ]
618- pub use alloc:: task:: * ;
619- }
620-
621- #[ doc = include_str ! ( "../../stdarch/crates/core_arch/src/core_arch_docs.md" ) ]
622- #[ stable( feature = "simd_arch" , since = "1.27.0" ) ]
623- pub mod arch {
624- #[ stable( feature = "simd_arch" , since = "1.27.0" ) ]
625- // The `no_inline`-attribute is required to make the documentation of all
626- // targets available.
627- // See https://github.com/rust-lang/rust/pull/57808#issuecomment-457390549 for
628- // more information.
629- #[ doc( no_inline) ] // Note (#82861): required for correct documentation
630- pub use core:: arch:: * ;
631-
632- #[ stable( feature = "simd_aarch64" , since = "1.60.0" ) ]
633- pub use std_detect:: is_aarch64_feature_detected;
634- #[ unstable( feature = "stdarch_arm_feature_detection" , issue = "111190" ) ]
635- pub use std_detect:: is_arm_feature_detected;
636- #[ unstable( feature = "is_riscv_feature_detected" , issue = "111192" ) ]
637- pub use std_detect:: is_riscv_feature_detected;
638- #[ stable( feature = "simd_x86" , since = "1.27.0" ) ]
639- pub use std_detect:: is_x86_feature_detected;
640- #[ unstable( feature = "stdarch_mips_feature_detection" , issue = "111188" ) ]
641- pub use std_detect:: { is_mips64_feature_detected, is_mips_feature_detected} ;
642- #[ unstable( feature = "stdarch_powerpc_feature_detection" , issue = "111191" ) ]
643- pub use std_detect:: { is_powerpc64_feature_detected, is_powerpc_feature_detected} ;
644- }
645-
646- // This was stabilized in the crate root so we have to keep it there.
647- #[ stable( feature = "simd_x86" , since = "1.27.0" ) ]
648- pub use std_detect:: is_x86_feature_detected;
649-
650- // Platform-abstraction modules
651- mod sys;
652- mod sys_common;
653497
654- pub mod alloc;
655-
656- // Private support modules
657- mod panicking;
658-
659- #[ path = "../../backtrace/src/lib.rs" ]
660- #[ allow( dead_code, unused_attributes, fuzzy_provenance_casts) ]
661- mod backtrace_rs;
662-
663- // Re-export macros defined in core.
664- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
665- #[ allow( deprecated, deprecated_in_future) ]
666- pub use core:: {
667- assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, matches, todo, r#try,
668- unimplemented, unreachable, write, writeln,
669- } ;
670-
671- // Re-export built-in macros defined through core.
672- #[ stable( feature = "builtin_macro_prelude" , since = "1.38.0" ) ]
673- #[ allow( deprecated) ]
674- pub use core:: {
675- assert, assert_matches, cfg, column, compile_error, concat, concat_idents, const_format_args,
676- env, file, format_args, format_args_nl, include, include_bytes, include_str, line, log_syntax,
677- module_path, option_env, stringify, trace_macros,
678- } ;
679-
680- #[ unstable(
681- feature = "concat_bytes" ,
682- issue = "87555" ,
683- reason = "`concat_bytes` is not stable enough for use and is subject to change"
684- ) ]
685- pub use core:: concat_bytes;
686-
687- #[ unstable( feature = "cfg_match" , issue = "115585" ) ]
688- pub use core:: cfg_match;
689-
690- #[ stable( feature = "core_primitive" , since = "1.43.0" ) ]
691- pub use core:: primitive;
692-
693- // Include a number of private modules that exist solely to provide
694- // the rustdoc documentation for primitive types. Using `include!`
695- // because rustdoc only looks for these modules at the crate level.
696- include ! ( "../../core/src/primitive_docs.rs" ) ;
697-
698- // Include a number of private modules that exist solely to provide
699- // the rustdoc documentation for the existing keywords. Using `include!`
700- // because rustdoc only looks for these modules at the crate level.
701- include ! ( "keyword_docs.rs" ) ;
702-
703- // This is required to avoid an unstable error when `restricted-std` is not
704- // enabled. The use of #![feature(restricted_std)] in rustc-std-workspace-std
705- // is unconditional, so the unstable feature needs to be defined somewhere.
706- #[ unstable( feature = "restricted_std" , issue = "none" ) ]
707- mod __restricted_std_workaround { }
708-
709- mod sealed {
710- /// This trait being unreachable from outside the crate
711- /// prevents outside implementations of our extension traits.
712- /// This allows adding more trait methods in the future.
713- #[ unstable( feature = "sealed" , issue = "none" ) ]
714- pub trait Sealed { }
715- }
716-
717- #[ cfg( test) ]
718- #[ allow( dead_code) ] // Not used in all configurations.
719- pub ( crate ) mod test_helpers {
720- /// Test-only replacement for `rand::thread_rng()`, which is unusable for
721- /// us, as we want to allow running stdlib tests on tier-3 targets which may
722- /// not have `getrandom` support.
723- ///
724- /// Does a bit of a song and dance to ensure that the seed is different on
725- /// each call (as some tests sadly rely on this), but doesn't try that hard.
726- ///
727- /// This is duplicated in the `core`, `alloc` test suites (as well as
728- /// `std`'s integration tests), but figuring out a mechanism to share these
729- /// seems far more painful than copy-pasting a 7 line function a couple
730- /// times, given that even under a perma-unstable feature, I don't think we
731- /// want to expose types from `rand` from `std`.
732- #[ track_caller]
733- pub ( crate ) fn test_rng ( ) -> rand_xorshift:: XorShiftRng {
734- use core:: hash:: { BuildHasher , Hash , Hasher } ;
735- let mut hasher = crate :: hash:: RandomState :: new ( ) . build_hasher ( ) ;
736- core:: panic:: Location :: caller ( ) . hash ( & mut hasher) ;
737- let hc64 = hasher. finish ( ) ;
738- let seed_vec = hc64. to_le_bytes ( ) . into_iter ( ) . chain ( 0u8 ..8 ) . collect :: < Vec < u8 > > ( ) ;
739- let seed: [ u8 ; 16 ] = seed_vec. as_slice ( ) . try_into ( ) . unwrap ( ) ;
740- rand:: SeedableRng :: from_seed ( seed)
741- }
742- }
498+ #[ cfg( not( all( feature = "miri-test" , not( any( test, doctest) ) ) ) ) ]
499+ include ! ( "lib_.rs" ) ;
0 commit comments