72
72
not( test) ,
73
73
not( any( test, bootstrap) ) ,
74
74
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) ) ) ) ,
75
77
no_global_oom_handling,
76
78
not( no_global_oom_handling) ,
77
79
not( no_rc) ,
217
219
// from other crates, but since this can only appear for lang items, it doesn't seem worth fixing.
218
220
#![ feature( intra_doc_pointers) ]
219
221
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. Everything that follows should have
234
+ // `#[cfg(not(all(feature = "miri-test", not(any(test, doctest)))))]`. To avoid having to repeat the
235
+ // same `cfg` so many times, we `include!("lib_.rs")` with the main crate contents, and `cfg` the
236
+ // `include!`. However, some macro-related things can't be behind the `include!` so we have to
237
+ // repeat the `cfg` for them.
238
+
239
+ // Module with internal macros used by other modules (needs to be included before other modules).
240
+ #[ cfg( not( all( feature = "miri-test" , not( any( test, doctest) ) ) ) ) ]
241
+ #[ macro_use]
242
+ mod macros;
243
+
220
244
// Allow testing this library
221
245
#[ cfg( test) ]
222
246
#[ macro_use]
@@ -226,64 +250,5 @@ extern crate test;
226
250
#[ cfg( test) ]
227
251
mod testing;
228
252
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
- }
253
+ #[ cfg( not( all( feature = "miri-test" , not( any( test, doctest) ) ) ) ) ]
254
+ include ! ( "lib_.rs" ) ;
0 commit comments