Skip to content

Commit 7befc24

Browse files
authored
Unrolled build for rust-lang#136642
Rollup merge of rust-lang#136642 - bjorn3:separate_alloctest_crate, r=cuviper Put the alloc unit tests in a separate alloctests package Same rationale as rust-lang#135937. This PR has some extra complexity though as a decent amount of tests are testing internal implementation details rather than the public api. As such I opted to include the modules containing the types under test using `#[path]` into the alloctests package. This means that those modules still need `#[cfg(test)]`, but the rest of liballoc no longer need it.
2 parents cdd8af2 + 22d0440 commit 7befc24

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+579
-603
lines changed

compiler/rustc_codegen_cranelift/patches/0029-stdlib-Disable-f16-and-f128-in-compiler-builtins.patch

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ index 7165c3e48af..968552ad435 100644
1212
--- a/library/alloc/Cargo.toml
1313
+++ b/library/alloc/Cargo.toml
1414
@@ -11,7 +11,7 @@ test = { path = "../test" }
15-
edition = "2021"
15+
bench = false
1616

1717
[dependencies]
1818
core = { path = "../core", public = true }
1919
-compiler_builtins = { version = "=0.1.151", features = ['rustc-dep-of-std'] }
2020
+compiler_builtins = { version = "=0.1.151", features = ['rustc-dep-of-std', 'no-f16-f128'] }
2121

22-
[dev-dependencies]
23-
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }
22+
[features]
23+
compiler-builtins-mem = ['compiler_builtins/mem']
2424
--
2525
2.34.1
2626

library/Cargo.lock

+8-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ version = "0.0.0"
3030
dependencies = [
3131
"compiler_builtins",
3232
"core",
33-
"rand",
34-
"rand_xorshift",
3533
]
3634

3735
[[package]]
@@ -40,6 +38,14 @@ version = "0.2.21"
4038
source = "registry+https://github.com/rust-lang/crates.io-index"
4139
checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
4240

41+
[[package]]
42+
name = "alloctests"
43+
version = "0.0.0"
44+
dependencies = [
45+
"rand",
46+
"rand_xorshift",
47+
]
48+
4349
[[package]]
4450
name = "cc"
4551
version = "1.2.0"

library/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ members = [
44
"std",
55
"sysroot",
66
"coretests",
7+
"alloctests",
78
]
89

910
exclude = [

library/alloc/Cargo.toml

+4-22
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,14 @@ autotests = false
1010
autobenches = false
1111
edition = "2021"
1212

13+
[lib]
14+
test = false
15+
bench = false
16+
1317
[dependencies]
1418
core = { path = "../core", public = true }
1519
compiler_builtins = { version = "=0.1.151", features = ['rustc-dep-of-std'] }
1620

17-
[dev-dependencies]
18-
rand = { version = "0.9.0", default-features = false, features = ["alloc"] }
19-
rand_xorshift = "0.4.0"
20-
21-
[[test]]
22-
name = "alloctests"
23-
path = "tests/lib.rs"
24-
25-
[[test]]
26-
name = "vec_deque_alloc_error"
27-
path = "tests/vec_deque_alloc_error.rs"
28-
29-
[[bench]]
30-
name = "allocbenches"
31-
path = "benches/lib.rs"
32-
test = true
33-
34-
[[bench]]
35-
name = "vec_deque_append_bench"
36-
path = "benches/vec_deque_append.rs"
37-
harness = false
38-
3921
[features]
4022
compiler-builtins-mem = ['compiler_builtins/mem']
4123
compiler-builtins-c = ["compiler_builtins/c"]

library/alloc/src/alloc.rs

+3-15
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
#[stable(feature = "alloc_module", since = "1.28.0")]
66
#[doc(inline)]
77
pub use core::alloc::*;
8-
#[cfg(not(test))]
98
use core::hint;
10-
#[cfg(not(test))]
119
use core::ptr::{self, NonNull};
1210

1311
unsafe extern "Rust" {
@@ -44,14 +42,10 @@ unsafe extern "Rust" {
4442
/// accessed through the [free functions in `alloc`](self#functions).
4543
#[unstable(feature = "allocator_api", issue = "32838")]
4644
#[derive(Copy, Clone, Default, Debug)]
47-
#[cfg(not(test))]
4845
// the compiler needs to know when a Box uses the global allocator vs a custom one
4946
#[lang = "global_alloc_ty"]
5047
pub struct Global;
5148

52-
#[cfg(test)]
53-
pub use std::alloc::Global;
54-
5549
/// Allocates memory with the global allocator.
5650
///
5751
/// This function forwards calls to the [`GlobalAlloc::alloc`] method
@@ -180,7 +174,6 @@ pub unsafe fn alloc_zeroed(layout: Layout) -> *mut u8 {
180174
}
181175
}
182176

183-
#[cfg(not(test))]
184177
impl Global {
185178
#[inline]
186179
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
@@ -246,7 +239,6 @@ impl Global {
246239
}
247240

248241
#[unstable(feature = "allocator_api", issue = "32838")]
249-
#[cfg(not(test))]
250242
unsafe impl Allocator for Global {
251243
#[inline]
252244
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
@@ -346,7 +338,7 @@ unsafe impl Allocator for Global {
346338
}
347339

348340
/// The allocator for `Box`.
349-
#[cfg(all(not(no_global_oom_handling), not(test)))]
341+
#[cfg(not(no_global_oom_handling))]
350342
#[lang = "exchange_malloc"]
351343
#[inline]
352344
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
@@ -395,7 +387,7 @@ unsafe extern "Rust" {
395387
/// [no_std]: https://doc.rust-lang.org/reference/names/preludes.html#the-no_std-attribute
396388
#[stable(feature = "global_alloc", since = "1.28.0")]
397389
#[rustc_const_unstable(feature = "const_alloc_error", issue = "92523")]
398-
#[cfg(all(not(no_global_oom_handling), not(test)))]
390+
#[cfg(not(no_global_oom_handling))]
399391
#[cold]
400392
#[optimize(size)]
401393
pub const fn handle_alloc_error(layout: Layout) -> ! {
@@ -419,11 +411,7 @@ pub const fn handle_alloc_error(layout: Layout) -> ! {
419411
ct_error(layout)
420412
}
421413

422-
// For alloc test `std::alloc::handle_alloc_error` can be used directly.
423-
#[cfg(all(not(no_global_oom_handling), test))]
424-
pub use std::alloc::handle_alloc_error;
425-
426-
#[cfg(all(not(no_global_oom_handling), not(test)))]
414+
#[cfg(not(no_global_oom_handling))]
427415
#[doc(hidden)]
428416
#[allow(unused_attributes)]
429417
#[unstable(feature = "alloc_internals", issue = "none")]

library/alloc/src/borrow.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ where
3232
/// implementing the `Clone` trait. But `Clone` works only for going from `&T`
3333
/// to `T`. The `ToOwned` trait generalizes `Clone` to construct owned data
3434
/// from any borrow of a given type.
35-
#[cfg_attr(not(test), rustc_diagnostic_item = "ToOwned")]
35+
#[rustc_diagnostic_item = "ToOwned"]
3636
#[stable(feature = "rust1", since = "1.0.0")]
3737
pub trait ToOwned {
3838
/// The resulting type after obtaining ownership.
@@ -54,7 +54,7 @@ pub trait ToOwned {
5454
/// ```
5555
#[stable(feature = "rust1", since = "1.0.0")]
5656
#[must_use = "cloning is often expensive and is not expected to have side effects"]
57-
#[cfg_attr(not(test), rustc_diagnostic_item = "to_owned_method")]
57+
#[rustc_diagnostic_item = "to_owned_method"]
5858
fn to_owned(&self) -> Self::Owned;
5959

6060
/// Uses borrowed data to replace owned data, usually by cloning.
@@ -175,7 +175,7 @@ where
175175
/// }
176176
/// ```
177177
#[stable(feature = "rust1", since = "1.0.0")]
178-
#[cfg_attr(not(test), rustc_diagnostic_item = "Cow")]
178+
#[rustc_diagnostic_item = "Cow"]
179179
pub enum Cow<'a, B: ?Sized + 'a>
180180
where
181181
B: ToOwned,

library/alloc/src/bstr.rs

-20
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@ use core::ops::{
1212
Deref, DerefMut, DerefPure, Index, IndexMut, Range, RangeFrom, RangeFull, RangeInclusive,
1313
RangeTo, RangeToInclusive,
1414
};
15-
#[cfg(not(test))] // https://github.com/rust-lang/rust/issues/135100
1615
use core::str::FromStr;
1716
use core::{fmt, hash};
1817

19-
#[cfg(not(test))] // https://github.com/rust-lang/rust/issues/135100
2018
use crate::borrow::{Cow, ToOwned};
21-
#[cfg(not(test))] // https://github.com/rust-lang/rust/issues/135100
2219
use crate::boxed::Box;
2320
#[cfg(not(no_rc))]
2421
use crate::rc::Rc;
@@ -181,7 +178,6 @@ impl Default for ByteString {
181178

182179
// Omitted due to inference failures
183180
//
184-
// #[cfg(not(test))] // https://github.com/rust-lang/rust/issues/135100
185181
// #[unstable(feature = "bstr", issue = "134915")]
186182
// impl<'a, const N: usize> From<&'a [u8; N]> for ByteString {
187183
// #[inline]
@@ -190,7 +186,6 @@ impl Default for ByteString {
190186
// }
191187
// }
192188
//
193-
// #[cfg(not(test))] // https://github.com/rust-lang/rust/issues/135100
194189
// #[unstable(feature = "bstr", issue = "134915")]
195190
// impl<const N: usize> From<[u8; N]> for ByteString {
196191
// #[inline]
@@ -199,7 +194,6 @@ impl Default for ByteString {
199194
// }
200195
// }
201196
//
202-
// #[cfg(not(test))] // https://github.com/rust-lang/rust/issues/135100
203197
// #[unstable(feature = "bstr", issue = "134915")]
204198
// impl<'a> From<&'a [u8]> for ByteString {
205199
// #[inline]
@@ -226,7 +220,6 @@ impl From<ByteString> for Vec<u8> {
226220

227221
// Omitted due to inference failures
228222
//
229-
// #[cfg(not(test))] // https://github.com/rust-lang/rust/issues/135100
230223
// #[unstable(feature = "bstr", issue = "134915")]
231224
// impl<'a> From<&'a str> for ByteString {
232225
// #[inline]
@@ -243,7 +236,6 @@ impl From<ByteString> for Vec<u8> {
243236
// }
244237
// }
245238

246-
#[cfg(not(test))] // https://github.com/rust-lang/rust/issues/135100
247239
#[unstable(feature = "bstr", issue = "134915")]
248240
impl<'a> From<&'a ByteStr> for ByteString {
249241
#[inline]
@@ -252,7 +244,6 @@ impl<'a> From<&'a ByteStr> for ByteString {
252244
}
253245
}
254246

255-
#[cfg(not(test))] // https://github.com/rust-lang/rust/issues/135100
256247
#[unstable(feature = "bstr", issue = "134915")]
257248
impl<'a> From<ByteString> for Cow<'a, ByteStr> {
258249
#[inline]
@@ -261,7 +252,6 @@ impl<'a> From<ByteString> for Cow<'a, ByteStr> {
261252
}
262253
}
263254

264-
#[cfg(not(test))] // https://github.com/rust-lang/rust/issues/135100
265255
#[unstable(feature = "bstr", issue = "134915")]
266256
impl<'a> From<&'a ByteString> for Cow<'a, ByteStr> {
267257
#[inline]
@@ -330,7 +320,6 @@ impl FromIterator<ByteString> for ByteString {
330320
}
331321
}
332322

333-
#[cfg(not(test))] // https://github.com/rust-lang/rust/issues/135100
334323
#[unstable(feature = "bstr", issue = "134915")]
335324
impl FromStr for ByteString {
336325
type Err = core::convert::Infallible;
@@ -488,7 +477,6 @@ impl PartialEq for ByteString {
488477

489478
macro_rules! impl_partial_eq_ord_cow {
490479
($lhs:ty, $rhs:ty) => {
491-
#[cfg(not(test))] // https://github.com/rust-lang/rust/issues/135100
492480
#[allow(unused_lifetimes)]
493481
#[unstable(feature = "bstr", issue = "134915")]
494482
impl<'a> PartialEq<$rhs> for $lhs {
@@ -499,7 +487,6 @@ macro_rules! impl_partial_eq_ord_cow {
499487
}
500488
}
501489

502-
#[cfg(not(test))] // https://github.com/rust-lang/rust/issues/135100
503490
#[allow(unused_lifetimes)]
504491
#[unstable(feature = "bstr", issue = "134915")]
505492
impl<'a> PartialEq<$lhs> for $rhs {
@@ -510,7 +497,6 @@ macro_rules! impl_partial_eq_ord_cow {
510497
}
511498
}
512499

513-
#[cfg(not(test))] // https://github.com/rust-lang/rust/issues/135100
514500
#[allow(unused_lifetimes)]
515501
#[unstable(feature = "bstr", issue = "134915")]
516502
impl<'a> PartialOrd<$rhs> for $lhs {
@@ -521,7 +507,6 @@ macro_rules! impl_partial_eq_ord_cow {
521507
}
522508
}
523509

524-
#[cfg(not(test))] // https://github.com/rust-lang/rust/issues/135100
525510
#[allow(unused_lifetimes)]
526511
#[unstable(feature = "bstr", issue = "134915")]
527512
impl<'a> PartialOrd<$lhs> for $rhs {
@@ -572,7 +557,6 @@ impl PartialOrd for ByteString {
572557
}
573558
}
574559

575-
#[cfg(not(test))] // https://github.com/rust-lang/rust/issues/135100
576560
#[unstable(feature = "bstr", issue = "134915")]
577561
impl ToOwned for ByteStr {
578562
type Owned = ByteString;
@@ -605,7 +589,6 @@ impl<'a> TryFrom<&'a ByteString> for &'a str {
605589

606590
// Additional impls for `ByteStr` that require types from `alloc`:
607591

608-
#[cfg(not(test))] // https://github.com/rust-lang/rust/issues/135100
609592
#[unstable(feature = "bstr", issue = "134915")]
610593
impl Clone for Box<ByteStr> {
611594
#[inline]
@@ -614,7 +597,6 @@ impl Clone for Box<ByteStr> {
614597
}
615598
}
616599

617-
#[cfg(not(test))] // https://github.com/rust-lang/rust/issues/135100
618600
#[unstable(feature = "bstr", issue = "134915")]
619601
impl<'a> From<&'a ByteStr> for Cow<'a, ByteStr> {
620602
#[inline]
@@ -623,7 +605,6 @@ impl<'a> From<&'a ByteStr> for Cow<'a, ByteStr> {
623605
}
624606
}
625607

626-
#[cfg(not(test))] // https://github.com/rust-lang/rust/issues/135100
627608
#[unstable(feature = "bstr", issue = "134915")]
628609
impl From<Box<[u8]>> for Box<ByteStr> {
629610
#[inline]
@@ -633,7 +614,6 @@ impl From<Box<[u8]>> for Box<ByteStr> {
633614
}
634615
}
635616

636-
#[cfg(not(test))] // https://github.com/rust-lang/rust/issues/135100
637617
#[unstable(feature = "bstr", issue = "134915")]
638618
impl From<Box<ByteStr>> for Box<[u8]> {
639619
#[inline]

library/alloc/src/collections/binary_heap/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ use core::{fmt, ptr};
153153
use crate::alloc::Global;
154154
use crate::collections::TryReserveError;
155155
use crate::slice;
156-
use crate::vec::{self, AsVecIntoIter, Vec};
156+
#[cfg(not(test))]
157+
use crate::vec::AsVecIntoIter;
158+
use crate::vec::{self, Vec};
157159

158160
/// A priority queue implemented with a binary heap.
159161
///
@@ -1600,6 +1602,7 @@ unsafe impl<I, A: Allocator> InPlaceIterable for IntoIter<I, A> {
16001602
const MERGE_BY: Option<NonZero<usize>> = NonZero::new(1);
16011603
}
16021604

1605+
#[cfg(not(test))]
16031606
unsafe impl<I> AsVecIntoIter for IntoIter<I> {
16041607
type Item = I;
16051608

0 commit comments

Comments
 (0)