Skip to content

Commit ea538d2

Browse files
INTERIM: Macros instead of const for global COOP defaults.
1 parent adfb416 commit ea538d2

File tree

15 files changed

+80
-36
lines changed

15 files changed

+80
-36
lines changed

library/alloc/src/boxed.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@
146146
147147
#![stable(feature = "rust1", since = "1.0.0")]
148148

149-
use core::alloc;
150149
use core::any::Any;
151150
use core::async_iter::AsyncIterator;
152151
use core::borrow;
@@ -776,9 +775,10 @@ where
776775
#[unstable(feature = "allocator_api", issue = "32838")]
777776
// #[unstable(feature = "new_uninit", issue = "63291")]
778777
#[must_use]
778+
#[allow(unused_braces)]
779779
pub fn new_uninit_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit<T>], A> {
780780
unsafe {
781-
RawVec::<T, A, { alloc::SHORT_TERM_VEC_PREFERS_COOP }>::with_capacity_in(len, alloc)
781+
RawVec::<T, A, { SHORT_TERM_VEC_PREFERS_COOP!() }>::with_capacity_in(len, alloc)
782782
.into_box(len)
783783
}
784784
}
@@ -807,9 +807,10 @@ where
807807
#[unstable(feature = "allocator_api", issue = "32838")]
808808
// #[unstable(feature = "new_uninit", issue = "63291")]
809809
#[must_use]
810+
#[allow(unused_braces)]
810811
pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit<T>], A> {
811812
unsafe {
812-
RawVec::<T, A, { alloc::SHORT_TERM_VEC_PREFERS_COOP }>::with_capacity_zeroed_in(
813+
RawVec::<T, A, { SHORT_TERM_VEC_PREFERS_COOP!() }>::with_capacity_zeroed_in(
813814
len, alloc,
814815
)
815816
.into_box(len)

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,14 @@ use core::mem::{self, swap, ManuallyDrop};
148148
use core::num::NonZeroUsize;
149149
use core::ops::{Deref, DerefMut};
150150
use core::ptr;
151-
use core::{alloc, fmt};
151+
use core::fmt;
152152

153153
use crate::alloc::Global;
154154

155155
use crate::collections::TryReserveError;
156156
use crate::slice;
157157
use crate::vec::{self, AsVecIntoIter, Vec};
158+
use crate::DEFAULT_COOP_PREFERRED;
158159

159160
use super::SpecExtend;
160161

@@ -1243,7 +1244,8 @@ impl<T> BinaryHeap<T> {
12431244
/// ```
12441245
#[inline]
12451246
#[stable(feature = "drain", since = "1.6.0")]
1246-
pub fn drain(&mut self) -> Drain<'_, T, { alloc::SHORT_TERM_VEC_PREFERS_COOP }> {
1247+
#[allow(unused_braces)]
1248+
pub fn drain(&mut self) -> Drain<'_, T, { SHORT_TERM_VEC_PREFERS_COOP!() }> {
12471249
Drain { iter: self.data.drain(..) }
12481250
}
12491251

@@ -1652,7 +1654,8 @@ impl<T: Ord, const N: usize> From<[T; N]> for BinaryHeap<T> {
16521654
}
16531655

16541656
#[stable(feature = "binary_heap_extras_15", since = "1.5.0")]
1655-
impl<T> From<BinaryHeap<T>> for Vec<T, Global, DEFAULT_COOP_PREFERRED> {
1657+
#[allow(unused_braces)]
1658+
impl<T> From<BinaryHeap<T>> for Vec<T, Global, {DEFAULT_COOP_PREFERRED!()}> {
16561659
/// Converts a `BinaryHeap<T>` into a `Vec<T>`.
16571660
///
16581661
/// This conversion requires no data movement or allocation, and has

library/alloc/src/collections/vec_deque/drain.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ use super::VecDeque;
1515
///
1616
/// [`drain`]: VecDeque::drain
1717
#[stable(feature = "drain", since = "1.6.0")]
18+
#[allow(unused_braces)]
1819
pub struct Drain<
1920
'a,
2021
T: 'a,
2122
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
22-
const COOP_PREFERRED: bool = { alloc::SHORT_TERM_VEC_PREFERS_COOP },
23+
const COOP_PREFERRED: bool = { SHORT_TERM_VEC_PREFERS_COOP!() },
2324
> where
2425
[(); alloc::co_alloc_metadata_num_slots_with_preference_specific::<A>(COOP_PREFERRED)]:,
2526
{

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
#![feature(global_co_alloc)]
99
#![stable(feature = "rust1", since = "1.0.0")]
10-
use crate::vec::DEFAULT_COOP_PREFERRED;
10+
use crate::DEFAULT_COOP_PREFERRED;
1111
use core::alloc;
1212
use core::cmp::{self, Ordering};
1313
use core::fmt;
@@ -93,10 +93,11 @@ mod tests;
9393
#[cfg_attr(not(test), rustc_diagnostic_item = "VecDeque")]
9494
#[stable(feature = "rust1", since = "1.0.0")]
9595
#[rustc_insignificant_dtor]
96+
#[allow(unused_braces)]
9697
pub struct VecDeque<
9798
T,
9899
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
99-
const COOP_PREFERRED: bool = DEFAULT_COOP_PREFERRED,
100+
const COOP_PREFERRED: bool = {DEFAULT_COOP_PREFERRED!()},
100101
> where
101102
[(); alloc::co_alloc_metadata_num_slots_with_preference_specific::<A>(COOP_PREFERRED)]:,
102103
{

library/alloc/src/ffi/c_str.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ use core::ptr;
1717
use core::slice;
1818
use core::slice::memchr;
1919
use core::str::{self, Utf8Error};
20+
use crate::Global;
21+
use crate::DEFAULT_COOP_PREFERRED;
2022

2123
#[cfg(target_has_atomic = "ptr")]
2224
use crate::sync::Arc;
@@ -723,7 +725,8 @@ impl fmt::Debug for CString {
723725
}
724726

725727
#[stable(feature = "cstring_into", since = "1.7.0")]
726-
impl From<CString> for Vec<u8, Global, DEFAULT_COOP_PREFERRED> {
728+
#[allow(unused_braces)]
729+
impl From<CString> for Vec<u8, Global, {DEFAULT_COOP_PREFERRED!()}> {
727730
/// Converts a [`CString`] into a <code>[Vec]<[u8]></code>.
728731
///
729732
/// The conversion consumes the [`CString`], and removes the terminating NUL byte.

library/alloc/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@
185185
#![feature(global_co_alloc_short_term_pref)]
186186
#![feature(hashmap_internals)]
187187
#![feature(lang_items)]
188+
#![feature(global_co_alloc_def)]
188189
// When we used min_specialization instead of specialization, library/alloc/src/vec/mod.rs was failing with:
189190
// - cannot specialize on predicate `the constant `core::alloc::co_alloc_metadata_num_slots::<A>()` can be evaluated`
190191
// - cannot specialize on predicate `[(); _] well-formed`

library/alloc/src/raw_vec.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::alloc::{Allocator, Global, Layout};
1414
use crate::boxed::Box;
1515
use crate::collections::TryReserveError;
1616
use crate::collections::TryReserveErrorKind::*;
17-
use crate::vec::DEFAULT_COOP_PREFERRED;
17+
use crate::DEFAULT_COOP_PREFERRED;
1818

1919
#[cfg(test)]
2020
mod tests;
@@ -50,10 +50,11 @@ enum AllocInit {
5050
/// `usize::MAX`. This means that you need to be careful when round-tripping this type with a
5151
/// `Box<[T]>`, since `capacity()` won't yield the length.
5252
#[allow(missing_debug_implementations)]
53+
#[allow(unused_braces)]
5354
pub(crate) struct RawVec<
5455
T,
5556
A: Allocator = Global,
56-
const COOP_PREFERRED: bool = DEFAULT_COOP_PREFERRED,
57+
const COOP_PREFERRED: bool = {DEFAULT_COOP_PREFERRED!()},
5758
> where
5859
[(); alloc::co_alloc_metadata_num_slots_with_preference_specific::<A>(COOP_PREFERRED)]:,
5960
{

library/alloc/src/string.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ use crate::str::{self, from_utf8_unchecked_mut, Chars, Utf8Error};
7575
#[cfg(not(no_global_oom_handling))]
7676
use crate::str::{from_boxed_utf8_unchecked, FromStr};
7777
use crate::vec::Vec;
78-
use crate::vec::DEFAULT_COOP_PREFERRED;
78+
use crate::DEFAULT_COOP_PREFERRED;
7979

8080
/// A UTF-8–encoded, growable string.
8181
///
@@ -369,7 +369,8 @@ use crate::vec::DEFAULT_COOP_PREFERRED;
369369
#[derive(PartialOrd, Eq, Ord)]
370370
#[stable(feature = "rust1", since = "1.0.0")]
371371
#[cfg_attr(not(test), lang = "String")]
372-
pub struct String<const COOP_PREFERRED: bool = DEFAULT_COOP_PREFERRED>
372+
#[allow(unused_braces)]
373+
pub struct String<const COOP_PREFERRED: bool = {DEFAULT_COOP_PREFERRED!()}>
373374
where
374375
[(); crate::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:,
375376
{
@@ -2639,7 +2640,8 @@ where
26392640
/// [`Display`]: fmt::Display
26402641
#[cfg_attr(not(test), rustc_diagnostic_item = "ToString")]
26412642
#[stable(feature = "rust1", since = "1.0.0")]
2642-
pub trait ToString<const COOP_PREFERRED: bool = DEFAULT_COOP_PREFERRED>
2643+
#[allow(unused_braces)]
2644+
pub trait ToString<const COOP_PREFERRED: bool = {DEFAULT_COOP_PREFERRED!()}>
26432645
where
26442646
[(); crate::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:,
26452647
{
@@ -3088,7 +3090,8 @@ where
30883090
///
30893091
/// [`drain`]: String::drain
30903092
#[stable(feature = "drain", since = "1.6.0")]
3091-
pub struct Drain<'a, const COOP_PREFERRED: bool = DEFAULT_COOP_PREFERRED>
3093+
#[allow(unused_braces)]
3094+
pub struct Drain<'a, const COOP_PREFERRED: bool = {DEFAULT_COOP_PREFERRED!()}>
30923095
where
30933096
[(); crate::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:,
30943097
{

library/alloc/src/vec/drain.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ use super::Vec;
1919
/// let iter: std::vec::Drain<_> = v.drain(..);
2020
/// ```
2121
#[stable(feature = "drain", since = "1.6.0")]
22+
#[allow(unused_braces)]
2223
pub struct Drain<
2324
'a,
2425
T: 'a,
2526
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + 'a = Global,
26-
const COOP_PREFERRED: bool = { alloc::SHORT_TERM_VEC_PREFERS_COOP },
27+
const COOP_PREFERRED: bool = { SHORT_TERM_VEC_PREFERS_COOP!() },
2728
> where
2829
[(); alloc::co_alloc_metadata_num_slots_with_preference_specific::<A>(COOP_PREFERRED)]:,
2930
{

library/alloc/src/vec/in_place_collect.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ use core::iter::{InPlaceIterable, SourceIter, TrustedRandomAccessNoCoerce};
141141
use core::mem::{self, ManuallyDrop, SizedTypeProperties};
142142
use core::ptr::{self};
143143

144+
use crate::Global;
145+
use crate::DEFAULT_COOP_PREFERRED;
146+
144147
use super::{InPlaceDrop, InPlaceDstBufDrop, SpecFromIter, SpecFromIterNested, Vec};
145148

146149
/// Specialization marker for collecting an iterator pipeline into a Vec while reusing the
@@ -150,7 +153,8 @@ pub(super) trait InPlaceIterableMarker {}
150153

151154
impl<T> InPlaceIterableMarker for T where T: InPlaceIterable {}
152155

153-
impl<T, I> SpecFromIter<T, I> for Vec<T, Global, DEFAULT_COOP_PREFERRED>
156+
#[allow(unused_braces)]
157+
impl<T, I> SpecFromIter<T, I> for Vec<T, Global, {DEFAULT_COOP_PREFERRED!()}>
154158
where
155159
I: Iterator<Item = T> + SourceIter<Source: AsVecIntoIter> + InPlaceIterableMarker,
156160
{

0 commit comments

Comments
 (0)