Skip to content

Commit 0099117

Browse files
committed
add FIXME(const-hack)
1 parent 9a4c780 commit 0099117

File tree

17 files changed

+35
-58
lines changed

17 files changed

+35
-58
lines changed

alloc/src/collections/vec_deque/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,8 @@ impl<T> VecDeque<T> {
554554
#[rustc_const_stable(feature = "const_vec_deque_new", since = "1.68.0")]
555555
#[must_use]
556556
pub const fn new() -> VecDeque<T> {
557-
// FIXME: This should just be `VecDeque::new_in(Global)` once that hits stable.
558-
VecDeque { head: 0, len: 0, buf: RawVec::NEW }
557+
// FIXME(const-hack): This should just be `VecDeque::new_in(Global)` once that hits stable.
558+
VecDeque { head: 0, len: 0, buf: RawVec::new() }
559559
}
560560

561561
/// Creates an empty deque with space for at least `capacity` elements.

alloc/src/raw_vec.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,6 @@ struct RawVecInner<A: Allocator = Global> {
9696
}
9797

9898
impl<T> RawVec<T, Global> {
99-
/// HACK(Centril): This exists because stable `const fn` can only call stable `const fn`, so
100-
/// they cannot call `Self::new()`.
101-
///
102-
/// If you change `RawVec<T>::new` or dependencies, please take care to not introduce anything
103-
/// that would truly const-call something unstable.
104-
pub const NEW: Self = Self::new();
105-
10699
/// Creates the biggest possible `RawVec` (on the system heap)
107100
/// without allocating. If `T` has positive size, then this makes a
108101
/// `RawVec` with capacity `0`. If `T` is zero-sized, then it makes a
@@ -111,7 +104,7 @@ impl<T> RawVec<T, Global> {
111104
#[must_use]
112105
#[rustc_const_stable(feature = "raw_vec_internals_const", since = "1.81")]
113106
pub const fn new() -> Self {
114-
Self { inner: RawVecInner::new::<T>(), _marker: PhantomData }
107+
Self::new_in(Global)
115108
}
116109

117110
/// Creates a `RawVec` (on the system heap) with exactly the
@@ -149,12 +142,6 @@ impl<T> RawVec<T, Global> {
149142
}
150143

151144
impl RawVecInner<Global> {
152-
#[must_use]
153-
#[rustc_const_stable(feature = "raw_vec_internals_const", since = "1.81")]
154-
const fn new<T>() -> Self {
155-
Self::new_in(Global, core::mem::align_of::<T>())
156-
}
157-
158145
#[cfg(not(any(no_global_oom_handling, test)))]
159146
#[must_use]
160147
#[inline]

alloc/src/vec/in_place_collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ const fn in_place_collectible<DEST, SRC>(
191191

192192
const fn needs_realloc<SRC, DEST>(src_cap: usize, dst_cap: usize) -> bool {
193193
if const { mem::align_of::<SRC>() != mem::align_of::<DEST>() } {
194-
// FIXME: use unreachable! once that works in const
194+
// FIXME(const-hack): use unreachable! once that works in const
195195
panic!("in_place_collectible() prevents this");
196196
}
197197

alloc/src/vec/into_iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl<T, A: Allocator> IntoIter<T, A> {
142142
// struct and then overwriting &mut self.
143143
// this creates less assembly
144144
self.cap = 0;
145-
self.buf = RawVec::NEW.non_null();
145+
self.buf = RawVec::new().non_null();
146146
self.ptr = self.buf;
147147
self.end = self.buf.as_ptr();
148148

alloc/src/vec/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ impl<T> Vec<T> {
419419
#[stable(feature = "rust1", since = "1.0.0")]
420420
#[must_use]
421421
pub const fn new() -> Self {
422-
Vec { buf: RawVec::NEW, len: 0 }
422+
Vec { buf: RawVec::new(), len: 0 }
423423
}
424424

425425
/// Constructs a new, empty `Vec<T>` with at least the specified capacity.

core/src/char/convert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::ub_checks::assert_unsafe_precondition;
1111
#[must_use]
1212
#[inline]
1313
pub(super) const fn from_u32(i: u32) -> Option<char> {
14-
// FIXME: once Result::ok is const fn, use it here
14+
// FIXME(const-hack): once Result::ok is const fn, use it here
1515
match char_try_from_u32(i) {
1616
Ok(c) => Some(c),
1717
Err(_) => None,

core/src/char/methods.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ impl char {
386386
// Force the 6th bit to be set to ensure ascii is lower case.
387387
digit = (self as u32 | 0b10_0000).wrapping_sub('a' as u32).saturating_add(10);
388388
}
389-
// FIXME: once then_some is const fn, use it here
389+
// FIXME(const-hack): once then_some is const fn, use it here
390390
if digit < radix { Some(digit) } else { None }
391391
}
392392

core/src/num/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::str::FromStr;
66
use crate::ub_checks::assert_unsafe_precondition;
77
use crate::{ascii, intrinsics, mem};
88

9-
// Used because the `?` operator is not allowed in a const context.
9+
// FIXME(const-hack): Used because the `?` operator is not allowed in a const context.
1010
macro_rules! try_opt {
1111
($e:expr) => {
1212
match $e {

core/src/option.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,7 @@ impl<T> Option<T> {
739739
#[stable(feature = "pin", since = "1.33.0")]
740740
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
741741
pub const fn as_pin_ref(self: Pin<&Self>) -> Option<Pin<&T>> {
742+
// FIXME(const-hack): use `map` once that is possible
742743
match Pin::get_ref(self).as_ref() {
743744
// SAFETY: `x` is guaranteed to be pinned because it comes from `self`
744745
// which is pinned.
@@ -758,6 +759,7 @@ impl<T> Option<T> {
758759
// SAFETY: `get_unchecked_mut` is never used to move the `Option` inside `self`.
759760
// `x` is guaranteed to be pinned because it comes from `self` which is pinned.
760761
unsafe {
762+
// FIXME(const-hack): use `map` once that is possible
761763
match Pin::get_unchecked_mut(self).as_mut() {
762764
Some(x) => Some(Pin::new_unchecked(x)),
763765
None => None,
@@ -1290,10 +1292,7 @@ impl<T> Option<T> {
12901292
where
12911293
T: Deref,
12921294
{
1293-
match self.as_ref() {
1294-
Some(t) => Some(t.deref()),
1295-
None => None,
1296-
}
1295+
self.as_ref().map(|t| t.deref())
12971296
}
12981297

12991298
/// Converts from `Option<T>` (or `&mut Option<T>`) to `Option<&mut T::Target>`.
@@ -1316,10 +1315,7 @@ impl<T> Option<T> {
13161315
where
13171316
T: DerefMut,
13181317
{
1319-
match self.as_mut() {
1320-
Some(t) => Some(t.deref_mut()),
1321-
None => None,
1322-
}
1318+
self.as_mut().map(|t| t.deref_mut())
13231319
}
13241320

13251321
/////////////////////////////////////////////////////////////////////////
@@ -1633,13 +1629,7 @@ impl<T> Option<T> {
16331629
#[inline]
16341630
#[stable(feature = "option_entry", since = "1.20.0")]
16351631
pub fn get_or_insert(&mut self, value: T) -> &mut T {
1636-
if let None = *self {
1637-
*self = Some(value);
1638-
}
1639-
1640-
// SAFETY: a `None` variant for `self` would have been replaced by a `Some`
1641-
// variant in the code above.
1642-
unsafe { self.as_mut().unwrap_unchecked() }
1632+
self.get_or_insert_with(|| value)
16431633
}
16441634

16451635
/// Inserts the default value into the option if it is [`None`], then
@@ -1725,7 +1715,7 @@ impl<T> Option<T> {
17251715
#[stable(feature = "rust1", since = "1.0.0")]
17261716
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
17271717
pub const fn take(&mut self) -> Option<T> {
1728-
// FIXME replace `mem::replace` by `mem::take` when the latter is const ready
1718+
// FIXME(const-hack) replace `mem::replace` by `mem::take` when the latter is const ready
17291719
mem::replace(self, None)
17301720
}
17311721

@@ -1894,7 +1884,7 @@ impl<T> Option<&T> {
18941884
where
18951885
T: Copy,
18961886
{
1897-
// FIXME: this implementation, which sidesteps using `Option::map` since it's not const
1887+
// FIXME(const-hack): this implementation, which sidesteps using `Option::map` since it's not const
18981888
// ready yet, should be reverted when possible to avoid code repetition
18991889
match self {
19001890
Some(&v) => Some(v),

core/src/slice/index.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ where
3333
#[track_caller]
3434
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
3535
const fn slice_start_index_len_fail(index: usize, len: usize) -> ! {
36+
// FIXME(const-hack): once integer formatting in panics is possible, we
37+
// should use the same implementation at compiletime and runtime.
3638
const_eval_select((index, len), slice_start_index_len_fail_ct, slice_start_index_len_fail_rt)
3739
}
3840

39-
// FIXME const-hack
4041
#[inline]
4142
#[track_caller]
4243
fn slice_start_index_len_fail_rt(index: usize, len: usize) -> ! {
@@ -54,10 +55,11 @@ const fn slice_start_index_len_fail_ct(_: usize, _: usize) -> ! {
5455
#[track_caller]
5556
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
5657
const fn slice_end_index_len_fail(index: usize, len: usize) -> ! {
58+
// FIXME(const-hack): once integer formatting in panics is possible, we
59+
// should use the same implementation at compiletime and runtime.
5760
const_eval_select((index, len), slice_end_index_len_fail_ct, slice_end_index_len_fail_rt)
5861
}
5962

60-
// FIXME const-hack
6163
#[inline]
6264
#[track_caller]
6365
fn slice_end_index_len_fail_rt(index: usize, len: usize) -> ! {
@@ -75,10 +77,11 @@ const fn slice_end_index_len_fail_ct(_: usize, _: usize) -> ! {
7577
#[track_caller]
7678
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
7779
const fn slice_index_order_fail(index: usize, end: usize) -> ! {
80+
// FIXME(const-hack): once integer formatting in panics is possible, we
81+
// should use the same implementation at compiletime and runtime.
7882
const_eval_select((index, end), slice_index_order_fail_ct, slice_index_order_fail_rt)
7983
}
8084

81-
// FIXME const-hack
8285
#[inline]
8386
#[track_caller]
8487
fn slice_index_order_fail_rt(index: usize, end: usize) -> ! {

0 commit comments

Comments
 (0)