Skip to content

Commit 1ed03a2

Browse files
committed
restrict libs test to not(bootstrap)
1 parent 3fbed98 commit 1ed03a2

File tree

4 files changed

+32
-39
lines changed

4 files changed

+32
-39
lines changed

library/core/src/array/mod.rs

+15-26
Original file line numberDiff line numberDiff line change
@@ -391,36 +391,25 @@ mod array_defaults {
391391

392392
#[cfg(not(bootstrap))]
393393
mod array_defaults {
394-
// We use auto traits to get overlapping impls without relying on nightly features.
395-
//
396-
// As the auto impl for `SendToDefault` is only considered if the manual impl does not apply,
397-
// we have to use the generic impl for `T: Default` as the impl for the `N = 0` case would
398-
// influence type inference in undesirable ways.
399-
//
400-
// While we are now able to implement `Default` exactly for the array types we want,
401-
// we're still not able to actually write the body of the `Default` function without
402-
// some further hacks.
403-
//
404-
// The idea here is that `array_default_hack` is resolved to itself only if `N = 0`
405-
// and is otherwise replaced with `T::default()`.
406-
//
407-
// This would cause issues if `T` doesn't actually implement default but as this function
408-
// is private and only used in the default impl itself this can not happen.
409-
410-
struct ZeroToSend<T, const N: usize>(*mut (), T);
411-
unsafe impl<T> Send for ZeroToSend<T, 0> {}
412-
413-
/// This struct implements `Send` either because of the manual impl for `N` is `0` or
414-
/// because all its fields implement `Send`, which is the case if `T` implements `Default`.
394+
#[marker]
415395
#[unstable(
416396
feature = "array_default_impl",
417397
issue = "none",
418398
reason = "internal implementation detail for `[T; N]: Default`"
419399
)]
420-
#[allow(missing_debug_implementations)]
421-
pub struct SendToDefault<T, const N: usize>(ZeroToSend<T, N>);
422-
#[unstable(feature = "array_default_impl", issue = "none")]
423-
unsafe impl<T: Default, const N: usize> Send for SendToDefault<T, N> {}
400+
pub trait ArrayDefault {}
401+
#[unstable(
402+
feature = "array_default_impl",
403+
issue = "none",
404+
reason = "internal implementation detail for `[T; N]: Default`"
405+
)]
406+
impl<T: Default, const N: usize> ArrayDefault for [T; N] {}
407+
#[unstable(
408+
feature = "array_default_impl",
409+
issue = "none",
410+
reason = "internal implementation detail for `[T; N]: Default`"
411+
)]
412+
impl<T> ArrayDefault for [T; 0] {}
424413

425414
// This function must not get called for `N != 0` if `T` does not implement `Default`.
426415
#[lang = "array_default_hack"]
@@ -431,7 +420,7 @@ mod array_defaults {
431420
#[stable(since = "1.4.0", feature = "array_default")]
432421
impl<T, const N: usize> Default for [T; N]
433422
where
434-
SendToDefault<T, N>: Send,
423+
[T; N]: ArrayDefault,
435424
{
436425
fn default() -> [T; N] {
437426
// SAFETY: The only case where `T` does not implement `Default` is

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
#![feature(rustc_attrs)]
134134
#![feature(simd_ffi)]
135135
#![feature(min_specialization)]
136+
#![feature(marker_trait_attr)]
136137
#![feature(staged_api)]
137138
#![feature(std_internals)]
138139
#![feature(stmt_expr_attributes)]

library/core/tests/array.rs

+15-12
Original file line numberDiff line numberDiff line change
@@ -357,18 +357,21 @@ fn cell_allows_array_cycle() {
357357
b3.a[1].set(Some(&b2));
358358
}
359359

360-
fn generic_default<T: Default, const N: usize>() -> [T; N] {
361-
Default::default()
362-
}
360+
#[cfg(not(bootstrap))]
361+
mod array_defaults {
362+
fn generic_default<T: Default, const N: usize>() -> [T; N] {
363+
Default::default()
364+
}
363365

364-
#[test]
365-
fn use_generic_default() {
366-
assert_eq!(generic_default::<String, 2>(), [String::new(), String::new()]);
367-
assert_eq!(generic_default::<u8, 33>(), [0; 33]);
368-
}
366+
#[test]
367+
fn use_generic_default() {
368+
assert_eq!(generic_default::<String, 2>(), [String::new(), String::new()]);
369+
assert_eq!(generic_default::<u8, 33>(), [0; 33]);
370+
}
369371

370-
#[test]
371-
fn use_zero_default() {
372-
struct NotDefault;
373-
assert!(matches!(<[NotDefault; 0] as Default>::default(), []));
372+
#[test]
373+
fn use_zero_default() {
374+
struct NotDefault;
375+
assert!(matches!(<[NotDefault; 0] as Default>::default(), []));
376+
}
374377
}

src/test/ui/const-generics/array-impls/default-not-length-1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0277]: the trait bound `NotDefault: Default` is not satisfied
44
LL | let _: [NotDefault; 1] = Default::default();
55
| ^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `NotDefault`
66
|
7-
= note: required because of the requirements on the impl of `Send` for `array::array_defaults::SendToDefault<NotDefault, 1_usize>`
7+
= note: required because of the requirements on the impl of `array::array_defaults::ArrayDefault` for `[NotDefault; 1]`
88
= note: required because of the requirements on the impl of `Default` for `[NotDefault; 1]`
99
= note: required by `std::default::Default::default`
1010

0 commit comments

Comments
 (0)