Skip to content

Commit 63e0ddb

Browse files
committed
core is now compilable
1 parent e80c020 commit 63e0ddb

File tree

21 files changed

+85
-253
lines changed

21 files changed

+85
-253
lines changed

library/alloc/src/lib.rs

Lines changed: 0 additions & 2 deletions
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/core/src/alloc/layout.rs

Lines changed: 5 additions & 10 deletions
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/bool.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ impl bool {
3030
/// ```
3131
#[stable(feature = "bool_to_option", since = "1.62.0")]
3232
#[inline]
33-
pub fn then_some<T>(self, t: T) -> Option<T>
34-
{
33+
pub fn then_some<T>(self, t: T) -> Option<T> {
3534
if self { Some(t) } else { None }
3635
}
3736

@@ -57,8 +56,7 @@ impl bool {
5756
/// ```
5857
#[stable(feature = "lazy_bool_to_option", since = "1.50.0")]
5958
#[inline]
60-
pub fn then<T, F: FnOnce() -> T>(self, f: F) -> Option<T>
61-
{
59+
pub fn then<T, F: FnOnce() -> T>(self, f: F) -> Option<T> {
6260
if self { Some(f()) } else { None }
6361
}
6462
}

library/core/src/clone.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ pub trait Clone: Sized {
126126
/// allocations.
127127
#[inline]
128128
#[stable(feature = "rust1", since = "1.0.0")]
129-
fn clone_from(&mut self, source: &Self)
130-
{
129+
fn clone_from(&mut self, source: &Self) {
131130
*self = source.clone()
132131
}
133132
}

library/core/src/cmp.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
mod bytewise;
2626
pub(crate) use bytewise::BytewiseEq;
2727

28-
use crate::marker::Destruct;
29-
3028
use self::Ordering::*;
3129

3230
/// Trait for equality comparisons.
@@ -1158,9 +1156,8 @@ pub macro PartialOrd($item:item) {
11581156
#[inline]
11591157
#[must_use]
11601158
#[stable(feature = "rust1", since = "1.0.0")]
1161-
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
11621159
#[cfg_attr(not(test), rustc_diagnostic_item = "cmp_min")]
1163-
pub const fn min<T: Ord>(v1: T, v2: T) -> T {
1160+
pub fn min<T: Ord>(v1: T, v2: T) -> T {
11641161
v1.min(v2)
11651162
}
11661163

@@ -1179,8 +1176,7 @@ pub const fn min<T: Ord>(v1: T, v2: T) -> T {
11791176
#[inline]
11801177
#[must_use]
11811178
#[stable(feature = "cmp_min_max_by", since = "1.53.0")]
1182-
pub fn min_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T
1183-
{
1179+
pub fn min_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
11841180
match compare(&v1, &v2) {
11851181
Ordering::Less | Ordering::Equal => v1,
11861182
Ordering::Greater => v2,
@@ -1202,8 +1198,7 @@ pub fn min_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T
12021198
#[inline]
12031199
#[must_use]
12041200
#[stable(feature = "cmp_min_max_by", since = "1.53.0")]
1205-
pub fn min_by_key<T, F:FnMut(&T) -> K, K: Ord>(v1: T, v2: T, mut f: F) -> T
1206-
{
1201+
pub fn min_by_key<T, F: FnMut(&T) -> K, K: Ord>(v1: T, v2: T, mut f: F) -> T {
12071202
min_by(v1, v2, |v1, v2| f(v1).cmp(&f(v2)))
12081203
}
12091204

@@ -1244,8 +1239,7 @@ pub fn max<T: Ord>(v1: T, v2: T) -> T {
12441239
#[inline]
12451240
#[must_use]
12461241
#[stable(feature = "cmp_min_max_by", since = "1.53.0")]
1247-
pub fn max_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T
1248-
{
1242+
pub fn max_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
12491243
match compare(&v1, &v2) {
12501244
Ordering::Less | Ordering::Equal => v2,
12511245
Ordering::Greater => v1,
@@ -1267,14 +1261,8 @@ pub fn max_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T
12671261
#[inline]
12681262
#[must_use]
12691263
#[stable(feature = "cmp_min_max_by", since = "1.53.0")]
1270-
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
1271-
pub const fn max_by_key<T, F: FnMut(&T) -> K, K: Ord>(v1: T, v2: T, mut f: F) -> T
1272-
where
1273-
T: Destruct,
1274-
F: Destruct,
1275-
K: Destruct,
1276-
{
1277-
max_by(v1, v2, const |v1, v2| f(v1).cmp(&f(v2)))
1264+
pub fn max_by_key<T, F: FnMut(&T) -> K, K: Ord>(v1: T, v2: T, mut f: F) -> T {
1265+
max_by(v1, v2, |v1, v2| f(v1).cmp(&f(v2)))
12781266
}
12791267

12801268
// Implementation of PartialEq, Eq, PartialOrd and Ord for primitive types

library/core/src/ffi/c_str.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,14 +324,14 @@ impl CStr {
324324
/// assert_eq!(c_str.to_str().unwrap(), "AAAAAAAA");
325325
/// ```
326326
///
327-
#[rustc_allow_const_fn_unstable(const_slice_index)]
328327
#[stable(feature = "cstr_from_bytes_until_nul", since = "1.69.0")]
329328
#[rustc_const_stable(feature = "cstr_from_bytes_until_nul", since = "1.69.0")]
330329
pub const fn from_bytes_until_nul(bytes: &[u8]) -> Result<&CStr, FromBytesUntilNulError> {
331330
let nul_pos = memchr::memchr(0, bytes);
332331
match nul_pos {
333332
Some(nul_pos) => {
334-
let subslice = &bytes[..nul_pos + 1];
333+
// FIXME(const-hack) replace with range index
334+
let subslice = unsafe { crate::slice::from_raw_parts(bytes.as_ptr(), nul_pos + 1) };
335335
// SAFETY: We know there is a nul byte at nul_pos, so this slice
336336
// (ending at the nul byte) is a well-formed C string.
337337
Ok(unsafe { CStr::from_bytes_with_nul_unchecked(subslice) })
@@ -561,8 +561,7 @@ impl CStr {
561561
#[must_use = "this returns the result of the operation, \
562562
without modifying the original"]
563563
#[stable(feature = "rust1", since = "1.0.0")]
564-
#[rustc_const_unstable(feature = "const_cstr_methods", issue = "101719")]
565-
pub const fn to_bytes(&self) -> &[u8] {
564+
pub fn to_bytes(&self) -> &[u8] {
566565
let bytes = self.to_bytes_with_nul();
567566
// SAFETY: to_bytes_with_nul returns slice with length at least 1
568567
unsafe { bytes.get_unchecked(..bytes.len() - 1) }
@@ -613,8 +612,7 @@ impl CStr {
613612
/// assert_eq!(cstr.to_str(), Ok("foo"));
614613
/// ```
615614
#[stable(feature = "cstr_to_str", since = "1.4.0")]
616-
#[rustc_const_unstable(feature = "const_cstr_methods", issue = "101719")]
617-
pub const fn to_str(&self) -> Result<&str, str::Utf8Error> {
615+
pub fn to_str(&self) -> Result<&str, str::Utf8Error> {
618616
// N.B., when `CStr` is changed to perform the length check in `.to_bytes()`
619617
// instead of in `from_ptr()`, it may be worth considering if this should
620618
// be rewritten to do the UTF-8 check inline with the length calculation

library/core/src/hash/mod.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
#![stable(feature = "rust1", since = "1.0.0")]
8787

8888
use crate::fmt;
89-
use crate::intrinsics::const_eval_select;
9089
use crate::marker;
9190

9291
#[stable(feature = "rust1", since = "1.0.0")]
@@ -239,21 +238,9 @@ pub trait Hash {
239238
where
240239
Self: Sized,
241240
{
242-
//FIXME(const_trait_impl): revert to only a for loop
243-
fn rt<T: Hash, H: Hasher>(data: &[T], state: &mut H) {
244-
for piece in data {
245-
piece.hash(state)
246-
}
247-
}
248-
const fn ct<T: Hash, H: Hasher>(data: &[T], state: &mut H) {
249-
let mut i = 0;
250-
while i < data.len() {
251-
data[i].hash(state);
252-
i += 1;
253-
}
241+
for piece in data {
242+
piece.hash(state)
254243
}
255-
// SAFETY: same behavior, CT just uses while instead of for
256-
unsafe { const_eval_select((data, state), ct, rt) };
257244
}
258245
}
259246

library/core/src/hash/sip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ macro_rules! load_int_le {
118118
/// Safety: this performs unchecked indexing of `buf` at `start..start+len`, so
119119
/// that must be in-bounds.
120120
#[inline]
121-
const unsafe fn u8to64_le(buf: &[u8], start: usize, len: usize) -> u64 {
121+
unsafe fn u8to64_le(buf: &[u8], start: usize, len: usize) -> u64 {
122122
debug_assert!(len < 8);
123123
let mut i = 0; // current byte index (from LSB) in the output u64
124124
let mut out = 0;

library/core/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@
112112
#![feature(const_caller_location)]
113113
#![feature(const_cell_into_inner)]
114114
#![feature(const_char_from_u32_unchecked)]
115-
#![feature(const_cmp)]
116115
#![feature(const_cstr_methods)]
117116
#![feature(const_discriminant)]
118117
#![feature(const_eval_select)]
@@ -128,7 +127,6 @@
128127
#![feature(const_intrinsic_forget)]
129128
#![feature(const_ipv4)]
130129
#![feature(const_ipv6)]
131-
#![feature(const_is_char_boundary)]
132130
#![feature(const_likely)]
133131
#![feature(const_maybe_uninit_as_mut_ptr)]
134132
#![feature(const_maybe_uninit_assume_init)]
@@ -146,7 +144,6 @@
146144
#![feature(const_ptr_write)]
147145
#![feature(const_raw_ptr_comparison)]
148146
#![feature(const_replace)]
149-
#![feature(const_result_drop)]
150147
#![feature(const_size_of_val)]
151148
#![feature(const_size_of_val_raw)]
152149
#![feature(const_slice_from_raw_parts_mut)]

library/core/src/ops/range.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
116116
/// assert!(!(f32::NAN..1.0).contains(&0.5));
117117
/// ```
118118
#[stable(feature = "range_contains", since = "1.35.0")]
119-
#[rustc_const_unstable(feature = "const_range_bounds", issue = "108082")]
120-
pub const fn contains<U>(&self, item: &U) -> bool
119+
pub fn contains<U>(&self, item: &U) -> bool
121120
where
122121
Idx: PartialOrd<U>,
123122
U: ?Sized + PartialOrd<Idx>,
@@ -143,8 +142,7 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
143142
/// assert!( (f32::NAN..5.0).is_empty());
144143
/// ```
145144
#[stable(feature = "range_is_empty", since = "1.47.0")]
146-
#[rustc_const_unstable(feature = "const_range_bounds", issue = "108082")]
147-
pub const fn is_empty(&self) -> bool {
145+
pub fn is_empty(&self) -> bool {
148146
!(self.start < self.end)
149147
}
150148
}
@@ -538,9 +536,8 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
538536
/// assert!(r.is_empty());
539537
/// ```
540538
#[stable(feature = "range_is_empty", since = "1.47.0")]
541-
#[rustc_const_unstable(feature = "const_range_bounds", issue = "108082")]
542539
#[inline]
543-
pub const fn is_empty(&self) -> bool {
540+
pub fn is_empty(&self) -> bool {
544541
self.exhausted || !(self.start <= self.end)
545542
}
546543
}

library/core/src/ops/try_trait.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,7 @@ impl<T> NeverShortCircuit<T> {
386386
}
387387

388388
#[inline]
389-
pub fn wrap_mut_2<A, B>(
390-
mut f: impl FnMut(A, B) -> T,
391-
) -> impl FnMut(A, B) -> Self {
389+
pub fn wrap_mut_2<A, B>(mut f: impl FnMut(A, B) -> T) -> impl FnMut(A, B) -> Self {
392390
move |a, b| NeverShortCircuit(f(a, b))
393391
}
394392
}

0 commit comments

Comments
 (0)