Skip to content

Commit 3a5c8e9

Browse files
committed
Auto merge of #110393 - fee1-dead-contrib:rm-const-traits, r=oli-obk
Rm const traits in libcore See [zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/.60const.20Trait.60.20removal.20or.20rework) * [x] Bless ui tests * [ ] Re constify some unstable functions with workarounds if they are needed
2 parents d7f9e81 + 14d1e87 commit 3a5c8e9

File tree

180 files changed

+1460
-1953
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

180 files changed

+1460
-1953
lines changed

compiler/rustc_ast/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
)]
1111
#![feature(associated_type_bounds)]
1212
#![feature(box_patterns)]
13-
#![feature(const_default_impls)]
1413
#![feature(const_trait_impl)]
1514
#![feature(if_let_guard)]
1615
#![feature(let_chains)]

compiler/rustc_ast/src/ptr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ impl<S: Encoder, T: Encodable<S>> Encodable<S> for P<T> {
126126
}
127127

128128
impl<T> P<[T]> {
129-
pub const fn new() -> P<[T]> {
129+
// FIXME(const-hack) make this const again
130+
pub fn new() -> P<[T]> {
130131
P { ptr: Box::default() }
131132
}
132133

compiler/rustc_const_eval/src/transform/check_consts/ops.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -610,10 +610,11 @@ pub struct RawPtrComparison;
610610
impl<'tcx> NonConstOp<'tcx> for RawPtrComparison {
611611
fn build_error(
612612
&self,
613-
_: &ConstCx<'_, 'tcx>,
613+
ccx: &ConstCx<'_, 'tcx>,
614614
span: Span,
615615
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
616-
span_bug!(span, "raw ptr comparison should already be caught in the trait system");
616+
// FIXME(const_trait_impl): revert to span_bug?
617+
ccx.tcx.sess.create_err(errors::RawPtrComparisonErr { span })
617618
}
618619
}
619620

library/alloc/src/boxed.rs

+11-22
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,7 @@ impl<T, A: Allocator> Box<T, A> {
576576
///
577577
/// This conversion does not allocate on the heap and happens in place.
578578
#[unstable(feature = "box_into_boxed_slice", issue = "71582")]
579-
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
580-
pub const fn into_boxed_slice(boxed: Self) -> Box<[T], A> {
579+
pub fn into_boxed_slice(boxed: Self) -> Box<[T], A> {
581580
let (raw, alloc) = Box::into_raw_with_allocator(boxed);
582581
unsafe { Box::from_raw_in(raw as *mut [T; 1], alloc) }
583582
}
@@ -809,9 +808,8 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
809808
/// assert_eq!(*five, 5)
810809
/// ```
811810
#[unstable(feature = "new_uninit", issue = "63291")]
812-
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
813811
#[inline]
814-
pub const unsafe fn assume_init(self) -> Box<T, A> {
812+
pub unsafe fn assume_init(self) -> Box<T, A> {
815813
let (raw, alloc) = Box::into_raw_with_allocator(self);
816814
unsafe { Box::from_raw_in(raw as *mut T, alloc) }
817815
}
@@ -844,9 +842,8 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
844842
/// }
845843
/// ```
846844
#[unstable(feature = "new_uninit", issue = "63291")]
847-
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
848845
#[inline]
849-
pub const fn write(mut boxed: Self, value: T) -> Box<T, A> {
846+
pub fn write(mut boxed: Self, value: T) -> Box<T, A> {
850847
unsafe {
851848
(*boxed).write(value);
852849
boxed.assume_init()
@@ -1090,9 +1087,8 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
10901087
///
10911088
/// [memory layout]: self#memory-layout
10921089
#[unstable(feature = "allocator_api", issue = "32838")]
1093-
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
10941090
#[inline]
1095-
pub const fn into_raw_with_allocator(b: Self) -> (*mut T, A) {
1091+
pub fn into_raw_with_allocator(b: Self) -> (*mut T, A) {
10961092
let (leaked, alloc) = Box::into_unique(b);
10971093
(leaked.as_ptr(), alloc)
10981094
}
@@ -1102,10 +1098,9 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
11021098
issue = "none",
11031099
reason = "use `Box::leak(b).into()` or `Unique::from(Box::leak(b))` instead"
11041100
)]
1105-
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
11061101
#[inline]
11071102
#[doc(hidden)]
1108-
pub const fn into_unique(b: Self) -> (Unique<T>, A) {
1103+
pub fn into_unique(b: Self) -> (Unique<T>, A) {
11091104
// Box is recognized as a "unique pointer" by Stacked Borrows, but internally it is a
11101105
// raw pointer for the type system. Turning it directly into a raw pointer would not be
11111106
// recognized as "releasing" the unique pointer to permit aliased raw accesses,
@@ -1163,9 +1158,8 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
11631158
/// assert_eq!(*static_ref, [4, 2, 3]);
11641159
/// ```
11651160
#[stable(feature = "box_leak", since = "1.26.0")]
1166-
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
11671161
#[inline]
1168-
pub const fn leak<'a>(b: Self) -> &'a mut T
1162+
pub fn leak<'a>(b: Self) -> &'a mut T
11691163
where
11701164
A: 'a,
11711165
{
@@ -1234,8 +1228,7 @@ impl<T: Default> Default for Box<T> {
12341228

12351229
#[cfg(not(no_global_oom_handling))]
12361230
#[stable(feature = "rust1", since = "1.0.0")]
1237-
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
1238-
impl<T> const Default for Box<[T]> {
1231+
impl<T> Default for Box<[T]> {
12391232
#[inline]
12401233
fn default() -> Self {
12411234
let ptr: Unique<[T]> = Unique::<[T; 0]>::dangling();
@@ -1245,8 +1238,7 @@ impl<T> const Default for Box<[T]> {
12451238

12461239
#[cfg(not(no_global_oom_handling))]
12471240
#[stable(feature = "default_box_extra", since = "1.17.0")]
1248-
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
1249-
impl const Default for Box<str> {
1241+
impl Default for Box<str> {
12501242
#[inline]
12511243
fn default() -> Self {
12521244
// SAFETY: This is the same as `Unique::cast<U>` but with an unsized `U = str`.
@@ -1443,8 +1435,7 @@ impl<T> From<T> for Box<T> {
14431435
}
14441436

14451437
#[stable(feature = "pin", since = "1.33.0")]
1446-
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
1447-
impl<T: ?Sized, A: Allocator> const From<Box<T, A>> for Pin<Box<T, A>>
1438+
impl<T: ?Sized, A: Allocator> From<Box<T, A>> for Pin<Box<T, A>>
14481439
where
14491440
A: 'static,
14501441
{
@@ -1880,8 +1871,7 @@ impl<T: ?Sized, A: Allocator> fmt::Pointer for Box<T, A> {
18801871
}
18811872

18821873
#[stable(feature = "rust1", since = "1.0.0")]
1883-
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
1884-
impl<T: ?Sized, A: Allocator> const Deref for Box<T, A> {
1874+
impl<T: ?Sized, A: Allocator> Deref for Box<T, A> {
18851875
type Target = T;
18861876

18871877
fn deref(&self) -> &T {
@@ -1890,8 +1880,7 @@ impl<T: ?Sized, A: Allocator> const Deref for Box<T, A> {
18901880
}
18911881

18921882
#[stable(feature = "rust1", since = "1.0.0")]
1893-
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
1894-
impl<T: ?Sized, A: Allocator> const DerefMut for Box<T, A> {
1883+
impl<T: ?Sized, A: Allocator> DerefMut for Box<T, A> {
18951884
fn deref_mut(&mut self) -> &mut T {
18961885
&mut **self
18971886
}

library/alloc/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@
106106
#![feature(coerce_unsized)]
107107
#![feature(const_align_of_val)]
108108
#![feature(const_box)]
109-
#![feature(const_convert)]
110109
#![feature(const_cow_is_borrowed)]
111110
#![feature(const_eval_select)]
112111
#![feature(const_maybe_uninit_as_mut_ptr)]
@@ -174,7 +173,6 @@
174173
#![feature(associated_type_bounds)]
175174
#![feature(c_unwind)]
176175
#![feature(cfg_sanitize)]
177-
#![feature(const_deref)]
178176
#![feature(const_mut_refs)]
179177
#![feature(const_precise_live_drops)]
180178
#![feature(const_ptr_write)]

library/alloc/src/string.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2247,8 +2247,7 @@ impl_eq! { Cow<'a, str>, &'b str }
22472247
impl_eq! { Cow<'a, str>, String }
22482248

22492249
#[stable(feature = "rust1", since = "1.0.0")]
2250-
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
2251-
impl const Default for String {
2250+
impl Default for String {
22522251
/// Creates an empty `String`.
22532252
#[inline]
22542253
fn default() -> String {

library/alloc/src/vec/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3022,8 +3022,7 @@ unsafe impl<#[may_dangle] T, A: Allocator> Drop for Vec<T, A> {
30223022
}
30233023

30243024
#[stable(feature = "rust1", since = "1.0.0")]
3025-
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
3026-
impl<T> const Default for Vec<T> {
3025+
impl<T> Default for Vec<T> {
30273026
/// Creates an empty `Vec<T>`.
30283027
///
30293028
/// The vector will not allocate until elements are pushed onto it.

library/alloc/tests/boxed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn box_deref_lval() {
6161

6262
pub struct ConstAllocator;
6363

64-
unsafe impl const Allocator for ConstAllocator {
64+
unsafe impl Allocator for ConstAllocator {
6565
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
6666
match layout.size() {
6767
0 => Ok(NonNull::slice_from_raw_parts(layout.dangling(), 0)),

library/alloc/tests/const_fns.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
// Test const functions in the library
22

33
pub const MY_VEC: Vec<usize> = Vec::new();
4-
pub const MY_VEC2: Vec<usize> = Default::default();
4+
5+
// FIXME(#110395)
6+
// pub const MY_VEC2: Vec<usize> = Default::default();
57

68
pub const MY_STRING: String = String::new();
7-
pub const MY_STRING2: String = Default::default();
89

9-
pub const MY_BOXED_SLICE: Box<[usize]> = Default::default();
10-
pub const MY_BOXED_STR: Box<str> = Default::default();
10+
// pub const MY_STRING2: String = Default::default();
11+
12+
// pub const MY_BOXED_SLICE: Box<[usize]> = Default::default();
13+
// pub const MY_BOXED_STR: Box<str> = Default::default();
1114

1215
use std::collections::{BTreeMap, BTreeSet};
1316

@@ -23,11 +26,11 @@ pub const SET_IS_EMPTY: bool = SET.is_empty();
2326

2427
#[test]
2528
fn test_const() {
26-
assert_eq!(MY_VEC, MY_VEC2);
27-
assert_eq!(MY_STRING, MY_STRING2);
29+
assert_eq!(MY_VEC, /* MY_VEC */ vec![]);
30+
assert_eq!(MY_STRING, /* MY_STRING2 */ String::default());
2831

29-
assert_eq!(MY_VEC, *MY_BOXED_SLICE);
30-
assert_eq!(MY_STRING, *MY_BOXED_STR);
32+
// assert_eq!(MY_VEC, *MY_BOXED_SLICE);
33+
// assert_eq!(MY_STRING, *MY_BOXED_STR);
3134

3235
assert_eq!(MAP_LEN, 0);
3336
assert_eq!(SET_LEN, 0);

library/alloc/tests/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#![feature(assert_matches)]
44
#![feature(btree_drain_filter)]
55
#![feature(cow_is_borrowed)]
6-
#![feature(const_convert)]
76
#![feature(const_cow_is_borrowed)]
87
#![feature(const_heap)]
98
#![feature(const_mut_refs)]
@@ -33,7 +32,6 @@
3332
#![feature(slice_partition_dedup)]
3433
#![feature(string_remove_matches)]
3534
#![feature(const_btree_len)]
36-
#![feature(const_default_impls)]
3735
#![feature(const_trait_impl)]
3836
#![feature(const_str_from_utf8)]
3937
#![feature(panic_update_hook)]

library/core/src/alloc/layout.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,8 @@ impl Layout {
231231
/// Returns an error if the combination of `self.size()` and the given
232232
/// `align` violates the conditions listed in [`Layout::from_size_align`].
233233
#[stable(feature = "alloc_layout_manipulation", since = "1.44.0")]
234-
#[rustc_const_unstable(feature = "const_alloc_layout", issue = "67521")]
235234
#[inline]
236-
pub const fn align_to(&self, align: usize) -> Result<Self, LayoutError> {
235+
pub fn align_to(&self, align: usize) -> Result<Self, LayoutError> {
237236
Layout::from_size_align(self.size(), cmp::max(self.align(), align))
238237
}
239238

@@ -315,9 +314,8 @@ impl Layout {
315314
///
316315
/// On arithmetic overflow, returns `LayoutError`.
317316
#[unstable(feature = "alloc_layout_extra", issue = "55724")]
318-
#[rustc_const_unstable(feature = "const_alloc_layout", issue = "67521")]
319317
#[inline]
320-
pub const fn repeat(&self, n: usize) -> Result<(Self, usize), LayoutError> {
318+
pub fn repeat(&self, n: usize) -> Result<(Self, usize), LayoutError> {
321319
// This cannot overflow. Quoting from the invariant of Layout:
322320
// > `size`, when rounded up to the nearest multiple of `align`,
323321
// > must not overflow isize (i.e., the rounded value must be
@@ -376,9 +374,8 @@ impl Layout {
376374
/// # assert_eq!(repr_c(&[u64, u32, u16, u32]), Ok((s, vec![0, 8, 12, 16])));
377375
/// ```
378376
#[stable(feature = "alloc_layout_manipulation", since = "1.44.0")]
379-
#[rustc_const_unstable(feature = "const_alloc_layout", issue = "67521")]
380377
#[inline]
381-
pub const fn extend(&self, next: Self) -> Result<(Self, usize), LayoutError> {
378+
pub fn extend(&self, next: Self) -> Result<(Self, usize), LayoutError> {
382379
let new_align = cmp::max(self.align, next.align);
383380
let pad = self.padding_needed_for(next.align());
384381

@@ -403,9 +400,8 @@ impl Layout {
403400
///
404401
/// On arithmetic overflow, returns `LayoutError`.
405402
#[unstable(feature = "alloc_layout_extra", issue = "55724")]
406-
#[rustc_const_unstable(feature = "const_alloc_layout", issue = "67521")]
407403
#[inline]
408-
pub const fn repeat_packed(&self, n: usize) -> Result<Self, LayoutError> {
404+
pub fn repeat_packed(&self, n: usize) -> Result<Self, LayoutError> {
409405
let size = self.size().checked_mul(n).ok_or(LayoutError)?;
410406
// The safe constructor is called here to enforce the isize size limit.
411407
Layout::from_size_alignment(size, self.align)
@@ -418,9 +414,8 @@ impl Layout {
418414
///
419415
/// On arithmetic overflow, returns `LayoutError`.
420416
#[unstable(feature = "alloc_layout_extra", issue = "55724")]
421-
#[rustc_const_unstable(feature = "const_alloc_layout", issue = "67521")]
422417
#[inline]
423-
pub const fn extend_packed(&self, next: Self) -> Result<Self, LayoutError> {
418+
pub fn extend_packed(&self, next: Self) -> Result<Self, LayoutError> {
424419
let new_size = self.size().checked_add(next.size()).ok_or(LayoutError)?;
425420
// The safe constructor is called here to enforce the isize size limit.
426421
Layout::from_size_alignment(new_size, self.align)

library/core/src/alloc/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ impl fmt::Display for AllocError {
105105
///
106106
/// [*currently allocated*]: #currently-allocated-memory
107107
#[unstable(feature = "allocator_api", issue = "32838")]
108-
#[const_trait]
109108
pub unsafe trait Allocator {
110109
/// Attempts to allocate a block of memory.
111110
///

library/core/src/any.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,7 @@ impl dyn Any + Send + Sync {
662662
/// While `TypeId` implements `Hash`, `PartialOrd`, and `Ord`, it is worth
663663
/// noting that the hashes and ordering will vary between Rust releases. Beware
664664
/// of relying on them inside of your code!
665-
#[derive(Clone, Copy, Debug, Hash, Eq)]
666-
#[derive_const(PartialEq, PartialOrd, Ord)]
665+
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
667666
#[stable(feature = "rust1", since = "1.0.0")]
668667
pub struct TypeId {
669668
t: u64,

library/core/src/array/mod.rs

+9-16
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ impl Error for TryFromSliceError {
148148
}
149149

150150
#[stable(feature = "try_from_slice_error", since = "1.36.0")]
151-
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
152-
impl const From<Infallible> for TryFromSliceError {
151+
impl From<Infallible> for TryFromSliceError {
153152
fn from(x: Infallible) -> TryFromSliceError {
154153
match x {}
155154
}
@@ -172,16 +171,14 @@ impl<T, const N: usize> AsMut<[T]> for [T; N] {
172171
}
173172

174173
#[stable(feature = "array_borrow", since = "1.4.0")]
175-
#[rustc_const_unstable(feature = "const_borrow", issue = "91522")]
176-
impl<T, const N: usize> const Borrow<[T]> for [T; N] {
174+
impl<T, const N: usize> Borrow<[T]> for [T; N] {
177175
fn borrow(&self) -> &[T] {
178176
self
179177
}
180178
}
181179

182180
#[stable(feature = "array_borrow", since = "1.4.0")]
183-
#[rustc_const_unstable(feature = "const_borrow", issue = "91522")]
184-
impl<T, const N: usize> const BorrowMut<[T]> for [T; N] {
181+
impl<T, const N: usize> BorrowMut<[T]> for [T; N] {
185182
fn borrow_mut(&mut self) -> &mut [T] {
186183
self
187184
}
@@ -336,10 +333,9 @@ impl<'a, T, const N: usize> IntoIterator for &'a mut [T; N] {
336333
}
337334

338335
#[stable(feature = "index_trait_on_arrays", since = "1.50.0")]
339-
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
340-
impl<T, I, const N: usize> const Index<I> for [T; N]
336+
impl<T, I, const N: usize> Index<I> for [T; N]
341337
where
342-
[T]: ~const Index<I>,
338+
[T]: Index<I>,
343339
{
344340
type Output = <[T] as Index<I>>::Output;
345341

@@ -350,10 +346,9 @@ where
350346
}
351347

352348
#[stable(feature = "index_trait_on_arrays", since = "1.50.0")]
353-
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
354-
impl<T, I, const N: usize> const IndexMut<I> for [T; N]
349+
impl<T, I, const N: usize> IndexMut<I> for [T; N]
355350
where
356-
[T]: ~const IndexMut<I>,
351+
[T]: IndexMut<I>,
357352
{
358353
#[inline]
359354
fn index_mut(&mut self, index: I) -> &mut Self::Output {
@@ -435,8 +430,7 @@ impl<T: Copy> SpecArrayClone for T {
435430
macro_rules! array_impl_default {
436431
{$n:expr, $t:ident $($ts:ident)*} => {
437432
#[stable(since = "1.4.0", feature = "array_default")]
438-
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
439-
impl<T> const Default for [T; $n] where T: ~const Default {
433+
impl<T> Default for [T; $n] where T: Default {
440434
fn default() -> [T; $n] {
441435
[$t::default(), $($ts::default()),*]
442436
}
@@ -445,8 +439,7 @@ macro_rules! array_impl_default {
445439
};
446440
{$n:expr,} => {
447441
#[stable(since = "1.4.0", feature = "array_default")]
448-
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
449-
impl<T> const Default for [T; $n] {
442+
impl<T> Default for [T; $n] {
450443
fn default() -> [T; $n] { [] }
451444
}
452445
};

0 commit comments

Comments
 (0)