7272 not( test) ,
7373 not( any( test, bootstrap) ) ,
7474 any( not( feature = "miri-test-libstd" ) , test, doctest) ,
75+ all( feature = "miri-test" , not( any( test, doctest) ) ) ,
76+ not( all( feature = "miri-test" , not( any( test, doctest) ) ) ) ,
7577 no_global_oom_handling,
7678 not( no_global_oom_handling) ,
7779 not( no_rc) ,
217219// from other crates, but since this can only appear for lang items, it doesn't seem worth fixing.
218220#![ feature( intra_doc_pointers) ]
219221
222+ // We want to be able to `cargo miri test` this crate, but that's tricky.
223+ // We use the `miri-test` feature to indicate that we're running `cargo miri test`, and
224+ // with that feature we turn this crate into a re-export of the sysroot crate. We only do this when
225+ // building the crate that will become a dependency, not when doing the actual (doc)test build.
226+ // See `core/src/lib.rs` for more information.
227+ #[ cfg( all( feature = "miri-test" , not( any( test, doctest) ) ) ) ]
228+ extern crate alloc as realalloc;
229+ #[ cfg( all( feature = "miri-test" , not( any( test, doctest) ) ) ) ]
230+ #[ stable( feature = "miri_test" , since = "1.0.0" ) ]
231+ pub use realalloc:: * ;
232+
233+ // Otherwise, we build the crate as usual. To avoid having to repeat the same `cfg` so many times,
234+ // we `include!("lib_.rs")` with the main crate contents, and `cfg` the `include!`. However, some
235+ // macro-related things can't be behind the `include!` so we have to repeat the `cfg` for them.
236+
237+ // Module with internal macros used by other modules (needs to be included before other modules).
238+ #[ cfg( not( all( feature = "miri-test" , not( any( test, doctest) ) ) ) ) ]
239+ #[ macro_use]
240+ mod macros;
241+
220242// Allow testing this library
221243#[ cfg( test) ]
222244#[ macro_use]
@@ -226,64 +248,5 @@ extern crate test;
226248#[ cfg( test) ]
227249mod testing;
228250
229- // Module with internal macros used by other modules (needs to be included before other modules).
230- #[ macro_use]
231- mod macros;
232-
233- mod raw_vec;
234-
235- // Heaps provided for low-level allocation strategies
236-
237- pub mod alloc;
238-
239- // Primitive types using the heaps above
240-
241- // Need to conditionally define the mod from `boxed.rs` to avoid
242- // duplicating the lang-items when building in test cfg; but also need
243- // to allow code to have `use boxed::Box;` declarations.
244- #[ cfg( not( test) ) ]
245- pub mod boxed;
246- #[ cfg( test) ]
247- mod boxed {
248- pub use std:: boxed:: Box ;
249- }
250- pub mod borrow;
251- pub mod collections;
252- #[ cfg( all( not( no_rc) , not( no_sync) , not( no_global_oom_handling) ) ) ]
253- pub mod ffi;
254- pub mod fmt;
255- #[ cfg( not( no_rc) ) ]
256- pub mod rc;
257- pub mod slice;
258- pub mod str;
259- pub mod string;
260- #[ cfg( all( not( no_rc) , not( no_sync) , target_has_atomic = "ptr" ) ) ]
261- pub mod sync;
262- #[ cfg( all( not( no_global_oom_handling) , not( no_rc) , not( no_sync) ) ) ]
263- pub mod task;
264- #[ cfg( test) ]
265- mod tests;
266- pub mod vec;
267-
268- #[ doc( hidden) ]
269- #[ unstable( feature = "liballoc_internals" , issue = "none" , reason = "implementation detail" ) ]
270- pub mod __export {
271- pub use core:: format_args;
272- }
273-
274- #[ cfg( test) ]
275- #[ allow( dead_code) ] // Not used in all configurations
276- pub ( crate ) mod test_helpers {
277- /// Copied from `std::test_helpers::test_rng`, since these tests rely on the
278- /// seed not being the same for every RNG invocation too.
279- pub ( crate ) fn test_rng ( ) -> rand_xorshift:: XorShiftRng {
280- use std:: hash:: { BuildHasher , Hash , Hasher } ;
281- let mut hasher = std:: hash:: RandomState :: new ( ) . build_hasher ( ) ;
282- std:: panic:: Location :: caller ( ) . hash ( & mut hasher) ;
283- let hc64 = hasher. finish ( ) ;
284- let seed_vec =
285- hc64. to_le_bytes ( ) . into_iter ( ) . chain ( 0u8 ..8 ) . collect :: < crate :: vec:: Vec < u8 > > ( ) ;
286- let seed: [ u8 ; 16 ] = seed_vec. as_slice ( ) . try_into ( ) . unwrap ( ) ;
287- rand:: SeedableRng :: from_seed ( seed)
288- }
289- }
251+ #[ cfg( not( all( feature = "miri-test" , not( any( test, doctest) ) ) ) ) ]
252+ include ! ( "lib_.rs" ) ;
0 commit comments