constify parts of libcore.
This commit is contained in:
parent
b4c046b342
commit
5b89877dda
33 changed files with 84 additions and 112 deletions
|
@ -25,7 +25,7 @@ use num::NonZeroUsize;
|
|||
#[derive(Debug)]
|
||||
pub struct Excess(pub NonNull<u8>, pub usize);
|
||||
|
||||
fn size_align<T>() -> (usize, usize) {
|
||||
const fn size_align<T>() -> (usize, usize) {
|
||||
(mem::size_of::<T>(), mem::align_of::<T>())
|
||||
}
|
||||
|
||||
|
@ -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")]
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -474,7 +474,7 @@ impl<T: ?Sized> Cell<T> {
|
|||
/// ```
|
||||
#[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<T: ?Sized> UnsafeCell<T> {
|
|||
/// ```
|
||||
#[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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ impl<I: Iterator<Item = u16>> Iterator for DecodeUtf16<I> {
|
|||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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<T>(x: T) -> T { x }
|
||||
|
||||
|
|
|
@ -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<usize> { self.width }
|
||||
pub const fn width(&self) -> Option<usize> { 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<usize> { self.precision }
|
||||
pub const fn precision(&self) -> Option<usize> { 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.
|
||||
|
|
|
@ -2658,7 +2658,7 @@ impl<I, U> FusedIterator for Flatten<I>
|
|||
I::Item: IntoIterator<IntoIter = U, Item = U::Item> {}
|
||||
|
||||
/// Adapts an iterator by flattening it, for use in `flatten()` and `flat_map()`.
|
||||
fn flatten_compat<I, U>(iter: I) -> FlattenCompat<I, U> {
|
||||
const fn flatten_compat<I, U>(iter: I) -> FlattenCompat<I, U> {
|
||||
FlattenCompat { iter, frontiter: None, backiter: None }
|
||||
}
|
||||
|
||||
|
|
|
@ -283,7 +283,7 @@ impl<T> Default for Empty<T> {
|
|||
/// assert_eq!(None, nope.next());
|
||||
/// ```
|
||||
#[stable(feature = "iter_empty", since = "1.2.0")]
|
||||
pub fn empty<T>() -> Empty<T> {
|
||||
pub const fn empty<T>() -> Empty<T> {
|
||||
Empty(marker::PhantomData)
|
||||
}
|
||||
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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: T) {
|
||||
pub const fn forget<T>(t: T) {
|
||||
ManuallyDrop::new(t);
|
||||
}
|
||||
|
||||
|
@ -942,7 +942,6 @@ impl<T> ManuallyDrop<T> {
|
|||
/// 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<T> {
|
||||
ManuallyDrop { value }
|
||||
|
@ -961,7 +960,7 @@ impl<T> ManuallyDrop<T> {
|
|||
/// ```
|
||||
#[stable(feature = "manually_drop", since = "1.20.0")]
|
||||
#[inline]
|
||||
pub fn into_inner(slot: ManuallyDrop<T>) -> T {
|
||||
pub const fn into_inner(slot: ManuallyDrop<T>) -> T {
|
||||
slot.value
|
||||
}
|
||||
|
||||
|
|
|
@ -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 }
|
||||
}
|
||||
|
||||
|
|
|
@ -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 }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -658,4 +658,3 @@ pub fn to_exact_fixed_str<'a, T, F>(mut format_exact: F, v: T,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -416,7 +416,7 @@ impl<Idx> RangeInclusive<Idx> {
|
|||
/// ```
|
||||
#[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<Idx> RangeInclusive<Idx> {
|
|||
/// ```
|
||||
#[stable(feature = "inclusive_range_methods", since = "1.27.0")]
|
||||
#[inline]
|
||||
pub fn end(&self) -> &Idx {
|
||||
pub const fn end(&self) -> &Idx {
|
||||
&self.end
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 }
|
||||
}
|
||||
|
||||
|
|
|
@ -2759,7 +2759,7 @@ impl<T: ?Sized> Unique<T> {
|
|||
}
|
||||
|
||||
/// 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<T: ?Sized> NonNull<T> {
|
|||
/// 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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -385,7 +385,6 @@ impl<T> [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<T>(_: *const T) -> usize {
|
||||
const fn size_from_ptr<T>(_: *const T) -> usize {
|
||||
mem::size_of::<T>()
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -2598,4 +2598,3 @@ pub mod conversions {
|
|||
];
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -10,8 +10,6 @@
|
|||
|
||||
// compile-pass
|
||||
|
||||
#![feature(duration_getters)]
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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);
|
||||
}
|
|
@ -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
|
||||
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue