#[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>())
}
/// 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")]
issue = "0")]
#[inline]
#[doc(hidden)]
- pub fn __description(&self) -> &str {
+ pub const fn __description(&self) -> &str {
"could not convert slice to array"
}
}
});
}
-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) {
/// ```
#[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()
}
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
}
/// ```
#[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
}
}
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
}
}
/// ```
#[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
}
/// 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 }
#[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,
#[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 {
/// 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.
///
/// 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.
///
/// 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.
///
/// 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.
///
/// 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.
///
/// 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.
///
/// 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.
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 }
}
/// 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)
}
#![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)]
/// [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);
}
/// 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 }
/// ```
#[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
}
}
}
-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 }
}
}
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 }
}
}
}
impl Unpacked {
- pub fn new(sig: u64, k: i16) -> Self {
+ pub const fn new(sig: u64, k: i16) -> Self {
Unpacked { sig, k }
}
}
/// 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
}
-
```"),
#[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()
}
}
```"),
#[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()
}
}
```"),
#[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()
}
}
/// ```
#[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))
}
/// ```
#[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))
}
/// ```
#[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())
}
/// ```
#[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())
}
```"),
#[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))
}
}
```"),
#[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))
}
}
```"),
#[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())
}
}
```"),
#[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())
}
}
```"),
#[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()
}
}
```"),
#[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()
}
}
```"),
#[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()
}
}
```"),
#[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()
}
}
/// ```
#[stable(feature = "inclusive_range_methods", since = "1.27.0")]
#[inline]
- pub fn start(&self) -> &Idx {
+ pub const fn start(&self) -> &Idx {
&self.start
}
/// ```
#[stable(feature = "inclusive_range_methods", since = "1.27.0")]
#[inline]
- pub fn end(&self) -> &Idx {
+ pub const fn end(&self) -> &Idx {
&self.end
}
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;
///
/// [`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
}
/// 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)
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 }
}
/// panic!("Normal panic");
/// ```
#[stable(feature = "panic_hooks", since = "1.10.0")]
- pub fn file(&self) -> &str {
+ pub const fn file(&self) -> &str {
self.file
}
/// panic!("Normal panic");
/// ```
#[stable(feature = "panic_hooks", since = "1.10.0")]
- pub fn line(&self) -> u32 {
+ pub const fn line(&self) -> u32 {
self.line
}
/// panic!("Normal panic");
/// ```
#[stable(feature = "panic_col", since = "1.25.0")]
- pub fn column(&self) -> u32 {
+ pub const fn column(&self) -> u32 {
self.col
}
}
/// 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
}
}
/// 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 }
}
}
/// 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
}
/// 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
}
/// 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)
}
/// ```
#[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
}
// 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>()
}
/// 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
}
}
/// 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
}
}
unsafe { mem::transmute(bytes) }
}
- pub fn chunks(&self) -> Utf8LossyChunksIter {
+ pub const fn chunks(&self) -> Utf8LossyChunksIter {
Utf8LossyChunksIter { source: &self.bytes }
}
}
/// 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:
///
/// 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 {
/// 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
}
/// ```
#[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
}
/// `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
}
}
}
-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
}
// compile-pass
-#![feature(duration_getters)]
-
use std::time::Duration;
fn main() {
+++ /dev/null
-// 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);
-}
+++ /dev/null
-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
-
// 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);