diff --git a/src/libcore/alloc.rs b/src/libcore/alloc.rs index 113a85abecb..8b9f7f2c816 100644 --- a/src/libcore/alloc.rs +++ b/src/libcore/alloc.rs @@ -25,7 +25,7 @@ use num::NonZeroUsize; #[derive(Debug)] pub struct Excess(pub NonNull, pub usize); -fn size_align() -> (usize, usize) { +const fn size_align() -> (usize, usize) { (mem::size_of::(), mem::align_of::()) } @@ -116,7 +116,7 @@ impl Layout { /// The minimum size in bytes for a memory block of this layout. #[stable(feature = "alloc_layout", since = "1.28.0")] #[inline] - pub fn size(&self) -> usize { self.size_ } + pub const fn size(&self) -> usize { self.size_ } /// The minimum byte alignment for a memory block of this layout. #[stable(feature = "alloc_layout", since = "1.28.0")] diff --git a/src/libcore/array.rs b/src/libcore/array.rs index 3d24f8902bd..0bea541e163 100644 --- a/src/libcore/array.rs +++ b/src/libcore/array.rs @@ -77,7 +77,7 @@ impl TryFromSliceError { issue = "0")] #[inline] #[doc(hidden)] - pub fn __description(&self) -> &str { + pub const fn __description(&self) -> &str { "could not convert slice to array" } } diff --git a/src/libcore/benches/iter.rs b/src/libcore/benches/iter.rs index 6c597301ac2..c8b8c2eff97 100644 --- a/src/libcore/benches/iter.rs +++ b/src/libcore/benches/iter.rs @@ -39,7 +39,7 @@ fn bench_multiple_take(b: &mut Bencher) { }); } -fn scatter(x: i32) -> i32 { (x * 31) % 127 } +const fn scatter(x: i32) -> i32 { (x * 31) % 127 } #[bench] fn bench_max_by_key(b: &mut Bencher) { diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 689cf319bd7..3fe77fe688f 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -474,7 +474,7 @@ impl Cell { /// ``` #[inline] #[stable(feature = "cell_as_ptr", since = "1.12.0")] - pub fn as_ptr(&self) -> *mut T { + pub const fn as_ptr(&self) -> *mut T { self.value.get() } @@ -636,12 +636,12 @@ type BorrowFlag = isize; const UNUSED: BorrowFlag = 0; #[inline(always)] -fn is_writing(x: BorrowFlag) -> bool { +const fn is_writing(x: BorrowFlag) -> bool { x < UNUSED } #[inline(always)] -fn is_reading(x: BorrowFlag) -> bool { +const fn is_reading(x: BorrowFlag) -> bool { x > UNUSED } @@ -1508,7 +1508,7 @@ impl UnsafeCell { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub fn get(&self) -> *mut T { + pub const fn get(&self) -> *mut T { &self.value as *const T as *mut T } } diff --git a/src/libcore/char/decode.rs b/src/libcore/char/decode.rs index cc52f048b89..bcd1e92c6d8 100644 --- a/src/libcore/char/decode.rs +++ b/src/libcore/char/decode.rs @@ -130,7 +130,7 @@ impl> Iterator for DecodeUtf16 { impl DecodeUtf16Error { /// Returns the unpaired surrogate which caused this error. #[stable(feature = "decode_utf16", since = "1.9.0")] - pub fn unpaired_surrogate(&self) -> u16 { + pub const fn unpaired_surrogate(&self) -> u16 { self.code } } diff --git a/src/libcore/char/methods.rs b/src/libcore/char/methods.rs index 64a17786b0a..35181afea3d 100644 --- a/src/libcore/char/methods.rs +++ b/src/libcore/char/methods.rs @@ -903,7 +903,7 @@ impl char { /// ``` #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] #[inline] - pub fn is_ascii(&self) -> bool { + pub const fn is_ascii(&self) -> bool { *self as u32 <= 0x7F } diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index b900990d0a7..dbc28ef7cf6 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -104,7 +104,6 @@ /// assert_eq!(vec![1, 3], filtered); /// ``` #[unstable(feature = "convert_id", issue = "53500")] -#[rustc_const_unstable(feature = "const_convert_id")] #[inline] pub const fn identity(x: T) -> T { x } diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 75ec0d7d50b..56576f8334b 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -341,7 +341,7 @@ impl<'a> Arguments<'a> { #[doc(hidden)] #[inline] #[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "0")] - pub fn new_v1(pieces: &'a [&'a str], + pub const fn new_v1(pieces: &'a [&'a str], args: &'a [ArgumentV1<'a>]) -> Arguments<'a> { Arguments { pieces, @@ -359,7 +359,7 @@ impl<'a> Arguments<'a> { #[doc(hidden)] #[inline] #[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "0")] - pub fn new_v1_formatted(pieces: &'a [&'a str], + pub const fn new_v1_formatted(pieces: &'a [&'a str], args: &'a [ArgumentV1<'a>], fmt: &'a [rt::v1::Argument]) -> Arguments<'a> { Arguments { @@ -1492,7 +1492,7 @@ impl<'a> Formatter<'a> { /// assert_eq!(&format!("{:t>6}", Foo), "tttttt"); /// ``` #[stable(feature = "fmt_flags", since = "1.5.0")] - pub fn fill(&self) -> char { self.fill } + pub const fn fill(&self) -> char { self.fill } /// Flag indicating what form of alignment was requested. /// @@ -1562,7 +1562,7 @@ impl<'a> Formatter<'a> { /// assert_eq!(&format!("{}", Foo(23)), "Foo(23)"); /// ``` #[stable(feature = "fmt_flags", since = "1.5.0")] - pub fn width(&self) -> Option { self.width } + pub const fn width(&self) -> Option { self.width } /// Optionally specified precision for numeric types. /// @@ -1589,7 +1589,7 @@ impl<'a> Formatter<'a> { /// assert_eq!(&format!("{}", Foo(23.2)), "Foo(23.20)"); /// ``` #[stable(feature = "fmt_flags", since = "1.5.0")] - pub fn precision(&self) -> Option { self.precision } + pub const fn precision(&self) -> Option { self.precision } /// Determines if the `+` flag was specified. /// @@ -1617,7 +1617,9 @@ impl<'a> Formatter<'a> { /// assert_eq!(&format!("{}", Foo(23)), "Foo(23)"); /// ``` #[stable(feature = "fmt_flags", since = "1.5.0")] - pub fn sign_plus(&self) -> bool { self.flags & (1 << FlagV1::SignPlus as u32) != 0 } + pub const fn sign_plus(&self) -> bool { + self.flags & (1 << FlagV1::SignPlus as u32) != 0 + } /// Determines if the `-` flag was specified. /// @@ -1643,7 +1645,9 @@ impl<'a> Formatter<'a> { /// assert_eq!(&format!("{}", Foo(23)), "Foo(23)"); /// ``` #[stable(feature = "fmt_flags", since = "1.5.0")] - pub fn sign_minus(&self) -> bool { self.flags & (1 << FlagV1::SignMinus as u32) != 0 } + pub const fn sign_minus(&self) -> bool { + self.flags & (1 << FlagV1::SignMinus as u32) != 0 + } /// Determines if the `#` flag was specified. /// @@ -1668,7 +1672,9 @@ impl<'a> Formatter<'a> { /// assert_eq!(&format!("{}", Foo(23)), "23"); /// ``` #[stable(feature = "fmt_flags", since = "1.5.0")] - pub fn alternate(&self) -> bool { self.flags & (1 << FlagV1::Alternate as u32) != 0 } + pub const fn alternate(&self) -> bool { + self.flags & (1 << FlagV1::Alternate as u32) != 0 + } /// Determines if the `0` flag was specified. /// @@ -1691,15 +1697,19 @@ impl<'a> Formatter<'a> { /// assert_eq!(&format!("{:04}", Foo(23)), "23"); /// ``` #[stable(feature = "fmt_flags", since = "1.5.0")] - pub fn sign_aware_zero_pad(&self) -> bool { + pub const fn sign_aware_zero_pad(&self) -> bool { self.flags & (1 << FlagV1::SignAwareZeroPad as u32) != 0 } // FIXME: Decide what public API we want for these two flags. // https://github.com/rust-lang/rust/issues/48584 - fn debug_lower_hex(&self) -> bool { self.flags & (1 << FlagV1::DebugLowerHex as u32) != 0 } + const fn debug_lower_hex(&self) -> bool { + self.flags & (1 << FlagV1::DebugLowerHex as u32) != 0 + } - fn debug_upper_hex(&self) -> bool { self.flags & (1 << FlagV1::DebugUpperHex as u32) != 0 } + const fn debug_upper_hex(&self) -> bool { + self.flags & (1 << FlagV1::DebugUpperHex as u32) != 0 + } /// Creates a [`DebugStruct`] builder designed to assist with creation of /// [`fmt::Debug`] implementations for structs. diff --git a/src/libcore/iter/mod.rs b/src/libcore/iter/mod.rs index c42fb7019c7..72a032b57d0 100644 --- a/src/libcore/iter/mod.rs +++ b/src/libcore/iter/mod.rs @@ -2658,7 +2658,7 @@ impl FusedIterator for Flatten I::Item: IntoIterator {} /// Adapts an iterator by flattening it, for use in `flatten()` and `flat_map()`. -fn flatten_compat(iter: I) -> FlattenCompat { +const fn flatten_compat(iter: I) -> FlattenCompat { FlattenCompat { iter, frontiter: None, backiter: None } } diff --git a/src/libcore/iter/sources.rs b/src/libcore/iter/sources.rs index d500cc99fa1..7fa3a4bcce7 100644 --- a/src/libcore/iter/sources.rs +++ b/src/libcore/iter/sources.rs @@ -283,7 +283,7 @@ impl Default for Empty { /// assert_eq!(None, nope.next()); /// ``` #[stable(feature = "iter_empty", since = "1.2.0")] -pub fn empty() -> Empty { +pub const fn empty() -> Empty { Empty(marker::PhantomData) } diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 1bbc7892c6b..2445d936927 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -82,7 +82,6 @@ #![feature(const_fn)] #![feature(const_int_ops)] #![feature(const_fn_union)] -#![feature(const_manually_drop_new)] #![feature(custom_attribute)] #![feature(doc_cfg)] #![feature(doc_spotlight)] diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 1d0b194487e..0aa374c7a64 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -139,7 +139,7 @@ pub use intrinsics::transmute; /// [ub]: ../../reference/behavior-considered-undefined.html #[inline] #[stable(feature = "rust1", since = "1.0.0")] -pub fn forget(t: T) { +pub const fn forget(t: T) { ManuallyDrop::new(t); } @@ -942,7 +942,6 @@ impl ManuallyDrop { /// ManuallyDrop::new(Box::new(())); /// ``` #[stable(feature = "manually_drop", since = "1.20.0")] - #[rustc_const_unstable(feature = "const_manually_drop_new")] #[inline] pub const fn new(value: T) -> ManuallyDrop { ManuallyDrop { value } @@ -961,7 +960,7 @@ impl ManuallyDrop { /// ``` #[stable(feature = "manually_drop", since = "1.20.0")] #[inline] - pub fn into_inner(slot: ManuallyDrop) -> T { + pub const fn into_inner(slot: ManuallyDrop) -> T { slot.value } diff --git a/src/libcore/num/dec2flt/mod.rs b/src/libcore/num/dec2flt/mod.rs index f93564c2849..0e1f6664d96 100644 --- a/src/libcore/num/dec2flt/mod.rs +++ b/src/libcore/num/dec2flt/mod.rs @@ -187,11 +187,11 @@ impl fmt::Display for ParseFloatError { } } -fn pfe_empty() -> ParseFloatError { +const fn pfe_empty() -> ParseFloatError { ParseFloatError { kind: FloatErrorKind::Empty } } -fn pfe_invalid() -> ParseFloatError { +const fn pfe_invalid() -> ParseFloatError { ParseFloatError { kind: FloatErrorKind::Invalid } } diff --git a/src/libcore/num/dec2flt/parse.rs b/src/libcore/num/dec2flt/parse.rs index e7ed94d4d91..8d8f357425e 100644 --- a/src/libcore/num/dec2flt/parse.rs +++ b/src/libcore/num/dec2flt/parse.rs @@ -39,7 +39,7 @@ pub struct Decimal<'a> { } impl<'a> Decimal<'a> { - pub fn new(integral: &'a [u8], fractional: &'a [u8], exp: i64) -> Decimal<'a> { + pub const fn new(integral: &'a [u8], fractional: &'a [u8], exp: i64) -> Decimal<'a> { Decimal { integral, fractional, exp } } } diff --git a/src/libcore/num/dec2flt/rawfp.rs b/src/libcore/num/dec2flt/rawfp.rs index 38f4e4687a9..c5d4aa68958 100644 --- a/src/libcore/num/dec2flt/rawfp.rs +++ b/src/libcore/num/dec2flt/rawfp.rs @@ -44,7 +44,7 @@ pub struct Unpacked { } impl Unpacked { - pub fn new(sig: u64, k: i16) -> Self { + pub const fn new(sig: u64, k: i16) -> Self { Unpacked { sig, k } } } diff --git a/src/libcore/num/flt2dec/estimator.rs b/src/libcore/num/flt2dec/estimator.rs index d42e05a91f1..2a87bf43664 100644 --- a/src/libcore/num/flt2dec/estimator.rs +++ b/src/libcore/num/flt2dec/estimator.rs @@ -15,11 +15,10 @@ /// This is used to approximate `k = ceil(log_10 (mant * 2^exp))`; /// the true `k` is either `k_0` or `k_0+1`. #[doc(hidden)] -pub fn estimate_scaling_factor(mant: u64, exp: i16) -> i16 { +pub const fn estimate_scaling_factor(mant: u64, exp: i16) -> i16 { // 2^(nbits-1) < mant <= 2^nbits if mant > 0 let nbits = 64 - (mant - 1).leading_zeros() as i64; // 1292913986 = floor(2^32 * log_10 2) // therefore this always underestimates (or is exact), but not much. (((nbits + exp as i64) * 1292913986) >> 32) as i16 } - diff --git a/src/libcore/num/flt2dec/mod.rs b/src/libcore/num/flt2dec/mod.rs index 21a2e72dac8..d58015beecb 100644 --- a/src/libcore/num/flt2dec/mod.rs +++ b/src/libcore/num/flt2dec/mod.rs @@ -658,4 +658,3 @@ pub fn to_exact_fixed_str<'a, T, F>(mut format_exact: F, v: T, } } } - diff --git a/src/libcore/num/wrapping.rs b/src/libcore/num/wrapping.rs index 1c826c2fa76..00134a58d30 100644 --- a/src/libcore/num/wrapping.rs +++ b/src/libcore/num/wrapping.rs @@ -387,7 +387,7 @@ assert_eq!(n.count_ones(), 3); ```"), #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn count_ones(self) -> u32 { + pub const fn count_ones(self) -> u32 { self.0.count_ones() } } @@ -407,7 +407,7 @@ assert_eq!(Wrapping(!0", stringify!($t), ").count_zeros(), 0); ```"), #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn count_zeros(self) -> u32 { + pub const fn count_zeros(self) -> u32 { self.0.count_zeros() } } @@ -430,7 +430,7 @@ assert_eq!(n.trailing_zeros(), 3); ```"), #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn trailing_zeros(self) -> u32 { + pub const fn trailing_zeros(self) -> u32 { self.0.trailing_zeros() } } @@ -456,7 +456,7 @@ assert_eq!(n.trailing_zeros(), 3); /// ``` #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn rotate_left(self, n: u32) -> Self { + pub const fn rotate_left(self, n: u32) -> Self { Wrapping(self.0.rotate_left(n)) } @@ -481,7 +481,7 @@ assert_eq!(n.trailing_zeros(), 3); /// ``` #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn rotate_right(self, n: u32) -> Self { + pub const fn rotate_right(self, n: u32) -> Self { Wrapping(self.0.rotate_right(n)) } @@ -505,7 +505,7 @@ assert_eq!(n.trailing_zeros(), 3); /// ``` #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn swap_bytes(self) -> Self { + pub const fn swap_bytes(self) -> Self { Wrapping(self.0.swap_bytes()) } @@ -532,7 +532,7 @@ assert_eq!(n.trailing_zeros(), 3); /// ``` #[unstable(feature = "reverse_bits", issue = "48763")] #[inline] - pub fn reverse_bits(self) -> Self { + pub const fn reverse_bits(self) -> Self { Wrapping(self.0.reverse_bits()) } @@ -560,7 +560,7 @@ if cfg!(target_endian = \"big\") { ```"), #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn from_be(x: Self) -> Self { + pub const fn from_be(x: Self) -> Self { Wrapping(<$t>::from_be(x.0)) } } @@ -589,7 +589,7 @@ if cfg!(target_endian = \"little\") { ```"), #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn from_le(x: Self) -> Self { + pub const fn from_le(x: Self) -> Self { Wrapping(<$t>::from_le(x.0)) } } @@ -618,7 +618,7 @@ if cfg!(target_endian = \"big\") { ```"), #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn to_be(self) -> Self { + pub const fn to_be(self) -> Self { Wrapping(self.0.to_be()) } } @@ -647,7 +647,7 @@ if cfg!(target_endian = \"little\") { ```"), #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn to_le(self) -> Self { + pub const fn to_le(self) -> Self { Wrapping(self.0.to_le()) } } @@ -707,7 +707,7 @@ assert_eq!(n.leading_zeros(), 3); ```"), #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn leading_zeros(self) -> u32 { + pub const fn leading_zeros(self) -> u32 { self.0.leading_zeros() } } @@ -784,7 +784,7 @@ assert!(!Wrapping(-10", stringify!($t), ").is_positive()); ```"), #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn is_positive(self) -> bool { + pub const fn is_positive(self) -> bool { self.0.is_positive() } } @@ -806,7 +806,7 @@ assert!(!Wrapping(10", stringify!($t), ").is_negative()); ```"), #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn is_negative(self) -> bool { + pub const fn is_negative(self) -> bool { self.0.is_negative() } } @@ -836,7 +836,7 @@ assert_eq!(n.leading_zeros(), 2); ```"), #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] - pub fn leading_zeros(self) -> u32 { + pub const fn leading_zeros(self) -> u32 { self.0.leading_zeros() } } diff --git a/src/libcore/ops/range.rs b/src/libcore/ops/range.rs index 6cfb1005325..908490e1c83 100644 --- a/src/libcore/ops/range.rs +++ b/src/libcore/ops/range.rs @@ -416,7 +416,7 @@ impl RangeInclusive { /// ``` #[stable(feature = "inclusive_range_methods", since = "1.27.0")] #[inline] - pub fn start(&self) -> &Idx { + pub const fn start(&self) -> &Idx { &self.start } @@ -440,7 +440,7 @@ impl RangeInclusive { /// ``` #[stable(feature = "inclusive_range_methods", since = "1.27.0")] #[inline] - pub fn end(&self) -> &Idx { + pub const fn end(&self) -> &Idx { &self.end } diff --git a/src/libcore/panic.rs b/src/libcore/panic.rs index f0efeb59e8d..af9d1596938 100644 --- a/src/libcore/panic.rs +++ b/src/libcore/panic.rs @@ -55,7 +55,7 @@ impl<'a> PanicInfo<'a> { issue = "0")] #[doc(hidden)] #[inline] - pub fn internal_constructor(message: Option<&'a fmt::Arguments<'a>>, + pub const fn internal_constructor(message: Option<&'a fmt::Arguments<'a>>, location: Location<'a>) -> Self { struct NoPayload; @@ -96,7 +96,7 @@ impl<'a> PanicInfo<'a> { /// /// [`fmt::write`]: ../fmt/fn.write.html #[unstable(feature = "panic_info_message", issue = "44489")] - pub fn message(&self) -> Option<&fmt::Arguments> { + pub const fn message(&self) -> Option<&fmt::Arguments> { self.message } @@ -125,7 +125,7 @@ impl<'a> PanicInfo<'a> { /// panic!("Normal panic"); /// ``` #[stable(feature = "panic_hooks", since = "1.10.0")] - pub fn location(&self) -> Option<&Location> { + pub const fn location(&self) -> Option<&Location> { // NOTE: If this is changed to sometimes return None, // deal with that case in std::panicking::default_hook and std::panicking::begin_panic_fmt. Some(&self.location) @@ -186,7 +186,7 @@ impl<'a> Location<'a> { and related macros", issue = "0")] #[doc(hidden)] - pub fn internal_constructor(file: &'a str, line: u32, col: u32) -> Self { + pub const fn internal_constructor(file: &'a str, line: u32, col: u32) -> Self { Location { file, line, col } } @@ -208,7 +208,7 @@ impl<'a> Location<'a> { /// panic!("Normal panic"); /// ``` #[stable(feature = "panic_hooks", since = "1.10.0")] - pub fn file(&self) -> &str { + pub const fn file(&self) -> &str { self.file } @@ -230,7 +230,7 @@ impl<'a> Location<'a> { /// panic!("Normal panic"); /// ``` #[stable(feature = "panic_hooks", since = "1.10.0")] - pub fn line(&self) -> u32 { + pub const fn line(&self) -> u32 { self.line } @@ -252,7 +252,7 @@ impl<'a> Location<'a> { /// panic!("Normal panic"); /// ``` #[stable(feature = "panic_col", since = "1.25.0")] - pub fn column(&self) -> u32 { + pub const fn column(&self) -> u32 { self.col } } diff --git a/src/libcore/pin.rs b/src/libcore/pin.rs index 68de82d2945..63a433a8b23 100644 --- a/src/libcore/pin.rs +++ b/src/libcore/pin.rs @@ -207,7 +207,7 @@ impl<'a, T: ?Sized> Pin<&'a T> { /// with the same lifetime as the original `Pin`. #[unstable(feature = "pin", issue = "49150")] #[inline(always)] - pub fn get_ref(this: Pin<&'a T>) -> &'a T { + pub const fn get_ref(this: Pin<&'a T>) -> &'a T { this.pointer } } @@ -216,7 +216,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> { /// Convert this `Pin<&mut T>` into a `Pin<&T>` with the same lifetime. #[unstable(feature = "pin", issue = "49150")] #[inline(always)] - pub fn into_ref(this: Pin<&'a mut T>) -> Pin<&'a T> { + pub const fn into_ref(this: Pin<&'a mut T>) -> Pin<&'a T> { Pin { pointer: this.pointer } } diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 62ccf6c865c..c06e580e30e 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -2759,7 +2759,7 @@ impl Unique { } /// Acquires the underlying `*mut` pointer. - pub fn as_ptr(self) -> *mut T { + pub const fn as_ptr(self) -> *mut T { self.pointer.0 as *mut T } @@ -2905,7 +2905,7 @@ impl NonNull { /// Acquires the underlying `*mut` pointer. #[stable(feature = "nonnull", since = "1.25.0")] #[inline] - pub fn as_ptr(self) -> *mut T { + pub const fn as_ptr(self) -> *mut T { self.pointer.0 as *mut T } diff --git a/src/libcore/slice/memchr.rs b/src/libcore/slice/memchr.rs index cf95333af9c..deaeb53e84a 100644 --- a/src/libcore/slice/memchr.rs +++ b/src/libcore/slice/memchr.rs @@ -29,19 +29,19 @@ const HI_USIZE: usize = HI_U64 as usize; /// bytes where the borrow propagated all the way to the most significant /// bit." #[inline] -fn contains_zero_byte(x: usize) -> bool { +const fn contains_zero_byte(x: usize) -> bool { x.wrapping_sub(LO_USIZE) & !x & HI_USIZE != 0 } #[cfg(target_pointer_width = "16")] #[inline] -fn repeat_byte(b: u8) -> usize { +const fn repeat_byte(b: u8) -> usize { (b as usize) << 8 | b as usize } #[cfg(not(target_pointer_width = "16"))] #[inline] -fn repeat_byte(b: u8) -> usize { +const fn repeat_byte(b: u8) -> usize { (b as usize) * (::usize::MAX / 255) } diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 8a6b212020b..f8dee537062 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -385,7 +385,6 @@ impl [T] { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - #[rustc_const_unstable(feature = "const_slice_as_ptr")] pub const fn as_ptr(&self) -> *const T { self as *const [T] as *const T } @@ -2738,7 +2737,7 @@ impl<'a, T> IntoIterator for &'a mut [T] { // Macro helper functions #[inline(always)] -fn size_from_ptr(_: *const T) -> usize { +const fn size_from_ptr(_: *const T) -> usize { mem::size_of::() } @@ -4022,7 +4021,7 @@ impl<'a, T> ChunksExact<'a, T> { /// returned by the iterator. The returned slice has at most `chunk_size-1` /// elements. #[stable(feature = "chunks_exact", since = "1.31.0")] - pub fn remainder(&self) -> &'a [T] { + pub const fn remainder(&self) -> &'a [T] { self.rem } } @@ -4518,7 +4517,7 @@ impl<'a, T> RChunksExact<'a, T> { /// returned by the iterator. The returned slice has at most `chunk_size-1` /// elements. #[stable(feature = "rchunks", since = "1.31.0")] - pub fn remainder(&self) -> &'a [T] { + pub const fn remainder(&self) -> &'a [T] { self.rem } } diff --git a/src/libcore/str/lossy.rs b/src/libcore/str/lossy.rs index 186d6adbc91..950552fc6b1 100644 --- a/src/libcore/str/lossy.rs +++ b/src/libcore/str/lossy.rs @@ -29,7 +29,7 @@ impl Utf8Lossy { unsafe { mem::transmute(bytes) } } - pub fn chunks(&self) -> Utf8LossyChunksIter { + pub const fn chunks(&self) -> Utf8LossyChunksIter { Utf8LossyChunksIter { source: &self.bytes } } } diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index a2782dd8e2e..d73e5db727c 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -231,7 +231,7 @@ impl Utf8Error { /// assert_eq!(1, error.valid_up_to()); /// ``` #[stable(feature = "utf8_error", since = "1.5.0")] - pub fn valid_up_to(&self) -> usize { self.valid_up_to } + pub const fn valid_up_to(&self) -> usize { self.valid_up_to } /// Provide more information about the failure: /// @@ -476,16 +476,16 @@ pub struct Chars<'a> { /// The first byte is special, only want bottom 5 bits for width 2, 4 bits /// for width 3, and 3 bits for width 4. #[inline] -fn utf8_first_byte(byte: u8, width: u32) -> u32 { (byte & (0x7F >> width)) as u32 } +const fn utf8_first_byte(byte: u8, width: u32) -> u32 { (byte & (0x7F >> width)) as u32 } /// Returns the value of `ch` updated with continuation byte `byte`. #[inline] -fn utf8_acc_cont_byte(ch: u32, byte: u8) -> u32 { (ch << 6) | (byte & CONT_MASK) as u32 } +const fn utf8_acc_cont_byte(ch: u32, byte: u8) -> u32 { (ch << 6) | (byte & CONT_MASK) as u32 } /// Checks whether the byte is a UTF-8 continuation byte (i.e. starts with the /// bits `10`). #[inline] -fn utf8_is_cont_byte(byte: u8) -> bool { (byte & !CONT_MASK) == TAG_CONT_U8 } +const fn utf8_is_cont_byte(byte: u8) -> bool { (byte & !CONT_MASK) == TAG_CONT_U8 } #[inline] fn unwrap_or_0(opt: Option<&u8>) -> u8 { @@ -1420,7 +1420,7 @@ const NONASCII_MASK: usize = 0x80808080_80808080u64 as usize; /// Returns `true` if any byte in the word `x` is nonascii (>= 128). #[inline] -fn contains_nonascii(x: usize) -> bool { +const fn contains_nonascii(x: usize) -> bool { (x & NONASCII_MASK) != 0 } @@ -2277,7 +2277,6 @@ impl str { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - #[rustc_const_unstable(feature = "const_str_as_ptr")] pub const fn as_ptr(&self) -> *const u8 { self as *const str as *const u8 } diff --git a/src/libcore/task/wake.rs b/src/libcore/task/wake.rs index c9fb22e0080..1db3a290e04 100644 --- a/src/libcore/task/wake.rs +++ b/src/libcore/task/wake.rs @@ -141,7 +141,7 @@ impl LocalWaker { /// `Waker` is nearly identical to `LocalWaker`, but is threadsafe /// (implements `Send` and `Sync`). #[inline] - pub fn as_waker(&self) -> &Waker { + pub const fn as_waker(&self) -> &Waker { &self.0 } diff --git a/src/libcore/unicode/bool_trie.rs b/src/libcore/unicode/bool_trie.rs index 0e6437fded5..995795839b7 100644 --- a/src/libcore/unicode/bool_trie.rs +++ b/src/libcore/unicode/bool_trie.rs @@ -71,6 +71,6 @@ impl SmallBoolTrie { } } -fn trie_range_leaf(c: u32, bitmap_chunk: u64) -> bool { +const fn trie_range_leaf(c: u32, bitmap_chunk: u64) -> bool { ((bitmap_chunk >> (c & 63)) & 1) != 0 } diff --git a/src/libcore/unicode/tables.rs b/src/libcore/unicode/tables.rs index 3de855ac943..e525c057400 100644 --- a/src/libcore/unicode/tables.rs +++ b/src/libcore/unicode/tables.rs @@ -2598,4 +2598,3 @@ pub mod conversions { ]; } - diff --git a/src/test/ui/consts/const-eval/duration_conversion.rs b/src/test/ui/consts/const-eval/duration_conversion.rs index 4481b758404..c8bed4a2b77 100644 --- a/src/test/ui/consts/const-eval/duration_conversion.rs +++ b/src/test/ui/consts/const-eval/duration_conversion.rs @@ -10,8 +10,6 @@ // compile-pass -#![feature(duration_getters)] - use std::time::Duration; fn main() { diff --git a/src/test/ui/rfc-2306/convert-id-const-no-gate.rs b/src/test/ui/rfc-2306/convert-id-const-no-gate.rs deleted file mode 100644 index 545c179dec9..00000000000 --- a/src/test/ui/rfc-2306/convert-id-const-no-gate.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// This test should fail since identity is not stable as a const fn yet. - -#![feature(convert_id)] - -fn main() { - const _FOO: u8 = ::std::convert::identity(42u8); -} diff --git a/src/test/ui/rfc-2306/convert-id-const-no-gate.stderr b/src/test/ui/rfc-2306/convert-id-const-no-gate.stderr deleted file mode 100644 index dfd8619d875..00000000000 --- a/src/test/ui/rfc-2306/convert-id-const-no-gate.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: `std::convert::identity` is not yet stable as a const fn - --> $DIR/convert-id-const-no-gate.rs:16:22 - | -LL | const _FOO: u8 = ::std::convert::identity(42u8); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: in Nightly builds, add `#![feature(const_convert_id)]` to the crate attributes to enable - -error: aborting due to previous error - diff --git a/src/test/ui/rfc-2306/convert-id-const-with-gate.rs b/src/test/ui/rfc-2306/convert-id-const-with-gate.rs index c546f11914f..2e71aee57c2 100644 --- a/src/test/ui/rfc-2306/convert-id-const-with-gate.rs +++ b/src/test/ui/rfc-2306/convert-id-const-with-gate.rs @@ -8,12 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// This test should pass since we've opted into 'identity' as an -// unstable const fn. +// This test should pass since 'identity' is const fn. // compile-pass -#![feature(convert_id, const_convert_id)] +#![feature(convert_id)] fn main() { const _FOO: u8 = ::std::convert::identity(42u8);