Skip to content

Commit 332fa6a

Browse files
committed
add FIXME(const-hack)
1 parent 7f9a541 commit 332fa6a

File tree

18 files changed

+38
-61
lines changed

18 files changed

+38
-61
lines changed

compiler/rustc_mir_transform/src/pass_manager.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn to_profiler_name(type_name: &'static str) -> &'static str {
4242

4343
// const wrapper for `if let Some((_, tail)) = name.rsplit_once(':') { tail } else { name }`
4444
const fn c_name(name: &'static str) -> &'static str {
45-
// FIXME Simplify the implementation once more `str` methods get const-stable.
45+
// FIXME(const-hack) Simplify the implementation once more `str` methods get const-stable.
4646
// and inline into call site
4747
let bytes = name.as_bytes();
4848
let mut i = bytes.len();
@@ -61,7 +61,7 @@ const fn c_name(name: &'static str) -> &'static str {
6161
/// loop that goes over each available MIR and applies `run_pass`.
6262
pub(super) trait MirPass<'tcx> {
6363
fn name(&self) -> &'static str {
64-
// FIXME Simplify the implementation once more `str` methods get const-stable.
64+
// FIXME(const-hack) Simplify the implementation once more `str` methods get const-stable.
6565
// See copypaste in `MirLint`
6666
const {
6767
let name = std::any::type_name::<Self>();
@@ -89,7 +89,7 @@ pub(super) trait MirPass<'tcx> {
8989
/// disabled (via the `Lint` adapter).
9090
pub(super) trait MirLint<'tcx> {
9191
fn name(&self) -> &'static str {
92-
// FIXME Simplify the implementation once more `str` methods get const-stable.
92+
// FIXME(const-hack) Simplify the implementation once more `str` methods get const-stable.
9393
// See copypaste in `MirPass`
9494
const {
9595
let name = std::any::type_name::<Self>();

library/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.

library/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]

library/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

library/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

library/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.

library/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,

library/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

library/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 {

library/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),

0 commit comments

Comments
 (0)