Skip to content

33 files changed

+84
-112
lines changed
 

‎src/libcore/alloc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use num::NonZeroUsize;
2525
#[derive(Debug)]
2626
pub struct Excess(pub NonNull<u8>, pub usize);
2727

28-
fn size_align<T>() -> (usize, usize) {
28+
const fn size_align<T>() -> (usize, usize) {
2929
(mem::size_of::<T>(), mem::align_of::<T>())
3030
}
3131

@@ -116,7 +116,7 @@ impl Layout {
116116
/// The minimum size in bytes for a memory block of this layout.
117117
#[stable(feature = "alloc_layout", since = "1.28.0")]
118118
#[inline]
119-
pub fn size(&self) -> usize { self.size_ }
119+
pub const fn size(&self) -> usize { self.size_ }
120120

121121
/// The minimum byte alignment for a memory block of this layout.
122122
#[stable(feature = "alloc_layout", since = "1.28.0")]

‎src/libcore/array.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl TryFromSliceError {
7777
issue = "0")]
7878
#[inline]
7979
#[doc(hidden)]
80-
pub fn __description(&self) -> &str {
80+
pub const fn __description(&self) -> &str {
8181
"could not convert slice to array"
8282
}
8383
}

‎src/libcore/benches/iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn bench_multiple_take(b: &mut Bencher) {
3939
});
4040
}
4141

42-
fn scatter(x: i32) -> i32 { (x * 31) % 127 }
42+
const fn scatter(x: i32) -> i32 { (x * 31) % 127 }
4343

4444
#[bench]
4545
fn bench_max_by_key(b: &mut Bencher) {

‎src/libcore/cell.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ impl<T: ?Sized> Cell<T> {
474474
/// ```
475475
#[inline]
476476
#[stable(feature = "cell_as_ptr", since = "1.12.0")]
477-
pub fn as_ptr(&self) -> *mut T {
477+
pub const fn as_ptr(&self) -> *mut T {
478478
self.value.get()
479479
}
480480

@@ -636,12 +636,12 @@ type BorrowFlag = isize;
636636
const UNUSED: BorrowFlag = 0;
637637

638638
#[inline(always)]
639-
fn is_writing(x: BorrowFlag) -> bool {
639+
const fn is_writing(x: BorrowFlag) -> bool {
640640
x < UNUSED
641641
}
642642

643643
#[inline(always)]
644-
fn is_reading(x: BorrowFlag) -> bool {
644+
const fn is_reading(x: BorrowFlag) -> bool {
645645
x > UNUSED
646646
}
647647

@@ -1508,7 +1508,7 @@ impl<T: ?Sized> UnsafeCell<T> {
15081508
/// ```
15091509
#[inline]
15101510
#[stable(feature = "rust1", since = "1.0.0")]
1511-
pub fn get(&self) -> *mut T {
1511+
pub const fn get(&self) -> *mut T {
15121512
&self.value as *const T as *mut T
15131513
}
15141514
}

‎src/libcore/char/decode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl<I: Iterator<Item = u16>> Iterator for DecodeUtf16<I> {
130130
impl DecodeUtf16Error {
131131
/// Returns the unpaired surrogate which caused this error.
132132
#[stable(feature = "decode_utf16", since = "1.9.0")]
133-
pub fn unpaired_surrogate(&self) -> u16 {
133+
pub const fn unpaired_surrogate(&self) -> u16 {
134134
self.code
135135
}
136136
}

‎src/libcore/char/methods.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ impl char {
903903
/// ```
904904
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
905905
#[inline]
906-
pub fn is_ascii(&self) -> bool {
906+
pub const fn is_ascii(&self) -> bool {
907907
*self as u32 <= 0x7F
908908
}
909909

‎src/libcore/convert.rs

-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@
104104
/// assert_eq!(vec![1, 3], filtered);
105105
/// ```
106106
#[unstable(feature = "convert_id", issue = "53500")]
107-
#[rustc_const_unstable(feature = "const_convert_id")]
108107
#[inline]
109108
pub const fn identity<T>(x: T) -> T { x }
110109

‎src/libcore/fmt/mod.rs

+21-11
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ impl<'a> Arguments<'a> {
341341
#[doc(hidden)] #[inline]
342342
#[unstable(feature = "fmt_internals", reason = "internal to format_args!",
343343
issue = "0")]
344-
pub fn new_v1(pieces: &'a [&'a str],
344+
pub const fn new_v1(pieces: &'a [&'a str],
345345
args: &'a [ArgumentV1<'a>]) -> Arguments<'a> {
346346
Arguments {
347347
pieces,
@@ -359,7 +359,7 @@ impl<'a> Arguments<'a> {
359359
#[doc(hidden)] #[inline]
360360
#[unstable(feature = "fmt_internals", reason = "internal to format_args!",
361361
issue = "0")]
362-
pub fn new_v1_formatted(pieces: &'a [&'a str],
362+
pub const fn new_v1_formatted(pieces: &'a [&'a str],
363363
args: &'a [ArgumentV1<'a>],
364364
fmt: &'a [rt::v1::Argument]) -> Arguments<'a> {
365365
Arguments {
@@ -1492,7 +1492,7 @@ impl<'a> Formatter<'a> {
14921492
/// assert_eq!(&format!("{:t>6}", Foo), "tttttt");
14931493
/// ```
14941494
#[stable(feature = "fmt_flags", since = "1.5.0")]
1495-
pub fn fill(&self) -> char { self.fill }
1495+
pub const fn fill(&self) -> char { self.fill }
14961496

14971497
/// Flag indicating what form of alignment was requested.
14981498
///
@@ -1562,7 +1562,7 @@ impl<'a> Formatter<'a> {
15621562
/// assert_eq!(&format!("{}", Foo(23)), "Foo(23)");
15631563
/// ```
15641564
#[stable(feature = "fmt_flags", since = "1.5.0")]
1565-
pub fn width(&self) -> Option<usize> { self.width }
1565+
pub const fn width(&self) -> Option<usize> { self.width }
15661566

15671567
/// Optionally specified precision for numeric types.
15681568
///
@@ -1589,7 +1589,7 @@ impl<'a> Formatter<'a> {
15891589
/// assert_eq!(&format!("{}", Foo(23.2)), "Foo(23.20)");
15901590
/// ```
15911591
#[stable(feature = "fmt_flags", since = "1.5.0")]
1592-
pub fn precision(&self) -> Option<usize> { self.precision }
1592+
pub const fn precision(&self) -> Option<usize> { self.precision }
15931593

15941594
/// Determines if the `+` flag was specified.
15951595
///
@@ -1617,7 +1617,9 @@ impl<'a> Formatter<'a> {
16171617
/// assert_eq!(&format!("{}", Foo(23)), "Foo(23)");
16181618
/// ```
16191619
#[stable(feature = "fmt_flags", since = "1.5.0")]
1620-
pub fn sign_plus(&self) -> bool { self.flags & (1 << FlagV1::SignPlus as u32) != 0 }
1620+
pub const fn sign_plus(&self) -> bool {
1621+
self.flags & (1 << FlagV1::SignPlus as u32) != 0
1622+
}
16211623

16221624
/// Determines if the `-` flag was specified.
16231625
///
@@ -1643,7 +1645,9 @@ impl<'a> Formatter<'a> {
16431645
/// assert_eq!(&format!("{}", Foo(23)), "Foo(23)");
16441646
/// ```
16451647
#[stable(feature = "fmt_flags", since = "1.5.0")]
1646-
pub fn sign_minus(&self) -> bool { self.flags & (1 << FlagV1::SignMinus as u32) != 0 }
1648+
pub const fn sign_minus(&self) -> bool {
1649+
self.flags & (1 << FlagV1::SignMinus as u32) != 0
1650+
}
16471651

16481652
/// Determines if the `#` flag was specified.
16491653
///
@@ -1668,7 +1672,9 @@ impl<'a> Formatter<'a> {
16681672
/// assert_eq!(&format!("{}", Foo(23)), "23");
16691673
/// ```
16701674
#[stable(feature = "fmt_flags", since = "1.5.0")]
1671-
pub fn alternate(&self) -> bool { self.flags & (1 << FlagV1::Alternate as u32) != 0 }
1675+
pub const fn alternate(&self) -> bool {
1676+
self.flags & (1 << FlagV1::Alternate as u32) != 0
1677+
}
16721678

16731679
/// Determines if the `0` flag was specified.
16741680
///
@@ -1691,15 +1697,19 @@ impl<'a> Formatter<'a> {
16911697
/// assert_eq!(&format!("{:04}", Foo(23)), "23");
16921698
/// ```
16931699
#[stable(feature = "fmt_flags", since = "1.5.0")]
1694-
pub fn sign_aware_zero_pad(&self) -> bool {
1700+
pub const fn sign_aware_zero_pad(&self) -> bool {
16951701
self.flags & (1 << FlagV1::SignAwareZeroPad as u32) != 0
16961702
}
16971703

16981704
// FIXME: Decide what public API we want for these two flags.
16991705
// https://github.com/rust-lang/rust/issues/48584
1700-
fn debug_lower_hex(&self) -> bool { self.flags & (1 << FlagV1::DebugLowerHex as u32) != 0 }
1706+
const fn debug_lower_hex(&self) -> bool {
1707+
self.flags & (1 << FlagV1::DebugLowerHex as u32) != 0
1708+
}
17011709

1702-
fn debug_upper_hex(&self) -> bool { self.flags & (1 << FlagV1::DebugUpperHex as u32) != 0 }
1710+
const fn debug_upper_hex(&self) -> bool {
1711+
self.flags & (1 << FlagV1::DebugUpperHex as u32) != 0
1712+
}
17031713

17041714
/// Creates a [`DebugStruct`] builder designed to assist with creation of
17051715
/// [`fmt::Debug`] implementations for structs.

‎src/libcore/iter/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2658,7 +2658,7 @@ impl<I, U> FusedIterator for Flatten<I>
26582658
I::Item: IntoIterator<IntoIter = U, Item = U::Item> {}
26592659

26602660
/// Adapts an iterator by flattening it, for use in `flatten()` and `flat_map()`.
2661-
fn flatten_compat<I, U>(iter: I) -> FlattenCompat<I, U> {
2661+
const fn flatten_compat<I, U>(iter: I) -> FlattenCompat<I, U> {
26622662
FlattenCompat { iter, frontiter: None, backiter: None }
26632663
}
26642664

‎src/libcore/iter/sources.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ impl<T> Default for Empty<T> {
283283
/// assert_eq!(None, nope.next());
284284
/// ```
285285
#[stable(feature = "iter_empty", since = "1.2.0")]
286-
pub fn empty<T>() -> Empty<T> {
286+
pub const fn empty<T>() -> Empty<T> {
287287
Empty(marker::PhantomData)
288288
}
289289

‎src/libcore/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
#![feature(const_fn)]
8383
#![feature(const_int_ops)]
8484
#![feature(const_fn_union)]
85-
#![feature(const_manually_drop_new)]
8685
#![feature(custom_attribute)]
8786
#![feature(doc_cfg)]
8887
#![feature(doc_spotlight)]

‎src/libcore/mem.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub use intrinsics::transmute;
139139
/// [ub]: ../../reference/behavior-considered-undefined.html
140140
#[inline]
141141
#[stable(feature = "rust1", since = "1.0.0")]
142-
pub fn forget<T>(t: T) {
142+
pub const fn forget<T>(t: T) {
143143
ManuallyDrop::new(t);
144144
}
145145

@@ -942,7 +942,6 @@ impl<T> ManuallyDrop<T> {
942942
/// ManuallyDrop::new(Box::new(()));
943943
/// ```
944944
#[stable(feature = "manually_drop", since = "1.20.0")]
945-
#[rustc_const_unstable(feature = "const_manually_drop_new")]
946945
#[inline]
947946
pub const fn new(value: T) -> ManuallyDrop<T> {
948947
ManuallyDrop { value }
@@ -961,7 +960,7 @@ impl<T> ManuallyDrop<T> {
961960
/// ```
962961
#[stable(feature = "manually_drop", since = "1.20.0")]
963962
#[inline]
964-
pub fn into_inner(slot: ManuallyDrop<T>) -> T {
963+
pub const fn into_inner(slot: ManuallyDrop<T>) -> T {
965964
slot.value
966965
}
967966

‎src/libcore/num/dec2flt/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,11 @@ impl fmt::Display for ParseFloatError {
187187
}
188188
}
189189

190-
fn pfe_empty() -> ParseFloatError {
190+
const fn pfe_empty() -> ParseFloatError {
191191
ParseFloatError { kind: FloatErrorKind::Empty }
192192
}
193193

194-
fn pfe_invalid() -> ParseFloatError {
194+
const fn pfe_invalid() -> ParseFloatError {
195195
ParseFloatError { kind: FloatErrorKind::Invalid }
196196
}
197197

‎src/libcore/num/dec2flt/parse.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub struct Decimal<'a> {
3939
}
4040

4141
impl<'a> Decimal<'a> {
42-
pub fn new(integral: &'a [u8], fractional: &'a [u8], exp: i64) -> Decimal<'a> {
42+
pub const fn new(integral: &'a [u8], fractional: &'a [u8], exp: i64) -> Decimal<'a> {
4343
Decimal { integral, fractional, exp }
4444
}
4545
}

‎src/libcore/num/dec2flt/rawfp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub struct Unpacked {
4444
}
4545

4646
impl Unpacked {
47-
pub fn new(sig: u64, k: i16) -> Self {
47+
pub const fn new(sig: u64, k: i16) -> Self {
4848
Unpacked { sig, k }
4949
}
5050
}

‎src/libcore/num/flt2dec/estimator.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515
/// This is used to approximate `k = ceil(log_10 (mant * 2^exp))`;
1616
/// the true `k` is either `k_0` or `k_0+1`.
1717
#[doc(hidden)]
18-
pub fn estimate_scaling_factor(mant: u64, exp: i16) -> i16 {
18+
pub const fn estimate_scaling_factor(mant: u64, exp: i16) -> i16 {
1919
// 2^(nbits-1) < mant <= 2^nbits if mant > 0
2020
let nbits = 64 - (mant - 1).leading_zeros() as i64;
2121
// 1292913986 = floor(2^32 * log_10 2)
2222
// therefore this always underestimates (or is exact), but not much.
2323
(((nbits + exp as i64) * 1292913986) >> 32) as i16
2424
}
25-

‎src/libcore/num/flt2dec/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -658,4 +658,3 @@ pub fn to_exact_fixed_str<'a, T, F>(mut format_exact: F, v: T,
658658
}
659659
}
660660
}
661-

0 commit comments

Comments
 (0)
Please sign in to comment.