414
414
//
415
415
#![ default_lib_allocator]
416
416
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. Everything that follows should have
429
+ // `#[cfg(not(all(feature = "miri-test", not(any(test, doctest)))))]`. To avoid having to repeat the
430
+ // same `cfg` so many times, we `include!("lib_.rs")` with the main crate contents, and `cfg` the
431
+ // `include!`. However, some macro-related things can't be behind the `include!` so we have to
432
+ // repeat the `cfg` for them.
433
+
417
434
// Explicitly import the prelude. The compiler uses this same unstable attribute
418
435
// to import the prelude implicitly when building crates that depend on std.
436
+ #[ cfg( not( all( feature = "miri-test" , not( any( test, doctest) ) ) ) ) ]
419
437
#[ prelude_import]
420
438
#[ allow( unused) ]
421
439
use prelude:: rust_2021:: * ;
@@ -424,14 +442,17 @@ use prelude::rust_2021::*;
424
442
#[ cfg( test) ]
425
443
extern crate test;
426
444
445
+ #[ cfg( not( all( feature = "miri-test" , not( any( test, doctest) ) ) ) ) ]
427
446
#[ allow( unused_imports) ] // macros from `alloc` are not used on all platforms
428
447
#[ macro_use]
429
448
extern crate alloc as alloc_crate;
449
+ #[ cfg( not( all( feature = "miri-test" , not( any( test, doctest) ) ) ) ) ]
430
450
#[ doc( masked) ]
431
451
#[ allow( unused_extern_crates) ]
432
452
extern crate libc;
433
453
434
454
// We always need an unwinder currently for backtraces
455
+ #[ cfg( not( all( feature = "miri-test" , not( any( test, doctest) ) ) ) ) ]
435
456
#[ doc( masked) ]
436
457
#[ allow( unused_extern_crates) ]
437
458
extern crate unwind;
@@ -441,6 +462,7 @@ extern crate unwind;
441
462
// Remove exclusion from tidy platform check when this removed.
442
463
#[ doc( masked) ]
443
464
#[ allow( unused_extern_crates) ]
465
+ #[ cfg( not( all( feature = "miri-test" , not( any( test, doctest) ) ) ) ) ]
444
466
#[ cfg( all(
445
467
not( all( windows, target_env = "msvc" , not( target_vendor = "uwp" ) ) ) ,
446
468
feature = "miniz_oxide"
@@ -457,286 +479,23 @@ extern crate miniz_oxide;
457
479
extern crate std as realstd;
458
480
459
481
// The standard macros that are not built-in to the compiler.
482
+ #[ cfg( not( all( feature = "miri-test" , not( any( test, doctest) ) ) ) ) ]
460
483
#[ macro_use]
461
484
mod macros;
462
485
463
486
// The runtime entry point and a few unstable public functions used by the
464
487
// compiler
488
+ #[ cfg( not( all( feature = "miri-test" , not( any( test, doctest) ) ) ) ) ]
465
489
#[ macro_use]
466
490
pub mod rt;
467
491
468
492
// The Rust prelude
493
+ #[ cfg( not( all( feature = "miri-test" , not( any( test, doctest) ) ) ) ) ]
469
494
pub mod prelude;
470
495
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
-
496
+ #[ cfg( not( all( feature = "miri-test" , not( any( test, doctest) ) ) ) ) ]
570
497
#[ macro_use]
571
498
pub 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;
653
499
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
- }
500
+ #[ cfg( not( all( feature = "miri-test" , not( any( test, doctest) ) ) ) ) ]
501
+ include ! ( "lib_.rs" ) ;
0 commit comments