Skip to content

Commit 7fe4d21

Browse files
CoAlloc: asserts + docs
1 parent 9598b20 commit 7fe4d21

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl<T> SpecFromIter<T, IntoIter<T>> for VecDeque<T> {
3838
iterator.into_vecdeque()
3939
}
4040
}
41-
// ----
41+
// ---- CoAllocation:
4242

4343
#[allow(unused_braces)]
4444
impl<T, I, const CO_ALLOC_PREF: CoAllocPref> SpecFromIterCo<T, I>
@@ -48,6 +48,14 @@ where
4848
[(); { crate::meta_num_slots_global!(CO_ALLOC_PREF) }]:,
4949
{
5050
default fn spec_from_iter_co(iterator: I) -> Self {
51+
// @FIXME Move the assert to library/alloc/src/macros.rs -> co_alloc_pref!(...) and replace
52+
// calls to CO_ALLOC_PREF_META_YES and CO_ALLOC_PREF_META_NO with constants - once
53+
// https://github.com/rust-lang/rust/issues/106994 (the ICE) is fixed. Upvote it, please.
54+
core::debug_assert!(
55+
CO_ALLOC_PREF == crate::CO_ALLOC_PREF_META_YES!()
56+
|| CO_ALLOC_PREF == crate::CO_ALLOC_PREF_META_NO!(),
57+
"CO_ALLOC_PREF must equal to CO_ALLOC_PREF_META_YES!() or CO_ALLOC_PREF_META_NO!(), but it is: {CO_ALLOC_PREF}."
58+
);
5159
// Since converting is O(1) now, just re-use the `Vec` logic for
5260
// anything where we can't do something extra-special for `VecDeque`,
5361
// especially as that could save us some monomorphiziation work
@@ -57,7 +65,7 @@ where
5765
}
5866

5967
// Until we can use feature `specialization`:
60-
// FIXME macro
68+
// @FIXME new macro + replace 0 and 1 with META ZERO/ONE
6169
impl<T> SpecFromIterCo<T, crate::vec::IntoIter<T, Global, 0>> for VecDeque<T, Global, 0> {
6270
#[inline]
6371
fn spec_from_iter_co(iterator: crate::vec::IntoIter<T, Global, 0>) -> Self {

library/alloc/src/macros.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,14 @@ macro_rules! __rust_force_expr {
127127
};
128128
}
129129

130-
// ----- CoAlloc ICE workaround macro:
130+
// ----- CoAlloc ICE workaround macro
131+
//
132+
// Most of the following code is workaround until we have `generic_const_exprs`. Upvote
133+
// `https://github.com/rust-lang/rust/issues/76560, please.
134+
//
135+
// However, those (commented out) workarounds will compile only once
136+
// https://github.com/rust-lang/rust/issues/106994 (the ICE) is fixed first. Upvote it, too, please.
137+
131138
/// This "validates" type of a given `const` expression, and it casts it. That helps to prevent mix ups with macros/integer constant values.
132139
#[doc(hidden)]
133140
#[macro_export]

0 commit comments

Comments
 (0)