Skip to content

Commit 8f1c7c3

Browse files
committed
Fully test the alloc crate through alloctests
For the tests that make use of internal implementation details, we include the module to test using #[path] in alloctests now.
1 parent f721090 commit 8f1c7c3

28 files changed

+232
-311
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" }
1919
-compiler_builtins = { version = "=0.1.145", features = ['rustc-dep-of-std'] }
2020
+compiler_builtins = { version = "=0.1.145", 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

-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]]

library/alloc/Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ autotests = false
88
autobenches = false
99
edition = "2021"
1010

11+
[lib]
12+
test = false
13+
bench = false
14+
1115
[dependencies]
1216
core = { path = "../core" }
1317
compiler_builtins = { version = "=0.1.145", features = ['rustc-dep-of-std'] }
1418

15-
[dev-dependencies]
16-
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }
17-
rand_xorshift = "0.3.0"
18-
1919
[features]
2020
compiler-builtins-mem = ['compiler_builtins/mem']
2121
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
extern "Rust" {
@@ -44,14 +42,10 @@ 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
@@ -340,7 +332,7 @@ unsafe impl Allocator for Global {
340332
}
341333

342334
/// The allocator for `Box`.
343-
#[cfg(all(not(no_global_oom_handling), not(test)))]
335+
#[cfg(not(no_global_oom_handling))]
344336
#[lang = "exchange_malloc"]
345337
#[inline]
346338
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
@@ -389,7 +381,7 @@ extern "Rust" {
389381
/// [no_std]: https://doc.rust-lang.org/reference/names/preludes.html#the-no_std-attribute
390382
#[stable(feature = "global_alloc", since = "1.28.0")]
391383
#[rustc_const_unstable(feature = "const_alloc_error", issue = "92523")]
392-
#[cfg(all(not(no_global_oom_handling), not(test)))]
384+
#[cfg(not(no_global_oom_handling))]
393385
#[cold]
394386
#[optimize(size)]
395387
pub const fn handle_alloc_error(layout: Layout) -> ! {
@@ -413,11 +405,7 @@ pub const fn handle_alloc_error(layout: Layout) -> ! {
413405
ct_error(layout)
414406
}
415407

416-
// For alloc test `std::alloc::handle_alloc_error` can be used directly.
417-
#[cfg(all(not(no_global_oom_handling), test))]
418-
pub use std::alloc::handle_alloc_error;
419-
420-
#[cfg(all(not(no_global_oom_handling), not(test)))]
408+
#[cfg(not(no_global_oom_handling))]
421409
#[doc(hidden)]
422410
#[allow(unused_attributes)]
423411
#[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)