Skip to content

Commit 319b888

Browse files
CoAlloc: tidy
1 parent 08e675a commit 319b888

File tree

3 files changed

+23
-29
lines changed

3 files changed

+23
-29
lines changed

library/alloc/src/macros.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,19 @@ macro_rules! __rust_force_expr {
129129
/// This "validates" type of a given `const` expression, and it casts it. That helps to prevent mix ups with macros/integer constant values.
130130
#[doc(hidden)]
131131
#[macro_export]
132-
#[unstable(feature = "global_co_alloc_meta", issue = "none")]macro_rules! check_type_and_cast {
132+
#[unstable(feature = "global_co_alloc_meta", issue = "none")]
133+
macro_rules! check_type_and_cast {
133134
// Use the following for compile-time/build check only. And use it
134135
// with a hard-coded `0` version of `meta_num_slots` - otherwise you get an ICE.
135-
//
136+
//
136137
/*($e:expr, $t_check:ty, $t_cast:ty) => {
137138
($e + 0 as $t_check) as $t_cast
138139
}*/
139140
// Use the following to build for testing/using, while rustc causes an ICE with the above and
140141
// with a full version of `meta_num_slots`.
141142
($e:expr, $t_check:ty, $t_cast:ty) => {
142143
$e
143-
}
144+
};
144145
}
145146

146147
// ----- CoAlloc constant-like macros:
@@ -265,8 +266,11 @@ macro_rules! co_alloc_pref {
265266
// report the incorrect type of $meta_pref (if $meta_pref were some other integer, casting would
266267
// compile, and we would not be notified).
267268
($meta_pref:expr) => {
268-
$crate::check_type_and_cast!($meta_pref,$crate::co_alloc::CoAllocMetaNumSlotsPref,
269-
$crate::co_alloc::CoAllocPref)
269+
$crate::check_type_and_cast!(
270+
$meta_pref,
271+
$crate::co_alloc::CoAllocMetaNumSlotsPref,
272+
$crate::co_alloc::CoAllocPref
273+
)
270274
};
271275
}
272276

@@ -363,17 +367,3 @@ macro_rules! meta_num_slots_global {
363367
//<$crate::alloc::Global as ::core::alloc::Allocator>::CO_ALLOC_META_NUM_SLOTS
364368
};
365369
}
366-
/*
367-
/// Like `meta_num_slots`, but for `Global allocator and default coallocation preference
368-
/// (`CO_ALLOC_PREF_DEFAULT`).
369-
///
370-
// @FIXME once generic_const_exprs is stable, replace this with a `const` function. Then consider
371-
// moving the function to a submodule, for example alloc::co_alloc. See above.
372-
#[unstable(feature = "global_co_alloc", issue = "none")]
373-
#[macro_export]
374-
macro_rules! meta_num_slots_default_global {
375-
() => {
376-
$crate::meta_num_slots!($crate::alloc::Global, $crate::CO_ALLOC_PREF_DEFAULT!())
377-
};
378-
}
379-
*/

library/alloc/src/slice.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,8 @@ impl<T> [T] {
629629
#[inline]
630630
#[allow(unused_braces)]
631631
pub fn into_vec<A: Allocator>(self: Box<Self, A>) -> Vec<T, A>
632-
where [(); { crate::meta_num_slots_default!(A) }]:
632+
where
633+
[(); { crate::meta_num_slots_default!(A) }]:,
633634
{
634635
// N.B., see the `hack` module in this file for more details.
635636
hack::into_vec(self)
@@ -986,15 +987,17 @@ where
986987
#[cfg(not(no_global_oom_handling))]
987988
#[allow(unused_braces)]
988989
pub(crate) trait SpecCloneIntoVec<T, A: Allocator>
989-
where [(); { crate::meta_num_slots_default!(A) }]:
990+
where
991+
[(); { crate::meta_num_slots_default!(A) }]:,
990992
{
991993
fn clone_into(&self, target: &mut Vec<T, A>);
992994
}
993995

994996
#[cfg(not(no_global_oom_handling))]
995997
#[allow(unused_braces)]
996998
impl<T: Clone, A: Allocator> SpecCloneIntoVec<T, A> for [T]
997-
where [(); { crate::meta_num_slots_default!(A) }]:
999+
where
1000+
[(); { crate::meta_num_slots_default!(A) }]:,
9981001
{
9991002
default fn clone_into(&self, target: &mut Vec<T, A>) {
10001003
// drop anything in target that will not be overwritten
@@ -1013,7 +1016,8 @@ where [(); { crate::meta_num_slots_default!(A) }]:
10131016
#[cfg(not(no_global_oom_handling))]
10141017
#[allow(unused_braces)]
10151018
impl<T: Copy, A: Allocator> SpecCloneIntoVec<T, A> for [T]
1016-
where [(); { crate::meta_num_slots_default!(A) }]:
1019+
where
1020+
[(); { crate::meta_num_slots_default!(A) }]:,
10171021
{
10181022
fn clone_into(&self, target: &mut Vec<T, A>) {
10191023
target.clear();

library/alloc/src/vec/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,6 +1880,8 @@ where
18801880
where
18811881
[(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:,
18821882
{
1883+
crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:,
1884+
{
18831885
/* Offset of the element we want to check if it is duplicate */
18841886
read: usize,
18851887

@@ -3494,7 +3496,7 @@ where
34943496
// @FIXME unsure about test
34953497
#[cfg(not(test))]
34963498
#[allow(ineffective_unstable_trait_impl)] //@FIXME What/why is #[unstable(...)] ignored here?
3497-
#[unstable(feature = "global_co_alloc", issue="none")]
3499+
#[unstable(feature = "global_co_alloc", issue = "none")]
34983500
#[allow(unused_braces)]
34993501
impl<T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> From<Box<[T], A>>
35003502
for Vec<T, A, CO_ALLOC_PREF>
@@ -3509,8 +3511,7 @@ where
35093511
#[cfg(not(test))]
35103512
#[stable(feature = "vec_from_box", since = "1.18.0")]
35113513
#[allow(unused_braces)]
3512-
impl<T, A: Allocator> From<Box<[T], A>>
3513-
for Vec<T, A, {CO_ALLOC_PREF_DEFAULT!()}>
3514+
impl<T, A: Allocator> From<Box<[T], A>> for Vec<T, A, { CO_ALLOC_PREF_DEFAULT!() }>
35143515
where
35153516
[(); { crate::meta_num_slots_default!(A) }]:,
35163517
{
@@ -3532,7 +3533,7 @@ where
35323533
// @FIXME Can this apply to test?
35333534
#[cfg(not(test))]
35343535
#[allow(ineffective_unstable_trait_impl)] //@FIXME What/why is #[unstable(...)] ignored here?
3535-
#[unstable(feature = "global_co_alloc", issue="none")]
3536+
#[unstable(feature = "global_co_alloc", issue = "none")]
35363537
#[allow(unused_braces)]
35373538
impl<T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> From<Vec<T, A, CO_ALLOC_PREF>>
35383539
for Box<[T], A>
@@ -3548,8 +3549,7 @@ where
35483549
#[cfg(not(test))]
35493550
#[stable(feature = "box_from_vec", since = "1.20.0")]
35503551
#[allow(unused_braces)]
3551-
impl<T, A: Allocator> From<Vec<T, A>>
3552-
for Box<[T], A>
3552+
impl<T, A: Allocator> From<Vec<T, A>> for Box<[T], A>
35533553
where
35543554
[(); { crate::meta_num_slots_default!(A) }]:,
35553555
{

0 commit comments

Comments
 (0)