mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Auto merge of #110393 - fee1-dead-contrib:rm-const-traits, r=oli-obk
Rm const traits in libcore See [zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/.60const.20Trait.60.20removal.20or.20rework) * [x] Bless ui tests * [ ] Re constify some unstable functions with workarounds if they are needed
This commit is contained in:
commit
3a5c8e91f0
@ -10,7 +10,6 @@
|
||||
)]
|
||||
#![feature(associated_type_bounds)]
|
||||
#![feature(box_patterns)]
|
||||
#![feature(const_default_impls)]
|
||||
#![feature(const_trait_impl)]
|
||||
#![feature(if_let_guard)]
|
||||
#![feature(let_chains)]
|
||||
|
@ -126,7 +126,8 @@ impl<S: Encoder, T: Encodable<S>> Encodable<S> for P<T> {
|
||||
}
|
||||
|
||||
impl<T> P<[T]> {
|
||||
pub const fn new() -> P<[T]> {
|
||||
// FIXME(const-hack) make this const again
|
||||
pub fn new() -> P<[T]> {
|
||||
P { ptr: Box::default() }
|
||||
}
|
||||
|
||||
|
@ -610,10 +610,11 @@ pub struct RawPtrComparison;
|
||||
impl<'tcx> NonConstOp<'tcx> for RawPtrComparison {
|
||||
fn build_error(
|
||||
&self,
|
||||
_: &ConstCx<'_, 'tcx>,
|
||||
ccx: &ConstCx<'_, 'tcx>,
|
||||
span: Span,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||
span_bug!(span, "raw ptr comparison should already be caught in the trait system");
|
||||
// FIXME(const_trait_impl): revert to span_bug?
|
||||
ccx.tcx.sess.create_err(errors::RawPtrComparisonErr { span })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -576,8 +576,7 @@ impl<T, A: Allocator> Box<T, A> {
|
||||
///
|
||||
/// This conversion does not allocate on the heap and happens in place.
|
||||
#[unstable(feature = "box_into_boxed_slice", issue = "71582")]
|
||||
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
|
||||
pub const fn into_boxed_slice(boxed: Self) -> Box<[T], A> {
|
||||
pub fn into_boxed_slice(boxed: Self) -> Box<[T], A> {
|
||||
let (raw, alloc) = Box::into_raw_with_allocator(boxed);
|
||||
unsafe { Box::from_raw_in(raw as *mut [T; 1], alloc) }
|
||||
}
|
||||
@ -809,9 +808,8 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
|
||||
/// assert_eq!(*five, 5)
|
||||
/// ```
|
||||
#[unstable(feature = "new_uninit", issue = "63291")]
|
||||
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
|
||||
#[inline]
|
||||
pub const unsafe fn assume_init(self) -> Box<T, A> {
|
||||
pub unsafe fn assume_init(self) -> Box<T, A> {
|
||||
let (raw, alloc) = Box::into_raw_with_allocator(self);
|
||||
unsafe { Box::from_raw_in(raw as *mut T, alloc) }
|
||||
}
|
||||
@ -844,9 +842,8 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
|
||||
/// }
|
||||
/// ```
|
||||
#[unstable(feature = "new_uninit", issue = "63291")]
|
||||
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
|
||||
#[inline]
|
||||
pub const fn write(mut boxed: Self, value: T) -> Box<T, A> {
|
||||
pub fn write(mut boxed: Self, value: T) -> Box<T, A> {
|
||||
unsafe {
|
||||
(*boxed).write(value);
|
||||
boxed.assume_init()
|
||||
@ -1090,9 +1087,8 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
|
||||
///
|
||||
/// [memory layout]: self#memory-layout
|
||||
#[unstable(feature = "allocator_api", issue = "32838")]
|
||||
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
|
||||
#[inline]
|
||||
pub const fn into_raw_with_allocator(b: Self) -> (*mut T, A) {
|
||||
pub fn into_raw_with_allocator(b: Self) -> (*mut T, A) {
|
||||
let (leaked, alloc) = Box::into_unique(b);
|
||||
(leaked.as_ptr(), alloc)
|
||||
}
|
||||
@ -1102,10 +1098,9 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
|
||||
issue = "none",
|
||||
reason = "use `Box::leak(b).into()` or `Unique::from(Box::leak(b))` instead"
|
||||
)]
|
||||
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
|
||||
#[inline]
|
||||
#[doc(hidden)]
|
||||
pub const fn into_unique(b: Self) -> (Unique<T>, A) {
|
||||
pub fn into_unique(b: Self) -> (Unique<T>, A) {
|
||||
// Box is recognized as a "unique pointer" by Stacked Borrows, but internally it is a
|
||||
// raw pointer for the type system. Turning it directly into a raw pointer would not be
|
||||
// recognized as "releasing" the unique pointer to permit aliased raw accesses,
|
||||
@ -1163,9 +1158,8 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
|
||||
/// assert_eq!(*static_ref, [4, 2, 3]);
|
||||
/// ```
|
||||
#[stable(feature = "box_leak", since = "1.26.0")]
|
||||
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
|
||||
#[inline]
|
||||
pub const fn leak<'a>(b: Self) -> &'a mut T
|
||||
pub fn leak<'a>(b: Self) -> &'a mut T
|
||||
where
|
||||
A: 'a,
|
||||
{
|
||||
@ -1234,8 +1228,7 @@ impl<T: Default> Default for Box<T> {
|
||||
|
||||
#[cfg(not(no_global_oom_handling))]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
|
||||
impl<T> const Default for Box<[T]> {
|
||||
impl<T> Default for Box<[T]> {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
let ptr: Unique<[T]> = Unique::<[T; 0]>::dangling();
|
||||
@ -1245,8 +1238,7 @@ impl<T> const Default for Box<[T]> {
|
||||
|
||||
#[cfg(not(no_global_oom_handling))]
|
||||
#[stable(feature = "default_box_extra", since = "1.17.0")]
|
||||
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
|
||||
impl const Default for Box<str> {
|
||||
impl Default for Box<str> {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
// SAFETY: This is the same as `Unique::cast<U>` but with an unsized `U = str`.
|
||||
@ -1443,8 +1435,7 @@ impl<T> From<T> for Box<T> {
|
||||
}
|
||||
|
||||
#[stable(feature = "pin", since = "1.33.0")]
|
||||
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
|
||||
impl<T: ?Sized, A: Allocator> const From<Box<T, A>> for Pin<Box<T, A>>
|
||||
impl<T: ?Sized, A: Allocator> From<Box<T, A>> for Pin<Box<T, A>>
|
||||
where
|
||||
A: 'static,
|
||||
{
|
||||
@ -1880,8 +1871,7 @@ impl<T: ?Sized, A: Allocator> fmt::Pointer for Box<T, A> {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
|
||||
impl<T: ?Sized, A: Allocator> const Deref for Box<T, A> {
|
||||
impl<T: ?Sized, A: Allocator> Deref for Box<T, A> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &T {
|
||||
@ -1890,8 +1880,7 @@ impl<T: ?Sized, A: Allocator> const Deref for Box<T, A> {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
|
||||
impl<T: ?Sized, A: Allocator> const DerefMut for Box<T, A> {
|
||||
impl<T: ?Sized, A: Allocator> DerefMut for Box<T, A> {
|
||||
fn deref_mut(&mut self) -> &mut T {
|
||||
&mut **self
|
||||
}
|
||||
|
@ -106,7 +106,6 @@
|
||||
#![feature(coerce_unsized)]
|
||||
#![feature(const_align_of_val)]
|
||||
#![feature(const_box)]
|
||||
#![feature(const_convert)]
|
||||
#![feature(const_cow_is_borrowed)]
|
||||
#![feature(const_eval_select)]
|
||||
#![feature(const_maybe_uninit_as_mut_ptr)]
|
||||
@ -174,7 +173,6 @@
|
||||
#![feature(associated_type_bounds)]
|
||||
#![feature(c_unwind)]
|
||||
#![feature(cfg_sanitize)]
|
||||
#![feature(const_deref)]
|
||||
#![feature(const_mut_refs)]
|
||||
#![feature(const_precise_live_drops)]
|
||||
#![feature(const_ptr_write)]
|
||||
|
@ -2247,8 +2247,7 @@ impl_eq! { Cow<'a, str>, &'b str }
|
||||
impl_eq! { Cow<'a, str>, String }
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
|
||||
impl const Default for String {
|
||||
impl Default for String {
|
||||
/// Creates an empty `String`.
|
||||
#[inline]
|
||||
fn default() -> String {
|
||||
|
@ -3022,8 +3022,7 @@ unsafe impl<#[may_dangle] T, A: Allocator> Drop for Vec<T, A> {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
|
||||
impl<T> const Default for Vec<T> {
|
||||
impl<T> Default for Vec<T> {
|
||||
/// Creates an empty `Vec<T>`.
|
||||
///
|
||||
/// The vector will not allocate until elements are pushed onto it.
|
||||
|
@ -61,7 +61,7 @@ fn box_deref_lval() {
|
||||
|
||||
pub struct ConstAllocator;
|
||||
|
||||
unsafe impl const Allocator for ConstAllocator {
|
||||
unsafe impl Allocator for ConstAllocator {
|
||||
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
|
||||
match layout.size() {
|
||||
0 => Ok(NonNull::slice_from_raw_parts(layout.dangling(), 0)),
|
||||
|
@ -1,13 +1,16 @@
|
||||
// Test const functions in the library
|
||||
|
||||
pub const MY_VEC: Vec<usize> = Vec::new();
|
||||
pub const MY_VEC2: Vec<usize> = Default::default();
|
||||
|
||||
// FIXME(#110395)
|
||||
// pub const MY_VEC2: Vec<usize> = Default::default();
|
||||
|
||||
pub const MY_STRING: String = String::new();
|
||||
pub const MY_STRING2: String = Default::default();
|
||||
|
||||
pub const MY_BOXED_SLICE: Box<[usize]> = Default::default();
|
||||
pub const MY_BOXED_STR: Box<str> = Default::default();
|
||||
// pub const MY_STRING2: String = Default::default();
|
||||
|
||||
// pub const MY_BOXED_SLICE: Box<[usize]> = Default::default();
|
||||
// pub const MY_BOXED_STR: Box<str> = Default::default();
|
||||
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
@ -23,11 +26,11 @@ pub const SET_IS_EMPTY: bool = SET.is_empty();
|
||||
|
||||
#[test]
|
||||
fn test_const() {
|
||||
assert_eq!(MY_VEC, MY_VEC2);
|
||||
assert_eq!(MY_STRING, MY_STRING2);
|
||||
assert_eq!(MY_VEC, /* MY_VEC */ vec![]);
|
||||
assert_eq!(MY_STRING, /* MY_STRING2 */ String::default());
|
||||
|
||||
assert_eq!(MY_VEC, *MY_BOXED_SLICE);
|
||||
assert_eq!(MY_STRING, *MY_BOXED_STR);
|
||||
// assert_eq!(MY_VEC, *MY_BOXED_SLICE);
|
||||
// assert_eq!(MY_STRING, *MY_BOXED_STR);
|
||||
|
||||
assert_eq!(MAP_LEN, 0);
|
||||
assert_eq!(SET_LEN, 0);
|
||||
|
@ -3,7 +3,6 @@
|
||||
#![feature(assert_matches)]
|
||||
#![feature(btree_drain_filter)]
|
||||
#![feature(cow_is_borrowed)]
|
||||
#![feature(const_convert)]
|
||||
#![feature(const_cow_is_borrowed)]
|
||||
#![feature(const_heap)]
|
||||
#![feature(const_mut_refs)]
|
||||
@ -33,7 +32,6 @@
|
||||
#![feature(slice_partition_dedup)]
|
||||
#![feature(string_remove_matches)]
|
||||
#![feature(const_btree_len)]
|
||||
#![feature(const_default_impls)]
|
||||
#![feature(const_trait_impl)]
|
||||
#![feature(const_str_from_utf8)]
|
||||
#![feature(panic_update_hook)]
|
||||
|
@ -231,9 +231,8 @@ impl Layout {
|
||||
/// Returns an error if the combination of `self.size()` and the given
|
||||
/// `align` violates the conditions listed in [`Layout::from_size_align`].
|
||||
#[stable(feature = "alloc_layout_manipulation", since = "1.44.0")]
|
||||
#[rustc_const_unstable(feature = "const_alloc_layout", issue = "67521")]
|
||||
#[inline]
|
||||
pub const fn align_to(&self, align: usize) -> Result<Self, LayoutError> {
|
||||
pub fn align_to(&self, align: usize) -> Result<Self, LayoutError> {
|
||||
Layout::from_size_align(self.size(), cmp::max(self.align(), align))
|
||||
}
|
||||
|
||||
@ -315,9 +314,8 @@ impl Layout {
|
||||
///
|
||||
/// On arithmetic overflow, returns `LayoutError`.
|
||||
#[unstable(feature = "alloc_layout_extra", issue = "55724")]
|
||||
#[rustc_const_unstable(feature = "const_alloc_layout", issue = "67521")]
|
||||
#[inline]
|
||||
pub const fn repeat(&self, n: usize) -> Result<(Self, usize), LayoutError> {
|
||||
pub fn repeat(&self, n: usize) -> Result<(Self, usize), LayoutError> {
|
||||
// This cannot overflow. Quoting from the invariant of Layout:
|
||||
// > `size`, when rounded up to the nearest multiple of `align`,
|
||||
// > must not overflow isize (i.e., the rounded value must be
|
||||
@ -376,9 +374,8 @@ impl Layout {
|
||||
/// # assert_eq!(repr_c(&[u64, u32, u16, u32]), Ok((s, vec![0, 8, 12, 16])));
|
||||
/// ```
|
||||
#[stable(feature = "alloc_layout_manipulation", since = "1.44.0")]
|
||||
#[rustc_const_unstable(feature = "const_alloc_layout", issue = "67521")]
|
||||
#[inline]
|
||||
pub const fn extend(&self, next: Self) -> Result<(Self, usize), LayoutError> {
|
||||
pub fn extend(&self, next: Self) -> Result<(Self, usize), LayoutError> {
|
||||
let new_align = cmp::max(self.align, next.align);
|
||||
let pad = self.padding_needed_for(next.align());
|
||||
|
||||
@ -403,9 +400,8 @@ impl Layout {
|
||||
///
|
||||
/// On arithmetic overflow, returns `LayoutError`.
|
||||
#[unstable(feature = "alloc_layout_extra", issue = "55724")]
|
||||
#[rustc_const_unstable(feature = "const_alloc_layout", issue = "67521")]
|
||||
#[inline]
|
||||
pub const fn repeat_packed(&self, n: usize) -> Result<Self, LayoutError> {
|
||||
pub fn repeat_packed(&self, n: usize) -> Result<Self, LayoutError> {
|
||||
let size = self.size().checked_mul(n).ok_or(LayoutError)?;
|
||||
// The safe constructor is called here to enforce the isize size limit.
|
||||
Layout::from_size_alignment(size, self.align)
|
||||
@ -418,9 +414,8 @@ impl Layout {
|
||||
///
|
||||
/// On arithmetic overflow, returns `LayoutError`.
|
||||
#[unstable(feature = "alloc_layout_extra", issue = "55724")]
|
||||
#[rustc_const_unstable(feature = "const_alloc_layout", issue = "67521")]
|
||||
#[inline]
|
||||
pub const fn extend_packed(&self, next: Self) -> Result<Self, LayoutError> {
|
||||
pub fn extend_packed(&self, next: Self) -> Result<Self, LayoutError> {
|
||||
let new_size = self.size().checked_add(next.size()).ok_or(LayoutError)?;
|
||||
// The safe constructor is called here to enforce the isize size limit.
|
||||
Layout::from_size_alignment(new_size, self.align)
|
||||
|
@ -105,7 +105,6 @@ impl fmt::Display for AllocError {
|
||||
///
|
||||
/// [*currently allocated*]: #currently-allocated-memory
|
||||
#[unstable(feature = "allocator_api", issue = "32838")]
|
||||
#[const_trait]
|
||||
pub unsafe trait Allocator {
|
||||
/// Attempts to allocate a block of memory.
|
||||
///
|
||||
|
@ -662,8 +662,7 @@ impl dyn Any + Send + Sync {
|
||||
/// While `TypeId` implements `Hash`, `PartialOrd`, and `Ord`, it is worth
|
||||
/// noting that the hashes and ordering will vary between Rust releases. Beware
|
||||
/// of relying on them inside of your code!
|
||||
#[derive(Clone, Copy, Debug, Hash, Eq)]
|
||||
#[derive_const(PartialEq, PartialOrd, Ord)]
|
||||
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct TypeId {
|
||||
t: u64,
|
||||
|
@ -148,8 +148,7 @@ impl Error for TryFromSliceError {
|
||||
}
|
||||
|
||||
#[stable(feature = "try_from_slice_error", since = "1.36.0")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl const From<Infallible> for TryFromSliceError {
|
||||
impl From<Infallible> for TryFromSliceError {
|
||||
fn from(x: Infallible) -> TryFromSliceError {
|
||||
match x {}
|
||||
}
|
||||
@ -172,16 +171,14 @@ impl<T, const N: usize> AsMut<[T]> for [T; N] {
|
||||
}
|
||||
|
||||
#[stable(feature = "array_borrow", since = "1.4.0")]
|
||||
#[rustc_const_unstable(feature = "const_borrow", issue = "91522")]
|
||||
impl<T, const N: usize> const Borrow<[T]> for [T; N] {
|
||||
impl<T, const N: usize> Borrow<[T]> for [T; N] {
|
||||
fn borrow(&self) -> &[T] {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "array_borrow", since = "1.4.0")]
|
||||
#[rustc_const_unstable(feature = "const_borrow", issue = "91522")]
|
||||
impl<T, const N: usize> const BorrowMut<[T]> for [T; N] {
|
||||
impl<T, const N: usize> BorrowMut<[T]> for [T; N] {
|
||||
fn borrow_mut(&mut self) -> &mut [T] {
|
||||
self
|
||||
}
|
||||
@ -336,10 +333,9 @@ impl<'a, T, const N: usize> IntoIterator for &'a mut [T; N] {
|
||||
}
|
||||
|
||||
#[stable(feature = "index_trait_on_arrays", since = "1.50.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
impl<T, I, const N: usize> const Index<I> for [T; N]
|
||||
impl<T, I, const N: usize> Index<I> for [T; N]
|
||||
where
|
||||
[T]: ~const Index<I>,
|
||||
[T]: Index<I>,
|
||||
{
|
||||
type Output = <[T] as Index<I>>::Output;
|
||||
|
||||
@ -350,10 +346,9 @@ where
|
||||
}
|
||||
|
||||
#[stable(feature = "index_trait_on_arrays", since = "1.50.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
impl<T, I, const N: usize> const IndexMut<I> for [T; N]
|
||||
impl<T, I, const N: usize> IndexMut<I> for [T; N]
|
||||
where
|
||||
[T]: ~const IndexMut<I>,
|
||||
[T]: IndexMut<I>,
|
||||
{
|
||||
#[inline]
|
||||
fn index_mut(&mut self, index: I) -> &mut Self::Output {
|
||||
@ -435,8 +430,7 @@ impl<T: Copy> SpecArrayClone for T {
|
||||
macro_rules! array_impl_default {
|
||||
{$n:expr, $t:ident $($ts:ident)*} => {
|
||||
#[stable(since = "1.4.0", feature = "array_default")]
|
||||
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
|
||||
impl<T> const Default for [T; $n] where T: ~const Default {
|
||||
impl<T> Default for [T; $n] where T: Default {
|
||||
fn default() -> [T; $n] {
|
||||
[$t::default(), $($ts::default()),*]
|
||||
}
|
||||
@ -445,8 +439,7 @@ macro_rules! array_impl_default {
|
||||
};
|
||||
{$n:expr,} => {
|
||||
#[stable(since = "1.4.0", feature = "array_default")]
|
||||
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
|
||||
impl<T> const Default for [T; $n] {
|
||||
impl<T> Default for [T; $n] {
|
||||
fn default() -> [T; $n] { [] }
|
||||
}
|
||||
};
|
||||
|
@ -1,7 +1,5 @@
|
||||
//! impl bool {}
|
||||
|
||||
use crate::marker::Destruct;
|
||||
|
||||
impl bool {
|
||||
/// Returns `Some(t)` if the `bool` is [`true`](../std/keyword.true.html),
|
||||
/// or `None` otherwise.
|
||||
@ -31,12 +29,8 @@ impl bool {
|
||||
/// assert_eq!(a, 2);
|
||||
/// ```
|
||||
#[stable(feature = "bool_to_option", since = "1.62.0")]
|
||||
#[rustc_const_unstable(feature = "const_bool_to_option", issue = "91917")]
|
||||
#[inline]
|
||||
pub const fn then_some<T>(self, t: T) -> Option<T>
|
||||
where
|
||||
T: ~const Destruct,
|
||||
{
|
||||
pub fn then_some<T>(self, t: T) -> Option<T> {
|
||||
if self { Some(t) } else { None }
|
||||
}
|
||||
|
||||
@ -61,13 +55,8 @@ impl bool {
|
||||
/// assert_eq!(a, 1);
|
||||
/// ```
|
||||
#[stable(feature = "lazy_bool_to_option", since = "1.50.0")]
|
||||
#[rustc_const_unstable(feature = "const_bool_to_option", issue = "91917")]
|
||||
#[inline]
|
||||
pub const fn then<T, F>(self, f: F) -> Option<T>
|
||||
where
|
||||
F: ~const FnOnce() -> T,
|
||||
F: ~const Destruct,
|
||||
{
|
||||
pub fn then<T, F: FnOnce() -> T>(self, f: F) -> Option<T> {
|
||||
if self { Some(f()) } else { None }
|
||||
}
|
||||
}
|
||||
|
@ -154,7 +154,6 @@
|
||||
/// [`String`]: ../../std/string/struct.String.html
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_diagnostic_item = "Borrow"]
|
||||
#[const_trait]
|
||||
pub trait Borrow<Borrowed: ?Sized> {
|
||||
/// Immutably borrows from an owned value.
|
||||
///
|
||||
@ -185,7 +184,6 @@ pub trait Borrow<Borrowed: ?Sized> {
|
||||
/// an underlying type by providing a mutable reference. See [`Borrow<T>`]
|
||||
/// for more information on borrowing as another type.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[const_trait]
|
||||
pub trait BorrowMut<Borrowed: ?Sized>: Borrow<Borrowed> {
|
||||
/// Mutably borrows from an owned value.
|
||||
///
|
||||
@ -207,8 +205,7 @@ pub trait BorrowMut<Borrowed: ?Sized>: Borrow<Borrowed> {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_borrow", issue = "91522")]
|
||||
impl<T: ?Sized> const Borrow<T> for T {
|
||||
impl<T: ?Sized> Borrow<T> for T {
|
||||
#[rustc_diagnostic_item = "noop_method_borrow"]
|
||||
fn borrow(&self) -> &T {
|
||||
self
|
||||
@ -216,32 +213,28 @@ impl<T: ?Sized> const Borrow<T> for T {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_borrow", issue = "91522")]
|
||||
impl<T: ?Sized> const BorrowMut<T> for T {
|
||||
impl<T: ?Sized> BorrowMut<T> for T {
|
||||
fn borrow_mut(&mut self) -> &mut T {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_borrow", issue = "91522")]
|
||||
impl<T: ?Sized> const Borrow<T> for &T {
|
||||
impl<T: ?Sized> Borrow<T> for &T {
|
||||
fn borrow(&self) -> &T {
|
||||
&**self
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_borrow", issue = "91522")]
|
||||
impl<T: ?Sized> const Borrow<T> for &mut T {
|
||||
impl<T: ?Sized> Borrow<T> for &mut T {
|
||||
fn borrow(&self) -> &T {
|
||||
&**self
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_borrow", issue = "91522")]
|
||||
impl<T: ?Sized> const BorrowMut<T> for &mut T {
|
||||
impl<T: ?Sized> BorrowMut<T> for &mut T {
|
||||
fn borrow_mut(&mut self) -> &mut T {
|
||||
&mut **self
|
||||
}
|
||||
|
@ -370,8 +370,7 @@ impl<T: Ord + Copy> Ord for Cell<T> {
|
||||
}
|
||||
|
||||
#[stable(feature = "cell_from", since = "1.12.0")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl<T> const From<T> for Cell<T> {
|
||||
impl<T> From<T> for Cell<T> {
|
||||
/// Creates a new `Cell<T>` containing the given value.
|
||||
fn from(t: T) -> Cell<T> {
|
||||
Cell::new(t)
|
||||
@ -1318,8 +1317,7 @@ impl<T: ?Sized + Ord> Ord for RefCell<T> {
|
||||
}
|
||||
|
||||
#[stable(feature = "cell_from", since = "1.12.0")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl<T> const From<T> for RefCell<T> {
|
||||
impl<T> From<T> for RefCell<T> {
|
||||
/// Creates a new `RefCell<T>` containing the given value.
|
||||
fn from(t: T) -> RefCell<T> {
|
||||
RefCell::new(t)
|
||||
@ -2126,8 +2124,7 @@ impl<T: Default> Default for UnsafeCell<T> {
|
||||
}
|
||||
|
||||
#[stable(feature = "cell_from", since = "1.12.0")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl<T> const From<T> for UnsafeCell<T> {
|
||||
impl<T> From<T> for UnsafeCell<T> {
|
||||
/// Creates a new `UnsafeCell<T>` containing the given value.
|
||||
fn from(t: T) -> UnsafeCell<T> {
|
||||
UnsafeCell::new(t)
|
||||
@ -2226,8 +2223,7 @@ impl<T: Default> Default for SyncUnsafeCell<T> {
|
||||
}
|
||||
|
||||
#[unstable(feature = "sync_unsafe_cell", issue = "95439")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl<T> const From<T> for SyncUnsafeCell<T> {
|
||||
impl<T> From<T> for SyncUnsafeCell<T> {
|
||||
/// Creates a new `SyncUnsafeCell<T>` containing the given value.
|
||||
fn from(t: T) -> SyncUnsafeCell<T> {
|
||||
SyncUnsafeCell::new(t)
|
||||
|
@ -284,8 +284,7 @@ impl<T: PartialEq> PartialEq for OnceCell<T> {
|
||||
impl<T: Eq> Eq for OnceCell<T> {}
|
||||
|
||||
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl<T> const From<T> for OnceCell<T> {
|
||||
impl<T> From<T> for OnceCell<T> {
|
||||
/// Creates a new `OnceCell<T>` which already contains the given `value`.
|
||||
#[inline]
|
||||
fn from(value: T) -> Self {
|
||||
|
@ -27,8 +27,7 @@ pub(super) const unsafe fn from_u32_unchecked(i: u32) -> char {
|
||||
}
|
||||
|
||||
#[stable(feature = "char_convert", since = "1.13.0")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl const From<char> for u32 {
|
||||
impl From<char> for u32 {
|
||||
/// Converts a [`char`] into a [`u32`].
|
||||
///
|
||||
/// # Examples
|
||||
@ -47,8 +46,7 @@ impl const From<char> for u32 {
|
||||
}
|
||||
|
||||
#[stable(feature = "more_char_conversions", since = "1.51.0")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl const From<char> for u64 {
|
||||
impl From<char> for u64 {
|
||||
/// Converts a [`char`] into a [`u64`].
|
||||
///
|
||||
/// # Examples
|
||||
@ -69,8 +67,7 @@ impl const From<char> for u64 {
|
||||
}
|
||||
|
||||
#[stable(feature = "more_char_conversions", since = "1.51.0")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl const From<char> for u128 {
|
||||
impl From<char> for u128 {
|
||||
/// Converts a [`char`] into a [`u128`].
|
||||
///
|
||||
/// # Examples
|
||||
@ -123,8 +120,7 @@ impl TryFrom<char> for u8 {
|
||||
/// for a superset of Windows-1252 that fills the remaining blanks with corresponding
|
||||
/// C0 and C1 control codes.
|
||||
#[stable(feature = "char_convert", since = "1.13.0")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl const From<u8> for char {
|
||||
impl From<u8> for char {
|
||||
/// Converts a [`u8`] into a [`char`].
|
||||
///
|
||||
/// # Examples
|
||||
|
@ -36,8 +36,6 @@
|
||||
|
||||
#![stable(feature = "rust1", since = "1.0.0")]
|
||||
|
||||
use crate::marker::Destruct;
|
||||
|
||||
/// A common trait for the ability to explicitly duplicate an object.
|
||||
///
|
||||
/// Differs from [`Copy`] in that [`Copy`] is implicit and an inexpensive bit-wise copy, while
|
||||
@ -106,7 +104,6 @@ use crate::marker::Destruct;
|
||||
#[lang = "clone"]
|
||||
#[rustc_diagnostic_item = "Clone"]
|
||||
#[rustc_trivial_field_reads]
|
||||
#[const_trait]
|
||||
pub trait Clone: Sized {
|
||||
/// Returns a copy of the value.
|
||||
///
|
||||
@ -129,10 +126,7 @@ pub trait Clone: Sized {
|
||||
/// allocations.
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
fn clone_from(&mut self, source: &Self)
|
||||
where
|
||||
Self: ~const Destruct,
|
||||
{
|
||||
fn clone_from(&mut self, source: &Self) {
|
||||
*self = source.clone()
|
||||
}
|
||||
}
|
||||
@ -182,8 +176,7 @@ mod impls {
|
||||
($($t:ty)*) => {
|
||||
$(
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_clone", issue = "91805")]
|
||||
impl const Clone for $t {
|
||||
impl Clone for $t {
|
||||
#[inline(always)]
|
||||
fn clone(&self) -> Self {
|
||||
*self
|
||||
@ -201,8 +194,7 @@ mod impls {
|
||||
}
|
||||
|
||||
#[unstable(feature = "never_type", issue = "35121")]
|
||||
#[rustc_const_unstable(feature = "const_clone", issue = "91805")]
|
||||
impl const Clone for ! {
|
||||
impl Clone for ! {
|
||||
#[inline]
|
||||
fn clone(&self) -> Self {
|
||||
*self
|
||||
@ -210,8 +202,7 @@ mod impls {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_clone", issue = "91805")]
|
||||
impl<T: ?Sized> const Clone for *const T {
|
||||
impl<T: ?Sized> Clone for *const T {
|
||||
#[inline(always)]
|
||||
fn clone(&self) -> Self {
|
||||
*self
|
||||
@ -219,8 +210,7 @@ mod impls {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_clone", issue = "91805")]
|
||||
impl<T: ?Sized> const Clone for *mut T {
|
||||
impl<T: ?Sized> Clone for *mut T {
|
||||
#[inline(always)]
|
||||
fn clone(&self) -> Self {
|
||||
*self
|
||||
@ -229,8 +219,7 @@ mod impls {
|
||||
|
||||
/// Shared references can be cloned, but mutable references *cannot*!
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_clone", issue = "91805")]
|
||||
impl<T: ?Sized> const Clone for &T {
|
||||
impl<T: ?Sized> Clone for &T {
|
||||
#[inline(always)]
|
||||
#[rustc_diagnostic_item = "noop_method_clone"]
|
||||
fn clone(&self) -> Self {
|
||||
|
@ -25,8 +25,6 @@
|
||||
mod bytewise;
|
||||
pub(crate) use bytewise::BytewiseEq;
|
||||
|
||||
use crate::marker::Destruct;
|
||||
|
||||
use self::Ordering::*;
|
||||
|
||||
/// Trait for equality comparisons.
|
||||
@ -212,7 +210,6 @@ use self::Ordering::*;
|
||||
label = "no implementation for `{Self} == {Rhs}`",
|
||||
append_const_msg
|
||||
)]
|
||||
#[const_trait]
|
||||
#[rustc_diagnostic_item = "PartialEq"]
|
||||
pub trait PartialEq<Rhs: ?Sized = Self> {
|
||||
/// This method tests for `self` and `other` values to be equal, and is used
|
||||
@ -333,8 +330,7 @@ pub struct AssertParamIsEq<T: Eq + ?Sized> {
|
||||
/// let result = 2.cmp(&1);
|
||||
/// assert_eq!(Ordering::Greater, result);
|
||||
/// ```
|
||||
#[derive(Clone, Copy, Eq, Debug, Hash)]
|
||||
#[derive_const(PartialOrd, Ord, PartialEq)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[repr(i8)]
|
||||
pub enum Ordering {
|
||||
@ -604,8 +600,7 @@ impl Ordering {
|
||||
pub struct Reverse<T>(#[stable(feature = "reverse_cmp_key", since = "1.19.0")] pub T);
|
||||
|
||||
#[stable(feature = "reverse_cmp_key", since = "1.19.0")]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
|
||||
impl<T: ~const PartialOrd> const PartialOrd for Reverse<T> {
|
||||
impl<T: PartialOrd> PartialOrd for Reverse<T> {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &Reverse<T>) -> Option<Ordering> {
|
||||
other.0.partial_cmp(&self.0)
|
||||
@ -763,7 +758,6 @@ impl<T: Clone> Clone for Reverse<T> {
|
||||
#[doc(alias = ">=")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_diagnostic_item = "Ord"]
|
||||
#[const_trait]
|
||||
pub trait Ord: Eq + PartialOrd<Self> {
|
||||
/// This method returns an [`Ordering`] between `self` and `other`.
|
||||
///
|
||||
@ -799,7 +793,6 @@ pub trait Ord: Eq + PartialOrd<Self> {
|
||||
fn max(self, other: Self) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
Self: ~const Destruct,
|
||||
{
|
||||
max_by(self, other, Ord::cmp)
|
||||
}
|
||||
@ -820,7 +813,6 @@ pub trait Ord: Eq + PartialOrd<Self> {
|
||||
fn min(self, other: Self) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
Self: ~const Destruct,
|
||||
{
|
||||
min_by(self, other, Ord::cmp)
|
||||
}
|
||||
@ -846,8 +838,7 @@ pub trait Ord: Eq + PartialOrd<Self> {
|
||||
fn clamp(self, min: Self, max: Self) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
Self: ~const Destruct,
|
||||
Self: ~const PartialOrd,
|
||||
Self: PartialOrd,
|
||||
{
|
||||
assert!(min <= max);
|
||||
if self < min {
|
||||
@ -1035,7 +1026,6 @@ pub macro Ord($item:item) {
|
||||
label = "no implementation for `{Self} < {Rhs}` and `{Self} > {Rhs}`",
|
||||
append_const_msg
|
||||
)]
|
||||
#[const_trait]
|
||||
#[rustc_diagnostic_item = "PartialOrd"]
|
||||
pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
|
||||
/// This method returns an ordering between `self` and `other` values if one exists.
|
||||
@ -1166,9 +1156,8 @@ pub macro PartialOrd($item:item) {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
|
||||
#[cfg_attr(not(test), rustc_diagnostic_item = "cmp_min")]
|
||||
pub const fn min<T: ~const Ord + ~const Destruct>(v1: T, v2: T) -> T {
|
||||
pub fn min<T: Ord>(v1: T, v2: T) -> T {
|
||||
v1.min(v2)
|
||||
}
|
||||
|
||||
@ -1187,12 +1176,7 @@ pub const fn min<T: ~const Ord + ~const Destruct>(v1: T, v2: T) -> T {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "cmp_min_max_by", since = "1.53.0")]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
|
||||
pub const fn min_by<T, F: ~const FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T
|
||||
where
|
||||
T: ~const Destruct,
|
||||
F: ~const Destruct,
|
||||
{
|
||||
pub fn min_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
|
||||
match compare(&v1, &v2) {
|
||||
Ordering::Less | Ordering::Equal => v1,
|
||||
Ordering::Greater => v2,
|
||||
@ -1214,14 +1198,8 @@ where
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "cmp_min_max_by", since = "1.53.0")]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
|
||||
pub const fn min_by_key<T, F: ~const FnMut(&T) -> K, K: ~const Ord>(v1: T, v2: T, mut f: F) -> T
|
||||
where
|
||||
T: ~const Destruct,
|
||||
F: ~const Destruct,
|
||||
K: ~const Destruct,
|
||||
{
|
||||
min_by(v1, v2, const |v1, v2| f(v1).cmp(&f(v2)))
|
||||
pub fn min_by_key<T, F: FnMut(&T) -> K, K: Ord>(v1: T, v2: T, mut f: F) -> T {
|
||||
min_by(v1, v2, |v1, v2| f(v1).cmp(&f(v2)))
|
||||
}
|
||||
|
||||
/// Compares and returns the maximum of two values.
|
||||
@ -1241,9 +1219,8 @@ where
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
|
||||
#[cfg_attr(not(test), rustc_diagnostic_item = "cmp_max")]
|
||||
pub const fn max<T: ~const Ord + ~const Destruct>(v1: T, v2: T) -> T {
|
||||
pub fn max<T: Ord>(v1: T, v2: T) -> T {
|
||||
v1.max(v2)
|
||||
}
|
||||
|
||||
@ -1262,12 +1239,7 @@ pub const fn max<T: ~const Ord + ~const Destruct>(v1: T, v2: T) -> T {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "cmp_min_max_by", since = "1.53.0")]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
|
||||
pub const fn max_by<T, F: ~const FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T
|
||||
where
|
||||
T: ~const Destruct,
|
||||
F: ~const Destruct,
|
||||
{
|
||||
pub fn max_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
|
||||
match compare(&v1, &v2) {
|
||||
Ordering::Less | Ordering::Equal => v2,
|
||||
Ordering::Greater => v1,
|
||||
@ -1289,14 +1261,8 @@ where
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "cmp_min_max_by", since = "1.53.0")]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
|
||||
pub const fn max_by_key<T, F: ~const FnMut(&T) -> K, K: ~const Ord>(v1: T, v2: T, mut f: F) -> T
|
||||
where
|
||||
T: ~const Destruct,
|
||||
F: ~const Destruct,
|
||||
K: ~const Destruct,
|
||||
{
|
||||
max_by(v1, v2, const |v1, v2| f(v1).cmp(&f(v2)))
|
||||
pub fn max_by_key<T, F: FnMut(&T) -> K, K: Ord>(v1: T, v2: T, mut f: F) -> T {
|
||||
max_by(v1, v2, |v1, v2| f(v1).cmp(&f(v2)))
|
||||
}
|
||||
|
||||
// Implementation of PartialEq, Eq, PartialOrd and Ord for primitive types
|
||||
@ -1307,8 +1273,7 @@ mod impls {
|
||||
macro_rules! partial_eq_impl {
|
||||
($($t:ty)*) => ($(
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
|
||||
impl const PartialEq for $t {
|
||||
impl PartialEq for $t {
|
||||
#[inline]
|
||||
fn eq(&self, other: &$t) -> bool { (*self) == (*other) }
|
||||
#[inline]
|
||||
@ -1318,8 +1283,7 @@ mod impls {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
|
||||
impl const PartialEq for () {
|
||||
impl PartialEq for () {
|
||||
#[inline]
|
||||
fn eq(&self, _other: &()) -> bool {
|
||||
true
|
||||
@ -1346,8 +1310,7 @@ mod impls {
|
||||
macro_rules! partial_ord_impl {
|
||||
($($t:ty)*) => ($(
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
|
||||
impl const PartialOrd for $t {
|
||||
impl PartialOrd for $t {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &$t) -> Option<Ordering> {
|
||||
match (*self <= *other, *self >= *other) {
|
||||
@ -1370,8 +1333,7 @@ mod impls {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
|
||||
impl const PartialOrd for () {
|
||||
impl PartialOrd for () {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, _: &()) -> Option<Ordering> {
|
||||
Some(Equal)
|
||||
@ -1379,8 +1341,7 @@ mod impls {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
|
||||
impl const PartialOrd for bool {
|
||||
impl PartialOrd for bool {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &bool) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
@ -1392,8 +1353,7 @@ mod impls {
|
||||
macro_rules! ord_impl {
|
||||
($($t:ty)*) => ($(
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
|
||||
impl const PartialOrd for $t {
|
||||
impl PartialOrd for $t {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &$t) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
@ -1409,8 +1369,7 @@ mod impls {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
|
||||
impl const Ord for $t {
|
||||
impl Ord for $t {
|
||||
#[inline]
|
||||
fn cmp(&self, other: &$t) -> Ordering {
|
||||
// The order here is important to generate more optimal assembly.
|
||||
@ -1424,8 +1383,7 @@ mod impls {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
|
||||
impl const Ord for () {
|
||||
impl Ord for () {
|
||||
#[inline]
|
||||
fn cmp(&self, _other: &()) -> Ordering {
|
||||
Equal
|
||||
@ -1433,8 +1391,7 @@ mod impls {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
|
||||
impl const Ord for bool {
|
||||
impl Ord for bool {
|
||||
#[inline]
|
||||
fn cmp(&self, other: &bool) -> Ordering {
|
||||
// Casting to i8's and converting the difference to an Ordering generates
|
||||
@ -1453,8 +1410,7 @@ mod impls {
|
||||
ord_impl! { char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
|
||||
|
||||
#[unstable(feature = "never_type", issue = "35121")]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
|
||||
impl const PartialEq for ! {
|
||||
impl PartialEq for ! {
|
||||
fn eq(&self, _: &!) -> bool {
|
||||
*self
|
||||
}
|
||||
@ -1464,16 +1420,14 @@ mod impls {
|
||||
impl Eq for ! {}
|
||||
|
||||
#[unstable(feature = "never_type", issue = "35121")]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
|
||||
impl const PartialOrd for ! {
|
||||
impl PartialOrd for ! {
|
||||
fn partial_cmp(&self, _: &!) -> Option<Ordering> {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "never_type", issue = "35121")]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
|
||||
impl const Ord for ! {
|
||||
impl Ord for ! {
|
||||
fn cmp(&self, _: &!) -> Ordering {
|
||||
*self
|
||||
}
|
||||
@ -1482,10 +1436,9 @@ mod impls {
|
||||
// & pointers
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
|
||||
impl<A: ?Sized, B: ?Sized> const PartialEq<&B> for &A
|
||||
impl<A: ?Sized, B: ?Sized> PartialEq<&B> for &A
|
||||
where
|
||||
A: ~const PartialEq<B>,
|
||||
A: PartialEq<B>,
|
||||
{
|
||||
#[inline]
|
||||
fn eq(&self, other: &&B) -> bool {
|
||||
@ -1497,10 +1450,9 @@ mod impls {
|
||||
}
|
||||
}
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
|
||||
impl<A: ?Sized, B: ?Sized> const PartialOrd<&B> for &A
|
||||
impl<A: ?Sized, B: ?Sized> PartialOrd<&B> for &A
|
||||
where
|
||||
A: ~const PartialOrd<B>,
|
||||
A: PartialOrd<B>,
|
||||
{
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &&B) -> Option<Ordering> {
|
||||
|
@ -214,7 +214,6 @@ pub const fn identity<T>(x: T) -> T {
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[cfg_attr(not(test), rustc_diagnostic_item = "AsRef")]
|
||||
#[const_trait]
|
||||
pub trait AsRef<T: ?Sized> {
|
||||
/// Converts this type into a shared reference of the (usually inferred) input type.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -366,7 +365,6 @@ pub trait AsRef<T: ?Sized> {
|
||||
/// `&mut Vec<u8>`, for example, is the better choice (callers need to pass the correct type then).
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[cfg_attr(not(test), rustc_diagnostic_item = "AsMut")]
|
||||
#[const_trait]
|
||||
pub trait AsMut<T: ?Sized> {
|
||||
/// Converts this type into a mutable reference of the (usually inferred) input type.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -443,7 +441,6 @@ pub trait AsMut<T: ?Sized> {
|
||||
/// [`Vec`]: ../../std/vec/struct.Vec.html
|
||||
#[rustc_diagnostic_item = "Into"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[const_trait]
|
||||
pub trait Into<T>: Sized {
|
||||
/// Converts this type into the (usually inferred) input type.
|
||||
#[must_use]
|
||||
@ -539,7 +536,6 @@ pub trait Into<T>: Sized {
|
||||
all(_Self = "&str", T = "std::string::String"),
|
||||
note = "to coerce a `{T}` into a `{Self}`, use `&*` as a prefix",
|
||||
))]
|
||||
#[const_trait]
|
||||
pub trait From<T>: Sized {
|
||||
/// Converts to this type from the input type.
|
||||
#[rustc_diagnostic_item = "from_fn"]
|
||||
@ -564,7 +560,6 @@ pub trait From<T>: Sized {
|
||||
/// [`Into`], see there for details.
|
||||
#[rustc_diagnostic_item = "TryInto"]
|
||||
#[stable(feature = "try_from", since = "1.34.0")]
|
||||
#[const_trait]
|
||||
pub trait TryInto<T>: Sized {
|
||||
/// The type returned in the event of a conversion error.
|
||||
#[stable(feature = "try_from", since = "1.34.0")]
|
||||
@ -641,7 +636,6 @@ pub trait TryInto<T>: Sized {
|
||||
/// [`try_from`]: TryFrom::try_from
|
||||
#[rustc_diagnostic_item = "TryFrom"]
|
||||
#[stable(feature = "try_from", since = "1.34.0")]
|
||||
#[const_trait]
|
||||
pub trait TryFrom<T>: Sized {
|
||||
/// The type returned in the event of a conversion error.
|
||||
#[stable(feature = "try_from", since = "1.34.0")]
|
||||
@ -658,10 +652,9 @@ pub trait TryFrom<T>: Sized {
|
||||
|
||||
// As lifts over &
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl<T: ?Sized, U: ?Sized> const AsRef<U> for &T
|
||||
impl<T: ?Sized, U: ?Sized> AsRef<U> for &T
|
||||
where
|
||||
T: ~const AsRef<U>,
|
||||
T: AsRef<U>,
|
||||
{
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &U {
|
||||
@ -671,10 +664,9 @@ where
|
||||
|
||||
// As lifts over &mut
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl<T: ?Sized, U: ?Sized> const AsRef<U> for &mut T
|
||||
impl<T: ?Sized, U: ?Sized> AsRef<U> for &mut T
|
||||
where
|
||||
T: ~const AsRef<U>,
|
||||
T: AsRef<U>,
|
||||
{
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &U {
|
||||
@ -692,10 +684,9 @@ where
|
||||
|
||||
// AsMut lifts over &mut
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl<T: ?Sized, U: ?Sized> const AsMut<U> for &mut T
|
||||
impl<T: ?Sized, U: ?Sized> AsMut<U> for &mut T
|
||||
where
|
||||
T: ~const AsMut<U>,
|
||||
T: AsMut<U>,
|
||||
{
|
||||
#[inline]
|
||||
fn as_mut(&mut self) -> &mut U {
|
||||
@ -713,10 +704,9 @@ where
|
||||
|
||||
// From implies Into
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl<T, U> const Into<U> for T
|
||||
impl<T, U> Into<U> for T
|
||||
where
|
||||
U: ~const From<T>,
|
||||
U: From<T>,
|
||||
{
|
||||
/// Calls `U::from(self)`.
|
||||
///
|
||||
@ -730,8 +720,7 @@ where
|
||||
|
||||
// From (and thus Into) is reflexive
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl<T> const From<T> for T {
|
||||
impl<T> From<T> for T {
|
||||
/// Returns the argument unchanged.
|
||||
#[inline(always)]
|
||||
fn from(t: T) -> T {
|
||||
@ -748,8 +737,7 @@ impl<T> const From<T> for T {
|
||||
#[allow(unused_attributes)] // FIXME(#58633): do a principled fix instead.
|
||||
#[rustc_reservation_impl = "permitting this impl would forbid us from adding \
|
||||
`impl<T> From<!> for T` later; see rust-lang/rust#64715 for details"]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl<T> const From<!> for T {
|
||||
impl<T> From<!> for T {
|
||||
fn from(t: !) -> T {
|
||||
t
|
||||
}
|
||||
@ -757,10 +745,9 @@ impl<T> const From<!> for T {
|
||||
|
||||
// TryFrom implies TryInto
|
||||
#[stable(feature = "try_from", since = "1.34.0")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl<T, U> const TryInto<U> for T
|
||||
impl<T, U> TryInto<U> for T
|
||||
where
|
||||
U: ~const TryFrom<T>,
|
||||
U: TryFrom<T>,
|
||||
{
|
||||
type Error = U::Error;
|
||||
|
||||
@ -773,10 +760,9 @@ where
|
||||
// Infallible conversions are semantically equivalent to fallible conversions
|
||||
// with an uninhabited error type.
|
||||
#[stable(feature = "try_from", since = "1.34.0")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl<T, U> const TryFrom<U> for T
|
||||
impl<T, U> TryFrom<U> for T
|
||||
where
|
||||
U: ~const Into<T>,
|
||||
U: Into<T>,
|
||||
{
|
||||
type Error = Infallible;
|
||||
|
||||
@ -876,8 +862,7 @@ impl AsMut<str> for str {
|
||||
pub enum Infallible {}
|
||||
|
||||
#[stable(feature = "convert_infallible", since = "1.34.0")]
|
||||
#[rustc_const_unstable(feature = "const_clone", issue = "91805")]
|
||||
impl const Clone for Infallible {
|
||||
impl Clone for Infallible {
|
||||
fn clone(&self) -> Infallible {
|
||||
match *self {}
|
||||
}
|
||||
@ -929,8 +914,7 @@ impl Ord for Infallible {
|
||||
}
|
||||
|
||||
#[stable(feature = "convert_infallible", since = "1.34.0")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl const From<!> for Infallible {
|
||||
impl From<!> for Infallible {
|
||||
fn from(x: !) -> Self {
|
||||
x
|
||||
}
|
||||
|
@ -44,8 +44,7 @@ impl_float_to_int!(f64 => u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize);
|
||||
macro_rules! impl_from {
|
||||
($Small: ty, $Large: ty, #[$attr:meta], $doc: expr) => {
|
||||
#[$attr]
|
||||
#[rustc_const_unstable(feature = "const_num_from_num", issue = "87852")]
|
||||
impl const From<$Small> for $Large {
|
||||
impl From<$Small> for $Large {
|
||||
// Rustdocs on the impl block show a "[+] show undocumented items" toggle.
|
||||
// Rustdocs on functions do not.
|
||||
#[doc = $doc]
|
||||
@ -170,8 +169,7 @@ impl_from! { f32, f64, #[stable(feature = "lossless_float_conv", since = "1.6.0"
|
||||
|
||||
// bool -> Float
|
||||
#[stable(feature = "float_from_bool", since = "1.68.0")]
|
||||
#[rustc_const_unstable(feature = "const_num_from_num", issue = "87852")]
|
||||
impl const From<bool> for f32 {
|
||||
impl From<bool> for f32 {
|
||||
/// Converts `bool` to `f32` losslessly. The resulting value is positive
|
||||
/// `0.0` for `false` and `1.0` for `true` values.
|
||||
///
|
||||
@ -190,8 +188,7 @@ impl const From<bool> for f32 {
|
||||
}
|
||||
}
|
||||
#[stable(feature = "float_from_bool", since = "1.68.0")]
|
||||
#[rustc_const_unstable(feature = "const_num_from_num", issue = "87852")]
|
||||
impl const From<bool> for f64 {
|
||||
impl From<bool> for f64 {
|
||||
/// Converts `bool` to `f64` losslessly. The resulting value is positive
|
||||
/// `0.0` for `false` and `1.0` for `true` values.
|
||||
///
|
||||
@ -214,8 +211,7 @@ impl const From<bool> for f64 {
|
||||
macro_rules! try_from_unbounded {
|
||||
($source:ty, $($target:ty),*) => {$(
|
||||
#[stable(feature = "try_from", since = "1.34.0")]
|
||||
#[rustc_const_unstable(feature = "const_num_from_num", issue = "87852")]
|
||||
impl const TryFrom<$source> for $target {
|
||||
impl TryFrom<$source> for $target {
|
||||
type Error = TryFromIntError;
|
||||
|
||||
/// Try to create the target number type from a source
|
||||
@ -233,8 +229,7 @@ macro_rules! try_from_unbounded {
|
||||
macro_rules! try_from_lower_bounded {
|
||||
($source:ty, $($target:ty),*) => {$(
|
||||
#[stable(feature = "try_from", since = "1.34.0")]
|
||||
#[rustc_const_unstable(feature = "const_num_from_num", issue = "87852")]
|
||||
impl const TryFrom<$source> for $target {
|
||||
impl TryFrom<$source> for $target {
|
||||
type Error = TryFromIntError;
|
||||
|
||||
/// Try to create the target number type from a source
|
||||
@ -256,8 +251,7 @@ macro_rules! try_from_lower_bounded {
|
||||
macro_rules! try_from_upper_bounded {
|
||||
($source:ty, $($target:ty),*) => {$(
|
||||
#[stable(feature = "try_from", since = "1.34.0")]
|
||||
#[rustc_const_unstable(feature = "const_num_from_num", issue = "87852")]
|
||||
impl const TryFrom<$source> for $target {
|
||||
impl TryFrom<$source> for $target {
|
||||
type Error = TryFromIntError;
|
||||
|
||||
/// Try to create the target number type from a source
|
||||
@ -279,8 +273,7 @@ macro_rules! try_from_upper_bounded {
|
||||
macro_rules! try_from_both_bounded {
|
||||
($source:ty, $($target:ty),*) => {$(
|
||||
#[stable(feature = "try_from", since = "1.34.0")]
|
||||
#[rustc_const_unstable(feature = "const_num_from_num", issue = "87852")]
|
||||
impl const TryFrom<$source> for $target {
|
||||
impl TryFrom<$source> for $target {
|
||||
type Error = TryFromIntError;
|
||||
|
||||
/// Try to create the target number type from a source
|
||||
@ -431,8 +424,7 @@ use crate::num::NonZeroUsize;
|
||||
macro_rules! nzint_impl_from {
|
||||
($Small: ty, $Large: ty, #[$attr:meta], $doc: expr) => {
|
||||
#[$attr]
|
||||
#[rustc_const_unstable(feature = "const_num_from_num", issue = "87852")]
|
||||
impl const From<$Small> for $Large {
|
||||
impl From<$Small> for $Large {
|
||||
// Rustdocs on the impl block show a "[+] show undocumented items" toggle.
|
||||
// Rustdocs on functions do not.
|
||||
#[doc = $doc]
|
||||
|
@ -99,7 +99,6 @@
|
||||
/// ```
|
||||
#[cfg_attr(not(test), rustc_diagnostic_item = "Default")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[const_trait]
|
||||
pub trait Default: Sized {
|
||||
/// Returns the "default value" for a type.
|
||||
///
|
||||
@ -190,8 +189,7 @@ pub macro Default($item:item) {
|
||||
macro_rules! default_impl {
|
||||
($t:ty, $v:expr, $doc:tt) => {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
|
||||
impl const Default for $t {
|
||||
impl Default for $t {
|
||||
#[inline]
|
||||
#[doc = $doc]
|
||||
fn default() -> $t {
|
||||
|
@ -324,14 +324,15 @@ impl CStr {
|
||||
/// assert_eq!(c_str.to_str().unwrap(), "AAAAAAAA");
|
||||
/// ```
|
||||
///
|
||||
#[rustc_allow_const_fn_unstable(const_slice_index)]
|
||||
#[stable(feature = "cstr_from_bytes_until_nul", since = "1.69.0")]
|
||||
#[rustc_const_stable(feature = "cstr_from_bytes_until_nul", since = "1.69.0")]
|
||||
pub const fn from_bytes_until_nul(bytes: &[u8]) -> Result<&CStr, FromBytesUntilNulError> {
|
||||
let nul_pos = memchr::memchr(0, bytes);
|
||||
match nul_pos {
|
||||
Some(nul_pos) => {
|
||||
let subslice = &bytes[..nul_pos + 1];
|
||||
// FIXME(const-hack) replace with range index
|
||||
// SAFETY: nul_pos + 1 <= bytes.len()
|
||||
let subslice = unsafe { crate::slice::from_raw_parts(bytes.as_ptr(), nul_pos + 1) };
|
||||
// SAFETY: We know there is a nul byte at nul_pos, so this slice
|
||||
// (ending at the nul byte) is a well-formed C string.
|
||||
Ok(unsafe { CStr::from_bytes_with_nul_unchecked(subslice) })
|
||||
@ -536,7 +537,8 @@ impl CStr {
|
||||
pub const fn is_empty(&self) -> bool {
|
||||
// SAFETY: We know there is at least one byte; for empty strings it
|
||||
// is the NUL terminator.
|
||||
(unsafe { self.inner.get_unchecked(0) }) == &0
|
||||
// FIXME(const-hack): use get_unchecked
|
||||
unsafe { *self.inner.as_ptr() == 0 }
|
||||
}
|
||||
|
||||
/// Converts this C string to a byte slice.
|
||||
@ -560,8 +562,7 @@ impl CStr {
|
||||
#[must_use = "this returns the result of the operation, \
|
||||
without modifying the original"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_cstr_methods", issue = "101719")]
|
||||
pub const fn to_bytes(&self) -> &[u8] {
|
||||
pub fn to_bytes(&self) -> &[u8] {
|
||||
let bytes = self.to_bytes_with_nul();
|
||||
// SAFETY: to_bytes_with_nul returns slice with length at least 1
|
||||
unsafe { bytes.get_unchecked(..bytes.len() - 1) }
|
||||
@ -612,8 +613,7 @@ impl CStr {
|
||||
/// assert_eq!(cstr.to_str(), Ok("foo"));
|
||||
/// ```
|
||||
#[stable(feature = "cstr_to_str", since = "1.4.0")]
|
||||
#[rustc_const_unstable(feature = "const_cstr_methods", issue = "101719")]
|
||||
pub const fn to_str(&self) -> Result<&str, str::Utf8Error> {
|
||||
pub fn to_str(&self) -> Result<&str, str::Utf8Error> {
|
||||
// N.B., when `CStr` is changed to perform the length check in `.to_bytes()`
|
||||
// instead of in `from_ptr()`, it may be worth considering if this should
|
||||
// be rewritten to do the UTF-8 check inline with the length calculation
|
||||
|
@ -86,8 +86,7 @@
|
||||
#![stable(feature = "rust1", since = "1.0.0")]
|
||||
|
||||
use crate::fmt;
|
||||
use crate::intrinsics::const_eval_select;
|
||||
use crate::marker::{self, Destruct};
|
||||
use crate::marker;
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[allow(deprecated)]
|
||||
@ -184,7 +183,6 @@ mod sip;
|
||||
/// [impl]: ../../std/primitive.str.html#impl-Hash-for-str
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_diagnostic_item = "Hash"]
|
||||
#[const_trait]
|
||||
pub trait Hash {
|
||||
/// Feeds this value into the given [`Hasher`].
|
||||
///
|
||||
@ -199,7 +197,7 @@ pub trait Hash {
|
||||
/// println!("Hash is {:x}!", hasher.finish());
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
fn hash<H: ~const Hasher>(&self, state: &mut H);
|
||||
fn hash<H: Hasher>(&self, state: &mut H);
|
||||
|
||||
/// Feeds a slice of this type into the given [`Hasher`].
|
||||
///
|
||||
@ -236,25 +234,13 @@ pub trait Hash {
|
||||
/// [`hash`]: Hash::hash
|
||||
/// [`hash_slice`]: Hash::hash_slice
|
||||
#[stable(feature = "hash_slice", since = "1.3.0")]
|
||||
fn hash_slice<H: ~const Hasher>(data: &[Self], state: &mut H)
|
||||
fn hash_slice<H: Hasher>(data: &[Self], state: &mut H)
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
//FIXME(const_trait_impl): revert to only a for loop
|
||||
fn rt<T: Hash, H: Hasher>(data: &[T], state: &mut H) {
|
||||
for piece in data {
|
||||
piece.hash(state)
|
||||
}
|
||||
for piece in data {
|
||||
piece.hash(state)
|
||||
}
|
||||
const fn ct<T: ~const Hash, H: ~const Hasher>(data: &[T], state: &mut H) {
|
||||
let mut i = 0;
|
||||
while i < data.len() {
|
||||
data[i].hash(state);
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
// SAFETY: same behavior, CT just uses while instead of for
|
||||
unsafe { const_eval_select((data, state), ct, rt) };
|
||||
}
|
||||
}
|
||||
|
||||
@ -327,7 +313,6 @@ pub use macros::Hash;
|
||||
/// [`write_u8`]: Hasher::write_u8
|
||||
/// [`write_u32`]: Hasher::write_u32
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[const_trait]
|
||||
pub trait Hasher {
|
||||
/// Returns the hash value for the values written so far.
|
||||
///
|
||||
@ -573,8 +558,7 @@ pub trait Hasher {
|
||||
}
|
||||
|
||||
#[stable(feature = "indirect_hasher_impl", since = "1.22.0")]
|
||||
#[rustc_const_unstable(feature = "const_hash", issue = "104061")]
|
||||
impl<H: ~const Hasher + ?Sized> const Hasher for &mut H {
|
||||
impl<H: Hasher + ?Sized> Hasher for &mut H {
|
||||
fn finish(&self) -> u64 {
|
||||
(**self).finish()
|
||||
}
|
||||
@ -654,7 +638,6 @@ impl<H: ~const Hasher + ?Sized> const Hasher for &mut H {
|
||||
/// [`build_hasher`]: BuildHasher::build_hasher
|
||||
/// [`HashMap`]: ../../std/collections/struct.HashMap.html
|
||||
#[stable(since = "1.7.0", feature = "build_hasher")]
|
||||
#[const_trait]
|
||||
pub trait BuildHasher {
|
||||
/// Type of the hasher that will be created.
|
||||
#[stable(since = "1.7.0", feature = "build_hasher")]
|
||||
@ -715,10 +698,10 @@ pub trait BuildHasher {
|
||||
/// );
|
||||
/// ```
|
||||
#[unstable(feature = "build_hasher_simple_hash_one", issue = "86161")]
|
||||
fn hash_one<T: ~const Hash + ~const Destruct>(&self, x: T) -> u64
|
||||
fn hash_one<T: Hash>(&self, x: T) -> u64
|
||||
where
|
||||
Self: Sized,
|
||||
Self::Hasher: ~const Hasher + ~const Destruct,
|
||||
Self::Hasher: Hasher,
|
||||
{
|
||||
let mut hasher = self.build_hasher();
|
||||
x.hash(&mut hasher);
|
||||
@ -782,8 +765,7 @@ impl<H> fmt::Debug for BuildHasherDefault<H> {
|
||||
}
|
||||
|
||||
#[stable(since = "1.7.0", feature = "build_hasher")]
|
||||
#[rustc_const_unstable(feature = "const_hash", issue = "104061")]
|
||||
impl<H: ~const Default + Hasher> const BuildHasher for BuildHasherDefault<H> {
|
||||
impl<H: Default + Hasher> BuildHasher for BuildHasherDefault<H> {
|
||||
type Hasher = H;
|
||||
|
||||
fn build_hasher(&self) -> H {
|
||||
@ -799,8 +781,7 @@ impl<H> Clone for BuildHasherDefault<H> {
|
||||
}
|
||||
|
||||
#[stable(since = "1.7.0", feature = "build_hasher")]
|
||||
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
|
||||
impl<H> const Default for BuildHasherDefault<H> {
|
||||
impl<H> Default for BuildHasherDefault<H> {
|
||||
fn default() -> BuildHasherDefault<H> {
|
||||
BuildHasherDefault(marker::PhantomData)
|
||||
}
|
||||
@ -825,15 +806,14 @@ mod impls {
|
||||
macro_rules! impl_write {
|
||||
($(($ty:ident, $meth:ident),)*) => {$(
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_hash", issue = "104061")]
|
||||
impl const Hash for $ty {
|
||||
impl Hash for $ty {
|
||||
#[inline]
|
||||
fn hash<H: ~const Hasher>(&self, state: &mut H) {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
state.$meth(*self)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn hash_slice<H: ~const Hasher>(data: &[$ty], state: &mut H) {
|
||||
fn hash_slice<H: Hasher>(data: &[$ty], state: &mut H) {
|
||||
let newlen = mem::size_of_val(data);
|
||||
let ptr = data.as_ptr() as *const u8;
|
||||
// SAFETY: `ptr` is valid and aligned, as this macro is only used
|
||||
@ -862,37 +842,33 @@ mod impls {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_hash", issue = "104061")]
|
||||
impl const Hash for bool {
|
||||
impl Hash for bool {
|
||||
#[inline]
|
||||
fn hash<H: ~const Hasher>(&self, state: &mut H) {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
state.write_u8(*self as u8)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_hash", issue = "104061")]
|
||||
impl const Hash for char {
|
||||
impl Hash for char {
|
||||
#[inline]
|
||||
fn hash<H: ~const Hasher>(&self, state: &mut H) {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
state.write_u32(*self as u32)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_hash", issue = "104061")]
|
||||
impl const Hash for str {
|
||||
impl Hash for str {
|
||||
#[inline]
|
||||
fn hash<H: ~const Hasher>(&self, state: &mut H) {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
state.write_str(self);
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "never_hash", since = "1.29.0")]
|
||||
#[rustc_const_unstable(feature = "const_hash", issue = "104061")]
|
||||
impl const Hash for ! {
|
||||
impl Hash for ! {
|
||||
#[inline]
|
||||
fn hash<H: ~const Hasher>(&self, _: &mut H) {
|
||||
fn hash<H: Hasher>(&self, _: &mut H) {
|
||||
*self
|
||||
}
|
||||
}
|
||||
@ -900,10 +876,9 @@ mod impls {
|
||||
macro_rules! impl_hash_tuple {
|
||||
() => (
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_hash", issue = "104061")]
|
||||
impl const Hash for () {
|
||||
impl Hash for () {
|
||||
#[inline]
|
||||
fn hash<H: ~const Hasher>(&self, _state: &mut H) {}
|
||||
fn hash<H: Hasher>(&self, _state: &mut H) {}
|
||||
}
|
||||
);
|
||||
|
||||
@ -911,11 +886,10 @@ mod impls {
|
||||
maybe_tuple_doc! {
|
||||
$($name)+ @
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_hash", issue = "104061")]
|
||||
impl<$($name: ~const Hash),+> const Hash for ($($name,)+) where last_type!($($name,)+): ?Sized {
|
||||
impl<$($name: Hash),+> Hash for ($($name,)+) where last_type!($($name,)+): ?Sized {
|
||||
#[allow(non_snake_case)]
|
||||
#[inline]
|
||||
fn hash<S: ~const Hasher>(&self, state: &mut S) {
|
||||
fn hash<S: Hasher>(&self, state: &mut S) {
|
||||
let ($(ref $name,)+) = *self;
|
||||
$($name.hash(state);)+
|
||||
}
|
||||
@ -958,29 +932,26 @@ mod impls {
|
||||
impl_hash_tuple! { T B C D E F G H I J K L }
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_hash", issue = "104061")]
|
||||
impl<T: ~const Hash> const Hash for [T] {
|
||||
impl<T: Hash> Hash for [T] {
|
||||
#[inline]
|
||||
fn hash<H: ~const Hasher>(&self, state: &mut H) {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
state.write_length_prefix(self.len());
|
||||
Hash::hash_slice(self, state)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_hash", issue = "104061")]
|
||||
impl<T: ?Sized + ~const Hash> const Hash for &T {
|
||||
impl<T: ?Sized + Hash> Hash for &T {
|
||||
#[inline]
|
||||
fn hash<H: ~const Hasher>(&self, state: &mut H) {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
(**self).hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_hash", issue = "104061")]
|
||||
impl<T: ?Sized + ~const Hash> const Hash for &mut T {
|
||||
impl<T: ?Sized + Hash> Hash for &mut T {
|
||||
#[inline]
|
||||
fn hash<H: ~const Hasher>(&self, state: &mut H) {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
(**self).hash(state);
|
||||
}
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ macro_rules! load_int_le {
|
||||
/// Safety: this performs unchecked indexing of `buf` at `start..start+len`, so
|
||||
/// that must be in-bounds.
|
||||
#[inline]
|
||||
const unsafe fn u8to64_le(buf: &[u8], start: usize, len: usize) -> u64 {
|
||||
unsafe fn u8to64_le(buf: &[u8], start: usize, len: usize) -> u64 {
|
||||
debug_assert!(len < 8);
|
||||
let mut i = 0; // current byte index (from LSB) in the output u64
|
||||
let mut out = 0;
|
||||
@ -225,8 +225,7 @@ impl<S: Sip> Hasher<S> {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_hash", issue = "104061")]
|
||||
impl const super::Hasher for SipHasher {
|
||||
impl super::Hasher for SipHasher {
|
||||
#[inline]
|
||||
fn write(&mut self, msg: &[u8]) {
|
||||
self.0.hasher.write(msg)
|
||||
@ -244,8 +243,7 @@ impl const super::Hasher for SipHasher {
|
||||
}
|
||||
|
||||
#[unstable(feature = "hashmap_internals", issue = "none")]
|
||||
#[rustc_const_unstable(feature = "const_hash", issue = "104061")]
|
||||
impl const super::Hasher for SipHasher13 {
|
||||
impl super::Hasher for SipHasher13 {
|
||||
#[inline]
|
||||
fn write(&mut self, msg: &[u8]) {
|
||||
self.hasher.write(msg)
|
||||
@ -262,7 +260,7 @@ impl const super::Hasher for SipHasher13 {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: ~const Sip> const super::Hasher for Hasher<S> {
|
||||
impl<S: Sip> super::Hasher for Hasher<S> {
|
||||
// Note: no integer hashing methods (`write_u*`, `write_i*`) are defined
|
||||
// for this type. We could add them, copy the `short_write` implementation
|
||||
// in librustc_data_structures/sip128.rs, and add `write_u*`/`write_i*`
|
||||
@ -342,7 +340,7 @@ impl<S: ~const Sip> const super::Hasher for Hasher<S> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: Sip> const Clone for Hasher<S> {
|
||||
impl<S: Sip> Clone for Hasher<S> {
|
||||
#[inline]
|
||||
fn clone(&self) -> Hasher<S> {
|
||||
Hasher {
|
||||
@ -366,7 +364,6 @@ impl<S: Sip> Default for Hasher<S> {
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[const_trait]
|
||||
trait Sip {
|
||||
fn c_rounds(_: &mut State);
|
||||
fn d_rounds(_: &mut State);
|
||||
@ -375,7 +372,7 @@ trait Sip {
|
||||
#[derive(Debug, Clone, Default)]
|
||||
struct Sip13Rounds;
|
||||
|
||||
impl const Sip for Sip13Rounds {
|
||||
impl Sip for Sip13Rounds {
|
||||
#[inline]
|
||||
fn c_rounds(state: &mut State) {
|
||||
compress!(state);
|
||||
@ -392,7 +389,7 @@ impl const Sip for Sip13Rounds {
|
||||
#[derive(Debug, Clone, Default)]
|
||||
struct Sip24Rounds;
|
||||
|
||||
impl const Sip for Sip24Rounds {
|
||||
impl Sip for Sip24Rounds {
|
||||
#[inline]
|
||||
fn c_rounds(state: &mut State) {
|
||||
compress!(state);
|
||||
|
@ -1,23 +1,10 @@
|
||||
// implements the unary operator "op &T"
|
||||
// based on "op T" where T is expected to be `Copy`able
|
||||
macro_rules! forward_ref_unop {
|
||||
(impl const $imp:ident, $method:ident for $t:ty) => {
|
||||
forward_ref_unop!(impl const $imp, $method for $t,
|
||||
(impl $imp:ident, $method:ident for $t:ty) => {
|
||||
forward_ref_unop!(impl $imp, $method for $t,
|
||||
#[stable(feature = "rust1", since = "1.0.0")]);
|
||||
};
|
||||
// Equivalent to the non-const version, with the addition of `rustc_const_unstable`
|
||||
(impl const $imp:ident, $method:ident for $t:ty, #[$attr:meta]) => {
|
||||
#[$attr]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const $imp for &$t {
|
||||
type Output = <$t as $imp>::Output;
|
||||
|
||||
#[inline]
|
||||
fn $method(self) -> <$t as $imp>::Output {
|
||||
$imp::$method(*self)
|
||||
}
|
||||
}
|
||||
};
|
||||
(impl $imp:ident, $method:ident for $t:ty, #[$attr:meta]) => {
|
||||
#[$attr]
|
||||
impl $imp for &$t {
|
||||
@ -34,45 +21,10 @@ macro_rules! forward_ref_unop {
|
||||
// implements binary operators "&T op U", "T op &U", "&T op &U"
|
||||
// based on "T op U" where T and U are expected to be `Copy`able
|
||||
macro_rules! forward_ref_binop {
|
||||
(impl const $imp:ident, $method:ident for $t:ty, $u:ty) => {
|
||||
forward_ref_binop!(impl const $imp, $method for $t, $u,
|
||||
(impl $imp:ident, $method:ident for $t:ty, $u:ty) => {
|
||||
forward_ref_binop!(impl $imp, $method for $t, $u,
|
||||
#[stable(feature = "rust1", since = "1.0.0")]);
|
||||
};
|
||||
// Equivalent to the non-const version, with the addition of `rustc_const_unstable`
|
||||
(impl const $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
|
||||
#[$attr]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl<'a> const $imp<$u> for &'a $t {
|
||||
type Output = <$t as $imp<$u>>::Output;
|
||||
|
||||
#[inline]
|
||||
fn $method(self, other: $u) -> <$t as $imp<$u>>::Output {
|
||||
$imp::$method(*self, other)
|
||||
}
|
||||
}
|
||||
|
||||
#[$attr]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const $imp<&$u> for $t {
|
||||
type Output = <$t as $imp<$u>>::Output;
|
||||
|
||||
#[inline]
|
||||
fn $method(self, other: &$u) -> <$t as $imp<$u>>::Output {
|
||||
$imp::$method(self, *other)
|
||||
}
|
||||
}
|
||||
|
||||
#[$attr]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const $imp<&$u> for &$t {
|
||||
type Output = <$t as $imp<$u>>::Output;
|
||||
|
||||
#[inline]
|
||||
fn $method(self, other: &$u) -> <$t as $imp<$u>>::Output {
|
||||
$imp::$method(*self, *other)
|
||||
}
|
||||
}
|
||||
};
|
||||
(impl $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
|
||||
#[$attr]
|
||||
impl<'a> $imp<$u> for &'a $t {
|
||||
@ -113,21 +65,6 @@ macro_rules! forward_ref_op_assign {
|
||||
forward_ref_op_assign!(impl $imp, $method for $t, $u,
|
||||
#[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")]);
|
||||
};
|
||||
(impl const $imp:ident, $method:ident for $t:ty, $u:ty) => {
|
||||
forward_ref_op_assign!(impl const $imp, $method for $t, $u,
|
||||
#[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")]);
|
||||
};
|
||||
// Equivalent to the non-const version, with the addition of `rustc_const_unstable`
|
||||
(impl const $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
|
||||
#[$attr]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const $imp<&$u> for $t {
|
||||
#[inline]
|
||||
fn $method(&mut self, other: &$u) {
|
||||
$imp::$method(self, *other);
|
||||
}
|
||||
}
|
||||
};
|
||||
(impl $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
|
||||
#[$attr]
|
||||
impl $imp<&$u> for $t {
|
||||
|
@ -81,8 +81,7 @@ impl<T> Clone for Empty<T> {
|
||||
// not #[derive] because that adds a Default bound on T,
|
||||
// which isn't necessary.
|
||||
#[stable(feature = "iter_empty", since = "1.2.0")]
|
||||
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
|
||||
impl<T> const Default for Empty<T> {
|
||||
impl<T> Default for Empty<T> {
|
||||
fn default() -> Empty<T> {
|
||||
Empty(marker::PhantomData)
|
||||
}
|
||||
|
@ -228,7 +228,6 @@ pub trait FromIterator<A>: Sized {
|
||||
#[rustc_diagnostic_item = "IntoIterator"]
|
||||
#[rustc_skip_array_during_method_dispatch]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[const_trait]
|
||||
pub trait IntoIterator {
|
||||
/// The type of the elements being iterated over.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -264,7 +263,7 @@ pub trait IntoIterator {
|
||||
|
||||
#[rustc_const_unstable(feature = "const_intoiterator_identity", issue = "90603")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<I: Iterator> const IntoIterator for I {
|
||||
impl<I: Iterator> IntoIterator for I {
|
||||
type Item = I::Item;
|
||||
type IntoIter = I;
|
||||
|
||||
|
@ -70,7 +70,6 @@ fn _assert_is_object_safe(_: &dyn Iterator<Item = ()>) {}
|
||||
#[doc(notable_trait)]
|
||||
#[rustc_diagnostic_item = "Iterator"]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
#[const_trait]
|
||||
pub trait Iterator {
|
||||
/// The type of the elements being iterated over.
|
||||
#[rustc_diagnostic_item = "IteratorItem"]
|
||||
|
@ -112,11 +112,7 @@
|
||||
#![feature(const_caller_location)]
|
||||
#![feature(const_cell_into_inner)]
|
||||
#![feature(const_char_from_u32_unchecked)]
|
||||
#![feature(const_clone)]
|
||||
#![feature(const_cmp)]
|
||||
#![feature(const_convert)]
|
||||
#![feature(const_cstr_methods)]
|
||||
#![feature(const_default_impls)]
|
||||
#![feature(const_discriminant)]
|
||||
#![feature(const_eval_select)]
|
||||
#![feature(const_exact_div)]
|
||||
@ -131,14 +127,11 @@
|
||||
#![feature(const_intrinsic_forget)]
|
||||
#![feature(const_ipv4)]
|
||||
#![feature(const_ipv6)]
|
||||
#![feature(const_is_char_boundary)]
|
||||
#![feature(const_likely)]
|
||||
#![feature(const_maybe_uninit_as_mut_ptr)]
|
||||
#![feature(const_maybe_uninit_assume_init)]
|
||||
#![feature(const_maybe_uninit_uninit_array)]
|
||||
#![feature(const_nonnull_new)]
|
||||
#![feature(const_num_from_num)]
|
||||
#![feature(const_ops)]
|
||||
#![feature(const_option)]
|
||||
#![feature(const_option_ext)]
|
||||
#![feature(const_pin)]
|
||||
@ -151,7 +144,6 @@
|
||||
#![feature(const_ptr_write)]
|
||||
#![feature(const_raw_ptr_comparison)]
|
||||
#![feature(const_replace)]
|
||||
#![feature(const_result_drop)]
|
||||
#![feature(const_size_of_val)]
|
||||
#![feature(const_size_of_val_raw)]
|
||||
#![feature(const_slice_from_raw_parts_mut)]
|
||||
@ -161,7 +153,6 @@
|
||||
#![feature(const_slice_split_at_mut)]
|
||||
#![feature(const_str_from_utf8_unchecked_mut)]
|
||||
#![feature(const_swap)]
|
||||
#![feature(const_trait_impl)]
|
||||
#![feature(const_transmute_copy)]
|
||||
#![feature(const_try)]
|
||||
#![feature(const_type_id)]
|
||||
@ -207,9 +198,9 @@
|
||||
#![feature(const_mut_refs)]
|
||||
#![feature(const_precise_live_drops)]
|
||||
#![feature(const_refs_to_cell)]
|
||||
#![feature(const_trait_impl)]
|
||||
#![feature(decl_macro)]
|
||||
#![feature(deprecated_suggestion)]
|
||||
#![feature(derive_const)]
|
||||
#![feature(doc_cfg)]
|
||||
#![feature(doc_cfg_hide)]
|
||||
#![feature(doc_notable_trait)]
|
||||
|
@ -732,8 +732,7 @@ impl<T: ?Sized> Clone for PhantomData<T> {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
|
||||
impl<T: ?Sized> const Default for PhantomData<T> {
|
||||
impl<T: ?Sized> Default for PhantomData<T> {
|
||||
fn default() -> Self {
|
||||
Self
|
||||
}
|
||||
@ -858,8 +857,8 @@ impl<T: ?Sized> Unpin for *mut T {}
|
||||
#[unstable(feature = "const_trait_impl", issue = "67792")]
|
||||
#[lang = "destruct"]
|
||||
#[rustc_on_unimplemented(message = "can't drop `{Self}`", append_const_msg)]
|
||||
#[const_trait]
|
||||
#[rustc_deny_explicit_impl]
|
||||
#[const_trait]
|
||||
pub trait Destruct {}
|
||||
|
||||
/// A marker for tuple types.
|
||||
|
@ -146,8 +146,7 @@ impl<T: ?Sized> ManuallyDrop<T> {
|
||||
}
|
||||
|
||||
#[stable(feature = "manually_drop", since = "1.20.0")]
|
||||
#[rustc_const_unstable(feature = "const_deref", issue = "88955")]
|
||||
impl<T: ?Sized> const Deref for ManuallyDrop<T> {
|
||||
impl<T: ?Sized> Deref for ManuallyDrop<T> {
|
||||
type Target = T;
|
||||
#[inline(always)]
|
||||
fn deref(&self) -> &T {
|
||||
@ -156,8 +155,7 @@ impl<T: ?Sized> const Deref for ManuallyDrop<T> {
|
||||
}
|
||||
|
||||
#[stable(feature = "manually_drop", since = "1.20.0")]
|
||||
#[rustc_const_unstable(feature = "const_deref", issue = "88955")]
|
||||
impl<T: ?Sized> const DerefMut for ManuallyDrop<T> {
|
||||
impl<T: ?Sized> DerefMut for ManuallyDrop<T> {
|
||||
#[inline(always)]
|
||||
fn deref_mut(&mut self) -> &mut T {
|
||||
&mut self.value
|
||||
|
@ -81,8 +81,7 @@ impl Assume {
|
||||
// FIXME(jswrenn): This const op is not actually usable. Why?
|
||||
// https://github.com/rust-lang/rust/pull/100726#issuecomment-1219928926
|
||||
#[unstable(feature = "transmutability", issue = "99571")]
|
||||
#[rustc_const_unstable(feature = "transmutability", issue = "99571")]
|
||||
impl const core::ops::Add for Assume {
|
||||
impl core::ops::Add for Assume {
|
||||
type Output = Assume;
|
||||
|
||||
fn add(self, other_assumptions: Assume) -> Assume {
|
||||
@ -93,8 +92,7 @@ impl const core::ops::Add for Assume {
|
||||
// FIXME(jswrenn): This const op is not actually usable. Why?
|
||||
// https://github.com/rust-lang/rust/pull/100726#issuecomment-1219928926
|
||||
#[unstable(feature = "transmutability", issue = "99571")]
|
||||
#[rustc_const_unstable(feature = "transmutability", issue = "99571")]
|
||||
impl const core::ops::Sub for Assume {
|
||||
impl core::ops::Sub for Assume {
|
||||
type Output = Assume;
|
||||
|
||||
fn sub(self, other_assumptions: Assume) -> Assume {
|
||||
|
@ -26,15 +26,14 @@ impl Error for TryFromIntError {
|
||||
}
|
||||
|
||||
#[stable(feature = "try_from", since = "1.34.0")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl const From<Infallible> for TryFromIntError {
|
||||
impl From<Infallible> for TryFromIntError {
|
||||
fn from(x: Infallible) -> TryFromIntError {
|
||||
match x {}
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "never_type", issue = "35121")]
|
||||
impl const From<!> for TryFromIntError {
|
||||
impl From<!> for TryFromIntError {
|
||||
fn from(never: !) -> TryFromIntError {
|
||||
// Match rather than coerce to make sure that code like
|
||||
// `From<Infallible> for TryFromIntError` above will keep working
|
||||
|
@ -785,7 +785,7 @@ macro_rules! int_impl {
|
||||
// SAFETY: the caller must uphold the safety contract for
|
||||
// `unchecked_shl`.
|
||||
// Any legal shift amount is losslessly representable in the self type.
|
||||
unsafe { intrinsics::unchecked_shl(self, rhs.try_into().ok().unwrap_unchecked()) }
|
||||
unsafe { intrinsics::unchecked_shl(self, conv_rhs_for_unchecked_shift!($SelfT, rhs)) }
|
||||
}
|
||||
|
||||
/// Checked shift right. Computes `self >> rhs`, returning `None` if `rhs` is
|
||||
@ -833,7 +833,7 @@ macro_rules! int_impl {
|
||||
// SAFETY: the caller must uphold the safety contract for
|
||||
// `unchecked_shr`.
|
||||
// Any legal shift amount is losslessly representable in the self type.
|
||||
unsafe { intrinsics::unchecked_shr(self, rhs.try_into().ok().unwrap_unchecked()) }
|
||||
unsafe { intrinsics::unchecked_shr(self, conv_rhs_for_unchecked_shift!($SelfT, rhs)) }
|
||||
}
|
||||
|
||||
/// Checked absolute value. Computes `self.abs()`, returning `None` if
|
||||
@ -2603,13 +2603,16 @@ macro_rules! int_impl {
|
||||
#[must_use = "this returns the result of the operation, \
|
||||
without modifying the original"]
|
||||
#[inline(always)]
|
||||
#[rustc_allow_const_fn_unstable(const_cmp)]
|
||||
pub const fn signum(self) -> Self {
|
||||
// Picking the right way to phrase this is complicated
|
||||
// (<https://graphics.stanford.edu/~seander/bithacks.html#CopyIntegerSign>)
|
||||
// so delegate it to `Ord` which is already producing -1/0/+1
|
||||
// exactly like we need and can be the place to deal with the complexity.
|
||||
self.cmp(&0) as _
|
||||
|
||||
// FIXME(const-hack): replace with cmp
|
||||
if self < 0 { -1 }
|
||||
else if self == 0 { 0 }
|
||||
else { 1 }
|
||||
}
|
||||
|
||||
/// Returns `true` if `self` is positive and `false` if the number is zero or
|
||||
|
@ -225,6 +225,23 @@ macro_rules! widening_impl {
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! conv_rhs_for_unchecked_shift {
|
||||
($SelfT:ty, $x:expr) => {{
|
||||
#[inline]
|
||||
fn conv(x: u32) -> $SelfT {
|
||||
// FIXME(const-hack) replace with `.try_into().ok().unwrap_unchecked()`.
|
||||
// SAFETY: Any legal shift amount must be losslessly representable in the self type.
|
||||
unsafe { x.try_into().ok().unwrap_unchecked() }
|
||||
}
|
||||
#[inline]
|
||||
const fn const_conv(x: u32) -> $SelfT {
|
||||
x as _
|
||||
}
|
||||
|
||||
intrinsics::const_eval_select(($x,), const_conv, conv)
|
||||
}};
|
||||
}
|
||||
|
||||
impl i8 {
|
||||
int_impl! {
|
||||
Self = i8,
|
||||
|
@ -96,8 +96,7 @@ macro_rules! nonzero_integers {
|
||||
}
|
||||
|
||||
#[stable(feature = "from_nonzero", since = "1.31.0")]
|
||||
#[rustc_const_unstable(feature = "const_num_from_num", issue = "87852")]
|
||||
impl const From<$Ty> for $Int {
|
||||
impl From<$Ty> for $Int {
|
||||
#[doc = concat!("Converts a `", stringify!($Ty), "` into an `", stringify!($Int), "`")]
|
||||
#[inline]
|
||||
fn from(nonzero: $Ty) -> Self {
|
||||
@ -106,8 +105,7 @@ macro_rules! nonzero_integers {
|
||||
}
|
||||
|
||||
#[stable(feature = "nonzero_bitor", since = "1.45.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const BitOr for $Ty {
|
||||
impl BitOr for $Ty {
|
||||
type Output = Self;
|
||||
#[inline]
|
||||
fn bitor(self, rhs: Self) -> Self::Output {
|
||||
@ -118,8 +116,7 @@ macro_rules! nonzero_integers {
|
||||
}
|
||||
|
||||
#[stable(feature = "nonzero_bitor", since = "1.45.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const BitOr<$Int> for $Ty {
|
||||
impl BitOr<$Int> for $Ty {
|
||||
type Output = Self;
|
||||
#[inline]
|
||||
fn bitor(self, rhs: $Int) -> Self::Output {
|
||||
@ -131,8 +128,7 @@ macro_rules! nonzero_integers {
|
||||
}
|
||||
|
||||
#[stable(feature = "nonzero_bitor", since = "1.45.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const BitOr<$Ty> for $Int {
|
||||
impl BitOr<$Ty> for $Int {
|
||||
type Output = $Ty;
|
||||
#[inline]
|
||||
fn bitor(self, rhs: $Ty) -> Self::Output {
|
||||
@ -144,8 +140,7 @@ macro_rules! nonzero_integers {
|
||||
}
|
||||
|
||||
#[stable(feature = "nonzero_bitor", since = "1.45.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const BitOrAssign for $Ty {
|
||||
impl BitOrAssign for $Ty {
|
||||
#[inline]
|
||||
fn bitor_assign(&mut self, rhs: Self) {
|
||||
*self = *self | rhs;
|
||||
@ -153,8 +148,7 @@ macro_rules! nonzero_integers {
|
||||
}
|
||||
|
||||
#[stable(feature = "nonzero_bitor", since = "1.45.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const BitOrAssign<$Int> for $Ty {
|
||||
impl BitOrAssign<$Int> for $Ty {
|
||||
#[inline]
|
||||
fn bitor_assign(&mut self, rhs: $Int) {
|
||||
*self = *self | rhs;
|
||||
@ -276,8 +270,7 @@ macro_rules! nonzero_integers_div {
|
||||
( $( $Ty: ident($Int: ty); )+ ) => {
|
||||
$(
|
||||
#[stable(feature = "nonzero_div", since = "1.51.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const Div<$Ty> for $Int {
|
||||
impl Div<$Ty> for $Int {
|
||||
type Output = $Int;
|
||||
/// This operation rounds towards zero,
|
||||
/// truncating any fractional part of the exact result, and cannot panic.
|
||||
@ -290,8 +283,7 @@ macro_rules! nonzero_integers_div {
|
||||
}
|
||||
|
||||
#[stable(feature = "nonzero_div", since = "1.51.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const Rem<$Ty> for $Int {
|
||||
impl Rem<$Ty> for $Int {
|
||||
type Output = $Int;
|
||||
/// This operation satisfies `n % d == n - (n / d) * d`, and cannot panic.
|
||||
#[inline]
|
||||
|
@ -939,7 +939,7 @@ macro_rules! uint_impl {
|
||||
// SAFETY: the caller must uphold the safety contract for
|
||||
// `unchecked_shl`.
|
||||
// Any legal shift amount is losslessly representable in the self type.
|
||||
unsafe { intrinsics::unchecked_shl(self, rhs.try_into().ok().unwrap_unchecked()) }
|
||||
unsafe { intrinsics::unchecked_shl(self, conv_rhs_for_unchecked_shift!($SelfT, rhs)) }
|
||||
}
|
||||
|
||||
/// Checked shift right. Computes `self >> rhs`, returning `None`
|
||||
@ -987,7 +987,7 @@ macro_rules! uint_impl {
|
||||
// SAFETY: the caller must uphold the safety contract for
|
||||
// `unchecked_shr`.
|
||||
// Any legal shift amount is losslessly representable in the self type.
|
||||
unsafe { intrinsics::unchecked_shr(self, rhs.try_into().ok().unwrap_unchecked()) }
|
||||
unsafe { intrinsics::unchecked_shr(self, conv_rhs_for_unchecked_shift!($SelfT, rhs)) }
|
||||
}
|
||||
|
||||
/// Checked exponentiation. Computes `self.pow(exp)`, returning `None` if
|
||||
|
@ -87,8 +87,7 @@ impl<T: fmt::UpperHex> fmt::UpperHex for Wrapping<T> {
|
||||
macro_rules! sh_impl_signed {
|
||||
($t:ident, $f:ident) => {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const Shl<$f> for Wrapping<$t> {
|
||||
impl Shl<$f> for Wrapping<$t> {
|
||||
type Output = Wrapping<$t>;
|
||||
|
||||
#[inline]
|
||||
@ -100,22 +99,20 @@ macro_rules! sh_impl_signed {
|
||||
}
|
||||
}
|
||||
}
|
||||
forward_ref_binop! { impl const Shl, shl for Wrapping<$t>, $f,
|
||||
forward_ref_binop! { impl Shl, shl for Wrapping<$t>, $f,
|
||||
#[stable(feature = "wrapping_ref_ops", since = "1.39.0")] }
|
||||
|
||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const ShlAssign<$f> for Wrapping<$t> {
|
||||
impl ShlAssign<$f> for Wrapping<$t> {
|
||||
#[inline]
|
||||
fn shl_assign(&mut self, other: $f) {
|
||||
*self = *self << other;
|
||||
}
|
||||
}
|
||||
forward_ref_op_assign! { impl const ShlAssign, shl_assign for Wrapping<$t>, $f }
|
||||
forward_ref_op_assign! { impl ShlAssign, shl_assign for Wrapping<$t>, $f }
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const Shr<$f> for Wrapping<$t> {
|
||||
impl Shr<$f> for Wrapping<$t> {
|
||||
type Output = Wrapping<$t>;
|
||||
|
||||
#[inline]
|
||||
@ -127,26 +124,24 @@ macro_rules! sh_impl_signed {
|
||||
}
|
||||
}
|
||||
}
|
||||
forward_ref_binop! { impl const Shr, shr for Wrapping<$t>, $f,
|
||||
forward_ref_binop! { impl Shr, shr for Wrapping<$t>, $f,
|
||||
#[stable(feature = "wrapping_ref_ops", since = "1.39.0")] }
|
||||
|
||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const ShrAssign<$f> for Wrapping<$t> {
|
||||
impl ShrAssign<$f> for Wrapping<$t> {
|
||||
#[inline]
|
||||
fn shr_assign(&mut self, other: $f) {
|
||||
*self = *self >> other;
|
||||
}
|
||||
}
|
||||
forward_ref_op_assign! { impl const ShrAssign, shr_assign for Wrapping<$t>, $f }
|
||||
forward_ref_op_assign! { impl ShrAssign, shr_assign for Wrapping<$t>, $f }
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! sh_impl_unsigned {
|
||||
($t:ident, $f:ident) => {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const Shl<$f> for Wrapping<$t> {
|
||||
impl Shl<$f> for Wrapping<$t> {
|
||||
type Output = Wrapping<$t>;
|
||||
|
||||
#[inline]
|
||||
@ -154,22 +149,20 @@ macro_rules! sh_impl_unsigned {
|
||||
Wrapping(self.0.wrapping_shl((other & self::shift_max::$t as $f) as u32))
|
||||
}
|
||||
}
|
||||
forward_ref_binop! { impl const Shl, shl for Wrapping<$t>, $f,
|
||||
forward_ref_binop! { impl Shl, shl for Wrapping<$t>, $f,
|
||||
#[stable(feature = "wrapping_ref_ops", since = "1.39.0")] }
|
||||
|
||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const ShlAssign<$f> for Wrapping<$t> {
|
||||
impl ShlAssign<$f> for Wrapping<$t> {
|
||||
#[inline]
|
||||
fn shl_assign(&mut self, other: $f) {
|
||||
*self = *self << other;
|
||||
}
|
||||
}
|
||||
forward_ref_op_assign! { impl const ShlAssign, shl_assign for Wrapping<$t>, $f }
|
||||
forward_ref_op_assign! { impl ShlAssign, shl_assign for Wrapping<$t>, $f }
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const Shr<$f> for Wrapping<$t> {
|
||||
impl Shr<$f> for Wrapping<$t> {
|
||||
type Output = Wrapping<$t>;
|
||||
|
||||
#[inline]
|
||||
@ -177,18 +170,17 @@ macro_rules! sh_impl_unsigned {
|
||||
Wrapping(self.0.wrapping_shr((other & self::shift_max::$t as $f) as u32))
|
||||
}
|
||||
}
|
||||
forward_ref_binop! { impl const Shr, shr for Wrapping<$t>, $f,
|
||||
forward_ref_binop! { impl Shr, shr for Wrapping<$t>, $f,
|
||||
#[stable(feature = "wrapping_ref_ops", since = "1.39.0")] }
|
||||
|
||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const ShrAssign<$f> for Wrapping<$t> {
|
||||
impl ShrAssign<$f> for Wrapping<$t> {
|
||||
#[inline]
|
||||
fn shr_assign(&mut self, other: $f) {
|
||||
*self = *self >> other;
|
||||
}
|
||||
}
|
||||
forward_ref_op_assign! { impl const ShrAssign, shr_assign for Wrapping<$t>, $f }
|
||||
forward_ref_op_assign! { impl ShrAssign, shr_assign for Wrapping<$t>, $f }
|
||||
};
|
||||
}
|
||||
|
||||
@ -217,8 +209,7 @@ sh_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize }
|
||||
macro_rules! wrapping_impl {
|
||||
($($t:ty)*) => ($(
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const Add for Wrapping<$t> {
|
||||
impl Add for Wrapping<$t> {
|
||||
type Output = Wrapping<$t>;
|
||||
|
||||
#[inline]
|
||||
@ -226,32 +217,29 @@ macro_rules! wrapping_impl {
|
||||
Wrapping(self.0.wrapping_add(other.0))
|
||||
}
|
||||
}
|
||||
forward_ref_binop! { impl const Add, add for Wrapping<$t>, Wrapping<$t>,
|
||||
forward_ref_binop! { impl Add, add for Wrapping<$t>, Wrapping<$t>,
|
||||
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
|
||||
|
||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const AddAssign for Wrapping<$t> {
|
||||
impl AddAssign for Wrapping<$t> {
|
||||
#[inline]
|
||||
fn add_assign(&mut self, other: Wrapping<$t>) {
|
||||
*self = *self + other;
|
||||
}
|
||||
}
|
||||
forward_ref_op_assign! { impl const AddAssign, add_assign for Wrapping<$t>, Wrapping<$t> }
|
||||
forward_ref_op_assign! { impl AddAssign, add_assign for Wrapping<$t>, Wrapping<$t> }
|
||||
|
||||
#[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const AddAssign<$t> for Wrapping<$t> {
|
||||
impl AddAssign<$t> for Wrapping<$t> {
|
||||
#[inline]
|
||||
fn add_assign(&mut self, other: $t) {
|
||||
*self = *self + Wrapping(other);
|
||||
}
|
||||
}
|
||||
forward_ref_op_assign! { impl const AddAssign, add_assign for Wrapping<$t>, $t }
|
||||
forward_ref_op_assign! { impl AddAssign, add_assign for Wrapping<$t>, $t }
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const Sub for Wrapping<$t> {
|
||||
impl Sub for Wrapping<$t> {
|
||||
type Output = Wrapping<$t>;
|
||||
|
||||
#[inline]
|
||||
@ -259,32 +247,29 @@ macro_rules! wrapping_impl {
|
||||
Wrapping(self.0.wrapping_sub(other.0))
|
||||
}
|
||||
}
|
||||
forward_ref_binop! { impl const Sub, sub for Wrapping<$t>, Wrapping<$t>,
|
||||
forward_ref_binop! { impl Sub, sub for Wrapping<$t>, Wrapping<$t>,
|
||||
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
|
||||
|
||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const SubAssign for Wrapping<$t> {
|
||||
impl SubAssign for Wrapping<$t> {
|
||||
#[inline]
|
||||
fn sub_assign(&mut self, other: Wrapping<$t>) {
|
||||
*self = *self - other;
|
||||
}
|
||||
}
|
||||
forward_ref_op_assign! { impl const SubAssign, sub_assign for Wrapping<$t>, Wrapping<$t> }
|
||||
forward_ref_op_assign! { impl SubAssign, sub_assign for Wrapping<$t>, Wrapping<$t> }
|
||||
|
||||
#[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const SubAssign<$t> for Wrapping<$t> {
|
||||
impl SubAssign<$t> for Wrapping<$t> {
|
||||
#[inline]
|
||||
fn sub_assign(&mut self, other: $t) {
|
||||
*self = *self - Wrapping(other);
|
||||
}
|
||||
}
|
||||
forward_ref_op_assign! { impl const SubAssign, sub_assign for Wrapping<$t>, $t }
|
||||
forward_ref_op_assign! { impl SubAssign, sub_assign for Wrapping<$t>, $t }
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const Mul for Wrapping<$t> {
|
||||
impl Mul for Wrapping<$t> {
|
||||
type Output = Wrapping<$t>;
|
||||
|
||||
#[inline]
|
||||
@ -296,28 +281,25 @@ macro_rules! wrapping_impl {
|
||||
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
|
||||
|
||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const MulAssign for Wrapping<$t> {
|
||||
impl MulAssign for Wrapping<$t> {
|
||||
#[inline]
|
||||
fn mul_assign(&mut self, other: Wrapping<$t>) {
|
||||
*self = *self * other;
|
||||
}
|
||||
}
|
||||
forward_ref_op_assign! { impl const MulAssign, mul_assign for Wrapping<$t>, Wrapping<$t> }
|
||||
forward_ref_op_assign! { impl MulAssign, mul_assign for Wrapping<$t>, Wrapping<$t> }
|
||||
|
||||
#[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const MulAssign<$t> for Wrapping<$t> {
|
||||
impl MulAssign<$t> for Wrapping<$t> {
|
||||
#[inline]
|
||||
fn mul_assign(&mut self, other: $t) {
|
||||
*self = *self * Wrapping(other);
|
||||
}
|
||||
}
|
||||
forward_ref_op_assign! { impl const MulAssign, mul_assign for Wrapping<$t>, $t }
|
||||
forward_ref_op_assign! { impl MulAssign, mul_assign for Wrapping<$t>, $t }
|
||||
|
||||
#[stable(feature = "wrapping_div", since = "1.3.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const Div for Wrapping<$t> {
|
||||
impl Div for Wrapping<$t> {
|
||||
type Output = Wrapping<$t>;
|
||||
|
||||
#[inline]
|
||||
@ -325,32 +307,29 @@ macro_rules! wrapping_impl {
|
||||
Wrapping(self.0.wrapping_div(other.0))
|
||||
}
|
||||
}
|
||||
forward_ref_binop! { impl const Div, div for Wrapping<$t>, Wrapping<$t>,
|
||||
forward_ref_binop! { impl Div, div for Wrapping<$t>, Wrapping<$t>,
|
||||
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
|
||||
|
||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const DivAssign for Wrapping<$t> {
|
||||
impl DivAssign for Wrapping<$t> {
|
||||
#[inline]
|
||||
fn div_assign(&mut self, other: Wrapping<$t>) {
|
||||
*self = *self / other;
|
||||
}
|
||||
}
|
||||
forward_ref_op_assign! { impl const DivAssign, div_assign for Wrapping<$t>, Wrapping<$t> }
|
||||
forward_ref_op_assign! { impl DivAssign, div_assign for Wrapping<$t>, Wrapping<$t> }
|
||||
|
||||
#[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const DivAssign<$t> for Wrapping<$t> {
|
||||
impl DivAssign<$t> for Wrapping<$t> {
|
||||
#[inline]
|
||||
fn div_assign(&mut self, other: $t) {
|
||||
*self = *self / Wrapping(other);
|
||||
}
|
||||
}
|
||||
forward_ref_op_assign! { impl const DivAssign, div_assign for Wrapping<$t>, $t }
|
||||
forward_ref_op_assign! { impl DivAssign, div_assign for Wrapping<$t>, $t }
|
||||
|
||||
#[stable(feature = "wrapping_impls", since = "1.7.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const Rem for Wrapping<$t> {
|
||||
impl Rem for Wrapping<$t> {
|
||||
type Output = Wrapping<$t>;
|
||||
|
||||
#[inline]
|
||||
@ -358,32 +337,29 @@ macro_rules! wrapping_impl {
|
||||
Wrapping(self.0.wrapping_rem(other.0))
|
||||
}
|
||||
}
|
||||
forward_ref_binop! { impl const Rem, rem for Wrapping<$t>, Wrapping<$t>,
|
||||
forward_ref_binop! { impl Rem, rem for Wrapping<$t>, Wrapping<$t>,
|
||||
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
|
||||
|
||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const RemAssign for Wrapping<$t> {
|
||||
impl RemAssign for Wrapping<$t> {
|
||||
#[inline]
|
||||
fn rem_assign(&mut self, other: Wrapping<$t>) {
|
||||
*self = *self % other;
|
||||
}
|
||||
}
|
||||
forward_ref_op_assign! { impl const RemAssign, rem_assign for Wrapping<$t>, Wrapping<$t> }
|
||||
forward_ref_op_assign! { impl RemAssign, rem_assign for Wrapping<$t>, Wrapping<$t> }
|
||||
|
||||
#[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const RemAssign<$t> for Wrapping<$t> {
|
||||
impl RemAssign<$t> for Wrapping<$t> {
|
||||
#[inline]
|
||||
fn rem_assign(&mut self, other: $t) {
|
||||
*self = *self % Wrapping(other);
|
||||
}
|
||||
}
|
||||
forward_ref_op_assign! { impl const RemAssign, rem_assign for Wrapping<$t>, $t }
|
||||
forward_ref_op_assign! { impl RemAssign, rem_assign for Wrapping<$t>, $t }
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const Not for Wrapping<$t> {
|
||||
impl Not for Wrapping<$t> {
|
||||
type Output = Wrapping<$t>;
|
||||
|
||||
#[inline]
|
||||
@ -391,12 +367,11 @@ macro_rules! wrapping_impl {
|
||||
Wrapping(!self.0)
|
||||
}
|
||||
}
|
||||
forward_ref_unop! { impl const Not, not for Wrapping<$t>,
|
||||
forward_ref_unop! { impl Not, not for Wrapping<$t>,
|
||||
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const BitXor for Wrapping<$t> {
|
||||
impl BitXor for Wrapping<$t> {
|
||||
type Output = Wrapping<$t>;
|
||||
|
||||
#[inline]
|
||||
@ -404,32 +379,29 @@ macro_rules! wrapping_impl {
|
||||
Wrapping(self.0 ^ other.0)
|
||||
}
|
||||
}
|
||||
forward_ref_binop! { impl const BitXor, bitxor for Wrapping<$t>, Wrapping<$t>,
|
||||
forward_ref_binop! { impl BitXor, bitxor for Wrapping<$t>, Wrapping<$t>,
|
||||
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
|
||||
|
||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const BitXorAssign for Wrapping<$t> {
|
||||
impl BitXorAssign for Wrapping<$t> {
|
||||
#[inline]
|
||||
fn bitxor_assign(&mut self, other: Wrapping<$t>) {
|
||||
*self = *self ^ other;
|
||||
}
|
||||
}
|
||||
forward_ref_op_assign! { impl const BitXorAssign, bitxor_assign for Wrapping<$t>, Wrapping<$t> }
|
||||
forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for Wrapping<$t>, Wrapping<$t> }
|
||||
|
||||
#[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const BitXorAssign<$t> for Wrapping<$t> {
|
||||
impl BitXorAssign<$t> for Wrapping<$t> {
|
||||
#[inline]
|
||||
fn bitxor_assign(&mut self, other: $t) {
|
||||
*self = *self ^ Wrapping(other);
|
||||
}
|
||||
}
|
||||
forward_ref_op_assign! { impl const BitXorAssign, bitxor_assign for Wrapping<$t>, $t }
|
||||
forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for Wrapping<$t>, $t }
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const BitOr for Wrapping<$t> {
|
||||
impl BitOr for Wrapping<$t> {
|
||||
type Output = Wrapping<$t>;
|
||||
|
||||
#[inline]
|
||||
@ -437,32 +409,29 @@ macro_rules! wrapping_impl {
|
||||
Wrapping(self.0 | other.0)
|
||||
}
|
||||
}
|
||||
forward_ref_binop! { impl const BitOr, bitor for Wrapping<$t>, Wrapping<$t>,
|
||||
forward_ref_binop! { impl BitOr, bitor for Wrapping<$t>, Wrapping<$t>,
|
||||
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
|
||||
|
||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const BitOrAssign for Wrapping<$t> {
|
||||
impl BitOrAssign for Wrapping<$t> {
|
||||
#[inline]
|
||||
fn bitor_assign(&mut self, other: Wrapping<$t>) {
|
||||
*self = *self | other;
|
||||
}
|
||||
}
|
||||
forward_ref_op_assign! { impl const BitOrAssign, bitor_assign for Wrapping<$t>, Wrapping<$t> }
|
||||
forward_ref_op_assign! { impl BitOrAssign, bitor_assign for Wrapping<$t>, Wrapping<$t> }
|
||||
|
||||
#[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const BitOrAssign<$t> for Wrapping<$t> {
|
||||
impl BitOrAssign<$t> for Wrapping<$t> {
|
||||
#[inline]
|
||||
fn bitor_assign(&mut self, other: $t) {
|
||||
*self = *self | Wrapping(other);
|
||||
}
|
||||
}
|
||||
forward_ref_op_assign! { impl const BitOrAssign, bitor_assign for Wrapping<$t>, $t }
|
||||
forward_ref_op_assign! { impl BitOrAssign, bitor_assign for Wrapping<$t>, $t }
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const BitAnd for Wrapping<$t> {
|
||||
impl BitAnd for Wrapping<$t> {
|
||||
type Output = Wrapping<$t>;
|
||||
|
||||
#[inline]
|
||||
@ -470,39 +439,36 @@ macro_rules! wrapping_impl {
|
||||
Wrapping(self.0 & other.0)
|
||||
}
|
||||
}
|
||||
forward_ref_binop! { impl const BitAnd, bitand for Wrapping<$t>, Wrapping<$t>,
|
||||
forward_ref_binop! { impl BitAnd, bitand for Wrapping<$t>, Wrapping<$t>,
|
||||
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
|
||||
|
||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const BitAndAssign for Wrapping<$t> {
|
||||
impl BitAndAssign for Wrapping<$t> {
|
||||
#[inline]
|
||||
fn bitand_assign(&mut self, other: Wrapping<$t>) {
|
||||
*self = *self & other;
|
||||
}
|
||||
}
|
||||
forward_ref_op_assign! { impl const BitAndAssign, bitand_assign for Wrapping<$t>, Wrapping<$t> }
|
||||
forward_ref_op_assign! { impl BitAndAssign, bitand_assign for Wrapping<$t>, Wrapping<$t> }
|
||||
|
||||
#[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const BitAndAssign<$t> for Wrapping<$t> {
|
||||
impl BitAndAssign<$t> for Wrapping<$t> {
|
||||
#[inline]
|
||||
fn bitand_assign(&mut self, other: $t) {
|
||||
*self = *self & Wrapping(other);
|
||||
}
|
||||
}
|
||||
forward_ref_op_assign! { impl const BitAndAssign, bitand_assign for Wrapping<$t>, $t }
|
||||
forward_ref_op_assign! { impl BitAndAssign, bitand_assign for Wrapping<$t>, $t }
|
||||
|
||||
#[stable(feature = "wrapping_neg", since = "1.10.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const Neg for Wrapping<$t> {
|
||||
impl Neg for Wrapping<$t> {
|
||||
type Output = Self;
|
||||
#[inline]
|
||||
fn neg(self) -> Self {
|
||||
Wrapping(0) - self
|
||||
}
|
||||
}
|
||||
forward_ref_unop! { impl const Neg, neg for Wrapping<$t>,
|
||||
forward_ref_unop! { impl Neg, neg for Wrapping<$t>,
|
||||
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
|
||||
|
||||
)*)
|
||||
|
@ -73,7 +73,6 @@
|
||||
append_const_msg
|
||||
)]
|
||||
#[doc(alias = "+")]
|
||||
#[const_trait]
|
||||
pub trait Add<Rhs = Self> {
|
||||
/// The resulting type after applying the `+` operator.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -95,8 +94,7 @@ pub trait Add<Rhs = Self> {
|
||||
macro_rules! add_impl {
|
||||
($($t:ty)*) => ($(
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const Add for $t {
|
||||
impl Add for $t {
|
||||
type Output = $t;
|
||||
|
||||
#[inline]
|
||||
@ -104,7 +102,7 @@ macro_rules! add_impl {
|
||||
fn add(self, other: $t) -> $t { self + other }
|
||||
}
|
||||
|
||||
forward_ref_binop! { impl const Add, add for $t, $t }
|
||||
forward_ref_binop! { impl Add, add for $t, $t }
|
||||
)*)
|
||||
}
|
||||
|
||||
@ -183,7 +181,6 @@ add_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
|
||||
append_const_msg
|
||||
)]
|
||||
#[doc(alias = "-")]
|
||||
#[const_trait]
|
||||
pub trait Sub<Rhs = Self> {
|
||||
/// The resulting type after applying the `-` operator.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -205,8 +202,7 @@ pub trait Sub<Rhs = Self> {
|
||||
macro_rules! sub_impl {
|
||||
($($t:ty)*) => ($(
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const Sub for $t {
|
||||
impl Sub for $t {
|
||||
type Output = $t;
|
||||
|
||||
#[inline]
|
||||
@ -214,7 +210,7 @@ macro_rules! sub_impl {
|
||||
fn sub(self, other: $t) -> $t { self - other }
|
||||
}
|
||||
|
||||
forward_ref_binop! { impl const Sub, sub for $t, $t }
|
||||
forward_ref_binop! { impl Sub, sub for $t, $t }
|
||||
)*)
|
||||
}
|
||||
|
||||
@ -314,7 +310,6 @@ sub_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
|
||||
label = "no implementation for `{Self} * {Rhs}`"
|
||||
)]
|
||||
#[doc(alias = "*")]
|
||||
#[const_trait]
|
||||
pub trait Mul<Rhs = Self> {
|
||||
/// The resulting type after applying the `*` operator.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -336,8 +331,7 @@ pub trait Mul<Rhs = Self> {
|
||||
macro_rules! mul_impl {
|
||||
($($t:ty)*) => ($(
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const Mul for $t {
|
||||
impl Mul for $t {
|
||||
type Output = $t;
|
||||
|
||||
#[inline]
|
||||
@ -345,7 +339,7 @@ macro_rules! mul_impl {
|
||||
fn mul(self, other: $t) -> $t { self * other }
|
||||
}
|
||||
|
||||
forward_ref_binop! { impl const Mul, mul for $t, $t }
|
||||
forward_ref_binop! { impl Mul, mul for $t, $t }
|
||||
)*)
|
||||
}
|
||||
|
||||
@ -449,7 +443,6 @@ mul_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
|
||||
label = "no implementation for `{Self} / {Rhs}`"
|
||||
)]
|
||||
#[doc(alias = "/")]
|
||||
#[const_trait]
|
||||
pub trait Div<Rhs = Self> {
|
||||
/// The resulting type after applying the `/` operator.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -477,15 +470,14 @@ macro_rules! div_impl_integer {
|
||||
///
|
||||
#[doc = $panic]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const Div for $t {
|
||||
impl Div for $t {
|
||||
type Output = $t;
|
||||
|
||||
#[inline]
|
||||
fn div(self, other: $t) -> $t { self / other }
|
||||
}
|
||||
|
||||
forward_ref_binop! { impl const Div, div for $t, $t }
|
||||
forward_ref_binop! { impl Div, div for $t, $t }
|
||||
)*)*)
|
||||
}
|
||||
|
||||
@ -497,15 +489,14 @@ div_impl_integer! {
|
||||
macro_rules! div_impl_float {
|
||||
($($t:ty)*) => ($(
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const Div for $t {
|
||||
impl Div for $t {
|
||||
type Output = $t;
|
||||
|
||||
#[inline]
|
||||
fn div(self, other: $t) -> $t { self / other }
|
||||
}
|
||||
|
||||
forward_ref_binop! { impl const Div, div for $t, $t }
|
||||
forward_ref_binop! { impl Div, div for $t, $t }
|
||||
)*)
|
||||
}
|
||||
|
||||
@ -553,7 +544,6 @@ div_impl_float! { f32 f64 }
|
||||
label = "no implementation for `{Self} % {Rhs}`"
|
||||
)]
|
||||
#[doc(alias = "%")]
|
||||
#[const_trait]
|
||||
pub trait Rem<Rhs = Self> {
|
||||
/// The resulting type after applying the `%` operator.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -581,15 +571,14 @@ macro_rules! rem_impl_integer {
|
||||
///
|
||||
#[doc = $panic]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const Rem for $t {
|
||||
impl Rem for $t {
|
||||
type Output = $t;
|
||||
|
||||
#[inline]
|
||||
fn rem(self, other: $t) -> $t { self % other }
|
||||
}
|
||||
|
||||
forward_ref_binop! { impl const Rem, rem for $t, $t }
|
||||
forward_ref_binop! { impl Rem, rem for $t, $t }
|
||||
)*)*)
|
||||
}
|
||||
|
||||
@ -616,15 +605,14 @@ macro_rules! rem_impl_float {
|
||||
/// assert_eq!(x % y, remainder);
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const Rem for $t {
|
||||
impl Rem for $t {
|
||||
type Output = $t;
|
||||
|
||||
#[inline]
|
||||
fn rem(self, other: $t) -> $t { self % other }
|
||||
}
|
||||
|
||||
forward_ref_binop! { impl const Rem, rem for $t, $t }
|
||||
forward_ref_binop! { impl Rem, rem for $t, $t }
|
||||
)*)
|
||||
}
|
||||
|
||||
@ -669,7 +657,6 @@ rem_impl_float! { f32 f64 }
|
||||
#[lang = "neg"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[doc(alias = "-")]
|
||||
#[const_trait]
|
||||
pub trait Neg {
|
||||
/// The resulting type after applying the `-` operator.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -692,8 +679,7 @@ pub trait Neg {
|
||||
macro_rules! neg_impl {
|
||||
($($t:ty)*) => ($(
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const Neg for $t {
|
||||
impl Neg for $t {
|
||||
type Output = $t;
|
||||
|
||||
#[inline]
|
||||
@ -701,7 +687,7 @@ macro_rules! neg_impl {
|
||||
fn neg(self) -> $t { -self }
|
||||
}
|
||||
|
||||
forward_ref_unop! { impl const Neg, neg for $t }
|
||||
forward_ref_unop! { impl Neg, neg for $t }
|
||||
)*)
|
||||
}
|
||||
|
||||
@ -744,7 +730,6 @@ neg_impl! { isize i8 i16 i32 i64 i128 f32 f64 }
|
||||
)]
|
||||
#[doc(alias = "+")]
|
||||
#[doc(alias = "+=")]
|
||||
#[const_trait]
|
||||
pub trait AddAssign<Rhs = Self> {
|
||||
/// Performs the `+=` operation.
|
||||
///
|
||||
@ -762,14 +747,13 @@ pub trait AddAssign<Rhs = Self> {
|
||||
macro_rules! add_assign_impl {
|
||||
($($t:ty)+) => ($(
|
||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const AddAssign for $t {
|
||||
impl AddAssign for $t {
|
||||
#[inline]
|
||||
#[rustc_inherit_overflow_checks]
|
||||
fn add_assign(&mut self, other: $t) { *self += other }
|
||||
}
|
||||
|
||||
forward_ref_op_assign! { impl const AddAssign, add_assign for $t, $t }
|
||||
forward_ref_op_assign! { impl AddAssign, add_assign for $t, $t }
|
||||
)+)
|
||||
}
|
||||
|
||||
@ -812,7 +796,6 @@ add_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
|
||||
)]
|
||||
#[doc(alias = "-")]
|
||||
#[doc(alias = "-=")]
|
||||
#[const_trait]
|
||||
pub trait SubAssign<Rhs = Self> {
|
||||
/// Performs the `-=` operation.
|
||||
///
|
||||
@ -830,14 +813,13 @@ pub trait SubAssign<Rhs = Self> {
|
||||
macro_rules! sub_assign_impl {
|
||||
($($t:ty)+) => ($(
|
||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const SubAssign for $t {
|
||||
impl SubAssign for $t {
|
||||
#[inline]
|
||||
#[rustc_inherit_overflow_checks]
|
||||
fn sub_assign(&mut self, other: $t) { *self -= other }
|
||||
}
|
||||
|
||||
forward_ref_op_assign! { impl const SubAssign, sub_assign for $t, $t }
|
||||
forward_ref_op_assign! { impl SubAssign, sub_assign for $t, $t }
|
||||
)+)
|
||||
}
|
||||
|
||||
@ -871,7 +853,6 @@ sub_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
|
||||
)]
|
||||
#[doc(alias = "*")]
|
||||
#[doc(alias = "*=")]
|
||||
#[const_trait]
|
||||
pub trait MulAssign<Rhs = Self> {
|
||||
/// Performs the `*=` operation.
|
||||
///
|
||||
@ -889,14 +870,13 @@ pub trait MulAssign<Rhs = Self> {
|
||||
macro_rules! mul_assign_impl {
|
||||
($($t:ty)+) => ($(
|
||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const MulAssign for $t {
|
||||
impl MulAssign for $t {
|
||||
#[inline]
|
||||
#[rustc_inherit_overflow_checks]
|
||||
fn mul_assign(&mut self, other: $t) { *self *= other }
|
||||
}
|
||||
|
||||
forward_ref_op_assign! { impl const MulAssign, mul_assign for $t, $t }
|
||||
forward_ref_op_assign! { impl MulAssign, mul_assign for $t, $t }
|
||||
)+)
|
||||
}
|
||||
|
||||
@ -930,7 +910,6 @@ mul_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
|
||||
)]
|
||||
#[doc(alias = "/")]
|
||||
#[doc(alias = "/=")]
|
||||
#[const_trait]
|
||||
pub trait DivAssign<Rhs = Self> {
|
||||
/// Performs the `/=` operation.
|
||||
///
|
||||
@ -948,13 +927,12 @@ pub trait DivAssign<Rhs = Self> {
|
||||
macro_rules! div_assign_impl {
|
||||
($($t:ty)+) => ($(
|
||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const DivAssign for $t {
|
||||
impl DivAssign for $t {
|
||||
#[inline]
|
||||
fn div_assign(&mut self, other: $t) { *self /= other }
|
||||
}
|
||||
|
||||
forward_ref_op_assign! { impl const DivAssign, div_assign for $t, $t }
|
||||
forward_ref_op_assign! { impl DivAssign, div_assign for $t, $t }
|
||||
)+)
|
||||
}
|
||||
|
||||
@ -992,7 +970,6 @@ div_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
|
||||
)]
|
||||
#[doc(alias = "%")]
|
||||
#[doc(alias = "%=")]
|
||||
#[const_trait]
|
||||
pub trait RemAssign<Rhs = Self> {
|
||||
/// Performs the `%=` operation.
|
||||
///
|
||||
@ -1010,13 +987,12 @@ pub trait RemAssign<Rhs = Self> {
|
||||
macro_rules! rem_assign_impl {
|
||||
($($t:ty)+) => ($(
|
||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const RemAssign for $t {
|
||||
impl RemAssign for $t {
|
||||
#[inline]
|
||||
fn rem_assign(&mut self, other: $t) { *self %= other }
|
||||
}
|
||||
|
||||
forward_ref_op_assign! { impl const RemAssign, rem_assign for $t, $t }
|
||||
forward_ref_op_assign! { impl RemAssign, rem_assign for $t, $t }
|
||||
)+)
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,6 @@
|
||||
#[lang = "not"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[doc(alias = "!")]
|
||||
#[const_trait]
|
||||
pub trait Not {
|
||||
/// The resulting type after applying the `!` operator.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -55,23 +54,21 @@ pub trait Not {
|
||||
macro_rules! not_impl {
|
||||
($($t:ty)*) => ($(
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const Not for $t {
|
||||
impl Not for $t {
|
||||
type Output = $t;
|
||||
|
||||
#[inline]
|
||||
fn not(self) -> $t { !self }
|
||||
}
|
||||
|
||||
forward_ref_unop! { impl const Not, not for $t }
|
||||
forward_ref_unop! { impl Not, not for $t }
|
||||
)*)
|
||||
}
|
||||
|
||||
not_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
|
||||
|
||||
#[stable(feature = "not_never", since = "1.60.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const Not for ! {
|
||||
impl Not for ! {
|
||||
type Output = !;
|
||||
|
||||
#[inline]
|
||||
@ -144,7 +141,6 @@ impl const Not for ! {
|
||||
message = "no implementation for `{Self} & {Rhs}`",
|
||||
label = "no implementation for `{Self} & {Rhs}`"
|
||||
)]
|
||||
#[const_trait]
|
||||
pub trait BitAnd<Rhs = Self> {
|
||||
/// The resulting type after applying the `&` operator.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -168,15 +164,14 @@ pub trait BitAnd<Rhs = Self> {
|
||||
macro_rules! bitand_impl {
|
||||
($($t:ty)*) => ($(
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const BitAnd for $t {
|
||||
impl BitAnd for $t {
|
||||
type Output = $t;
|
||||
|
||||
#[inline]
|
||||
fn bitand(self, rhs: $t) -> $t { self & rhs }
|
||||
}
|
||||
|
||||
forward_ref_binop! { impl const BitAnd, bitand for $t, $t }
|
||||
forward_ref_binop! { impl BitAnd, bitand for $t, $t }
|
||||
)*)
|
||||
}
|
||||
|
||||
@ -246,7 +241,6 @@ bitand_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
|
||||
message = "no implementation for `{Self} | {Rhs}`",
|
||||
label = "no implementation for `{Self} | {Rhs}`"
|
||||
)]
|
||||
#[const_trait]
|
||||
pub trait BitOr<Rhs = Self> {
|
||||
/// The resulting type after applying the `|` operator.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -270,15 +264,14 @@ pub trait BitOr<Rhs = Self> {
|
||||
macro_rules! bitor_impl {
|
||||
($($t:ty)*) => ($(
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const BitOr for $t {
|
||||
impl BitOr for $t {
|
||||
type Output = $t;
|
||||
|
||||
#[inline]
|
||||
fn bitor(self, rhs: $t) -> $t { self | rhs }
|
||||
}
|
||||
|
||||
forward_ref_binop! { impl const BitOr, bitor for $t, $t }
|
||||
forward_ref_binop! { impl BitOr, bitor for $t, $t }
|
||||
)*)
|
||||
}
|
||||
|
||||
@ -348,7 +341,6 @@ bitor_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
|
||||
message = "no implementation for `{Self} ^ {Rhs}`",
|
||||
label = "no implementation for `{Self} ^ {Rhs}`"
|
||||
)]
|
||||
#[const_trait]
|
||||
pub trait BitXor<Rhs = Self> {
|
||||
/// The resulting type after applying the `^` operator.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -372,15 +364,14 @@ pub trait BitXor<Rhs = Self> {
|
||||
macro_rules! bitxor_impl {
|
||||
($($t:ty)*) => ($(
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const BitXor for $t {
|
||||
impl BitXor for $t {
|
||||
type Output = $t;
|
||||
|
||||
#[inline]
|
||||
fn bitxor(self, other: $t) -> $t { self ^ other }
|
||||
}
|
||||
|
||||
forward_ref_binop! { impl const BitXor, bitxor for $t, $t }
|
||||
forward_ref_binop! { impl BitXor, bitxor for $t, $t }
|
||||
)*)
|
||||
}
|
||||
|
||||
@ -449,7 +440,6 @@ bitxor_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
|
||||
message = "no implementation for `{Self} << {Rhs}`",
|
||||
label = "no implementation for `{Self} << {Rhs}`"
|
||||
)]
|
||||
#[const_trait]
|
||||
pub trait Shl<Rhs = Self> {
|
||||
/// The resulting type after applying the `<<` operator.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -471,8 +461,7 @@ pub trait Shl<Rhs = Self> {
|
||||
macro_rules! shl_impl {
|
||||
($t:ty, $f:ty) => {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const Shl<$f> for $t {
|
||||
impl Shl<$f> for $t {
|
||||
type Output = $t;
|
||||
|
||||
#[inline]
|
||||
@ -482,7 +471,7 @@ macro_rules! shl_impl {
|
||||
}
|
||||
}
|
||||
|
||||
forward_ref_binop! { impl const Shl, shl for $t, $f }
|
||||
forward_ref_binop! { impl Shl, shl for $t, $f }
|
||||
};
|
||||
}
|
||||
|
||||
@ -569,7 +558,6 @@ shl_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 isize i128 }
|
||||
message = "no implementation for `{Self} >> {Rhs}`",
|
||||
label = "no implementation for `{Self} >> {Rhs}`"
|
||||
)]
|
||||
#[const_trait]
|
||||
pub trait Shr<Rhs = Self> {
|
||||
/// The resulting type after applying the `>>` operator.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -591,8 +579,7 @@ pub trait Shr<Rhs = Self> {
|
||||
macro_rules! shr_impl {
|
||||
($t:ty, $f:ty) => {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const Shr<$f> for $t {
|
||||
impl Shr<$f> for $t {
|
||||
type Output = $t;
|
||||
|
||||
#[inline]
|
||||
@ -602,7 +589,7 @@ macro_rules! shr_impl {
|
||||
}
|
||||
}
|
||||
|
||||
forward_ref_binop! { impl const Shr, shr for $t, $f }
|
||||
forward_ref_binop! { impl Shr, shr for $t, $f }
|
||||
};
|
||||
}
|
||||
|
||||
@ -698,7 +685,6 @@ shr_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize }
|
||||
message = "no implementation for `{Self} &= {Rhs}`",
|
||||
label = "no implementation for `{Self} &= {Rhs}`"
|
||||
)]
|
||||
#[const_trait]
|
||||
pub trait BitAndAssign<Rhs = Self> {
|
||||
/// Performs the `&=` operation.
|
||||
///
|
||||
@ -728,13 +714,12 @@ pub trait BitAndAssign<Rhs = Self> {
|
||||
macro_rules! bitand_assign_impl {
|
||||
($($t:ty)+) => ($(
|
||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const BitAndAssign for $t {
|
||||
impl BitAndAssign for $t {
|
||||
#[inline]
|
||||
fn bitand_assign(&mut self, other: $t) { *self &= other }
|
||||
}
|
||||
|
||||
forward_ref_op_assign! { impl const BitAndAssign, bitand_assign for $t, $t }
|
||||
forward_ref_op_assign! { impl BitAndAssign, bitand_assign for $t, $t }
|
||||
)+)
|
||||
}
|
||||
|
||||
@ -771,7 +756,6 @@ bitand_assign_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
|
||||
message = "no implementation for `{Self} |= {Rhs}`",
|
||||
label = "no implementation for `{Self} |= {Rhs}`"
|
||||
)]
|
||||
#[const_trait]
|
||||
pub trait BitOrAssign<Rhs = Self> {
|
||||
/// Performs the `|=` operation.
|
||||
///
|
||||
@ -801,13 +785,12 @@ pub trait BitOrAssign<Rhs = Self> {
|
||||
macro_rules! bitor_assign_impl {
|
||||
($($t:ty)+) => ($(
|
||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const BitOrAssign for $t {
|
||||
impl BitOrAssign for $t {
|
||||
#[inline]
|
||||
fn bitor_assign(&mut self, other: $t) { *self |= other }
|
||||
}
|
||||
|
||||
forward_ref_op_assign! { impl const BitOrAssign, bitor_assign for $t, $t }
|
||||
forward_ref_op_assign! { impl BitOrAssign, bitor_assign for $t, $t }
|
||||
)+)
|
||||
}
|
||||
|
||||
@ -844,7 +827,6 @@ bitor_assign_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
|
||||
message = "no implementation for `{Self} ^= {Rhs}`",
|
||||
label = "no implementation for `{Self} ^= {Rhs}`"
|
||||
)]
|
||||
#[const_trait]
|
||||
pub trait BitXorAssign<Rhs = Self> {
|
||||
/// Performs the `^=` operation.
|
||||
///
|
||||
@ -874,13 +856,12 @@ pub trait BitXorAssign<Rhs = Self> {
|
||||
macro_rules! bitxor_assign_impl {
|
||||
($($t:ty)+) => ($(
|
||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const BitXorAssign for $t {
|
||||
impl BitXorAssign for $t {
|
||||
#[inline]
|
||||
fn bitxor_assign(&mut self, other: $t) { *self ^= other }
|
||||
}
|
||||
|
||||
forward_ref_op_assign! { impl const BitXorAssign, bitxor_assign for $t, $t }
|
||||
forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for $t, $t }
|
||||
)+)
|
||||
}
|
||||
|
||||
@ -915,7 +896,6 @@ bitxor_assign_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
|
||||
message = "no implementation for `{Self} <<= {Rhs}`",
|
||||
label = "no implementation for `{Self} <<= {Rhs}`"
|
||||
)]
|
||||
#[const_trait]
|
||||
pub trait ShlAssign<Rhs = Self> {
|
||||
/// Performs the `<<=` operation.
|
||||
///
|
||||
@ -937,8 +917,7 @@ pub trait ShlAssign<Rhs = Self> {
|
||||
macro_rules! shl_assign_impl {
|
||||
($t:ty, $f:ty) => {
|
||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const ShlAssign<$f> for $t {
|
||||
impl ShlAssign<$f> for $t {
|
||||
#[inline]
|
||||
#[rustc_inherit_overflow_checks]
|
||||
fn shl_assign(&mut self, other: $f) {
|
||||
@ -946,7 +925,7 @@ macro_rules! shl_assign_impl {
|
||||
}
|
||||
}
|
||||
|
||||
forward_ref_op_assign! { impl const ShlAssign, shl_assign for $t, $f }
|
||||
forward_ref_op_assign! { impl ShlAssign, shl_assign for $t, $f }
|
||||
};
|
||||
}
|
||||
|
||||
@ -999,7 +978,6 @@ shl_assign_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize }
|
||||
message = "no implementation for `{Self} >>= {Rhs}`",
|
||||
label = "no implementation for `{Self} >>= {Rhs}`"
|
||||
)]
|
||||
#[const_trait]
|
||||
pub trait ShrAssign<Rhs = Self> {
|
||||
/// Performs the `>>=` operation.
|
||||
///
|
||||
@ -1021,8 +999,7 @@ pub trait ShrAssign<Rhs = Self> {
|
||||
macro_rules! shr_assign_impl {
|
||||
($t:ty, $f:ty) => {
|
||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
|
||||
impl const ShrAssign<$f> for $t {
|
||||
impl ShrAssign<$f> for $t {
|
||||
#[inline]
|
||||
#[rustc_inherit_overflow_checks]
|
||||
fn shr_assign(&mut self, other: $f) {
|
||||
@ -1030,7 +1007,7 @@ macro_rules! shr_assign_impl {
|
||||
}
|
||||
}
|
||||
|
||||
forward_ref_op_assign! { impl const ShrAssign, shr_assign for $t, $f }
|
||||
forward_ref_op_assign! { impl ShrAssign, shr_assign for $t, $f }
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -97,8 +97,7 @@ pub enum ControlFlow<B, C = ()> {
|
||||
}
|
||||
|
||||
#[unstable(feature = "try_trait_v2", issue = "84277")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl<B, C> const ops::Try for ControlFlow<B, C> {
|
||||
impl<B, C> ops::Try for ControlFlow<B, C> {
|
||||
type Output = C;
|
||||
type Residual = ControlFlow<B, convert::Infallible>;
|
||||
|
||||
@ -117,8 +116,7 @@ impl<B, C> const ops::Try for ControlFlow<B, C> {
|
||||
}
|
||||
|
||||
#[unstable(feature = "try_trait_v2", issue = "84277")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl<B, C> const ops::FromResidual for ControlFlow<B, C> {
|
||||
impl<B, C> ops::FromResidual for ControlFlow<B, C> {
|
||||
#[inline]
|
||||
fn from_residual(residual: ControlFlow<B, convert::Infallible>) -> Self {
|
||||
match residual {
|
||||
@ -128,8 +126,7 @@ impl<B, C> const ops::FromResidual for ControlFlow<B, C> {
|
||||
}
|
||||
|
||||
#[unstable(feature = "try_trait_v2_residual", issue = "91285")]
|
||||
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
|
||||
impl<B, C> const ops::Residual<C> for ControlFlow<B, convert::Infallible> {
|
||||
impl<B, C> ops::Residual<C> for ControlFlow<B, convert::Infallible> {
|
||||
type TryType = ControlFlow<B, C>;
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,6 @@
|
||||
#[doc(alias = "&*")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_diagnostic_item = "Deref"]
|
||||
#[const_trait]
|
||||
pub trait Deref {
|
||||
/// The resulting type after dereferencing.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -77,8 +76,7 @@ pub trait Deref {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_deref", issue = "88955")]
|
||||
impl<T: ?Sized> const Deref for &T {
|
||||
impl<T: ?Sized> Deref for &T {
|
||||
type Target = T;
|
||||
|
||||
#[rustc_diagnostic_item = "noop_method_deref"]
|
||||
@ -91,8 +89,7 @@ impl<T: ?Sized> const Deref for &T {
|
||||
impl<T: ?Sized> !DerefMut for &T {}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_deref", issue = "88955")]
|
||||
impl<T: ?Sized> const Deref for &mut T {
|
||||
impl<T: ?Sized> Deref for &mut T {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &T {
|
||||
@ -170,7 +167,6 @@ impl<T: ?Sized> const Deref for &mut T {
|
||||
#[lang = "deref_mut"]
|
||||
#[doc(alias = "*")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[const_trait]
|
||||
pub trait DerefMut: Deref {
|
||||
/// Mutably dereferences the value.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
|
@ -254,10 +254,9 @@ mod impls {
|
||||
use crate::marker::Tuple;
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
|
||||
impl<A: Tuple, F: ?Sized> const Fn<A> for &F
|
||||
impl<A: Tuple, F: ?Sized> Fn<A> for &F
|
||||
where
|
||||
F: ~const Fn<A>,
|
||||
F: Fn<A>,
|
||||
{
|
||||
extern "rust-call" fn call(&self, args: A) -> F::Output {
|
||||
(**self).call(args)
|
||||
@ -265,10 +264,9 @@ mod impls {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
|
||||
impl<A: Tuple, F: ?Sized> const FnMut<A> for &F
|
||||
impl<A: Tuple, F: ?Sized> FnMut<A> for &F
|
||||
where
|
||||
F: ~const Fn<A>,
|
||||
F: Fn<A>,
|
||||
{
|
||||
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
|
||||
(**self).call(args)
|
||||
@ -276,10 +274,9 @@ mod impls {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
|
||||
impl<A: Tuple, F: ?Sized> const FnOnce<A> for &F
|
||||
impl<A: Tuple, F: ?Sized> FnOnce<A> for &F
|
||||
where
|
||||
F: ~const Fn<A>,
|
||||
F: Fn<A>,
|
||||
{
|
||||
type Output = F::Output;
|
||||
|
||||
@ -289,10 +286,9 @@ mod impls {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
|
||||
impl<A: Tuple, F: ?Sized> const FnMut<A> for &mut F
|
||||
impl<A: Tuple, F: ?Sized> FnMut<A> for &mut F
|
||||
where
|
||||
F: ~const FnMut<A>,
|
||||
F: FnMut<A>,
|
||||
{
|
||||
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
|
||||
(*self).call_mut(args)
|
||||
@ -300,10 +296,9 @@ mod impls {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
|
||||
impl<A: Tuple, F: ?Sized> const FnOnce<A> for &mut F
|
||||
impl<A: Tuple, F: ?Sized> FnOnce<A> for &mut F
|
||||
where
|
||||
F: ~const FnMut<A>,
|
||||
F: FnMut<A>,
|
||||
{
|
||||
type Output = F::Output;
|
||||
extern "rust-call" fn call_once(self, args: A) -> F::Output {
|
||||
|
@ -55,7 +55,6 @@
|
||||
#[doc(alias = "]")]
|
||||
#[doc(alias = "[")]
|
||||
#[doc(alias = "[]")]
|
||||
#[const_trait]
|
||||
pub trait Index<Idx: ?Sized> {
|
||||
/// The returned type after indexing.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -165,8 +164,7 @@ see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#ind
|
||||
#[doc(alias = "[")]
|
||||
#[doc(alias = "]")]
|
||||
#[doc(alias = "[]")]
|
||||
#[const_trait]
|
||||
pub trait IndexMut<Idx: ?Sized>: ~const Index<Idx> {
|
||||
pub trait IndexMut<Idx: ?Sized>: Index<Idx> {
|
||||
/// Performs the mutable indexing (`container[index]`) operation.
|
||||
///
|
||||
/// # Panics
|
||||
|
@ -96,7 +96,7 @@ impl<Idx: fmt::Debug> fmt::Debug for Range<Idx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<Idx: ~const PartialOrd<Idx>> Range<Idx> {
|
||||
impl<Idx: PartialOrd<Idx>> Range<Idx> {
|
||||
/// Returns `true` if `item` is contained in the range.
|
||||
///
|
||||
/// # Examples
|
||||
@ -116,11 +116,10 @@ impl<Idx: ~const PartialOrd<Idx>> Range<Idx> {
|
||||
/// assert!(!(f32::NAN..1.0).contains(&0.5));
|
||||
/// ```
|
||||
#[stable(feature = "range_contains", since = "1.35.0")]
|
||||
#[rustc_const_unstable(feature = "const_range_bounds", issue = "108082")]
|
||||
pub const fn contains<U>(&self, item: &U) -> bool
|
||||
pub fn contains<U>(&self, item: &U) -> bool
|
||||
where
|
||||
Idx: ~const PartialOrd<U>,
|
||||
U: ?Sized + ~const PartialOrd<Idx>,
|
||||
Idx: PartialOrd<U>,
|
||||
U: ?Sized + PartialOrd<Idx>,
|
||||
{
|
||||
<Self as RangeBounds<Idx>>::contains(self, item)
|
||||
}
|
||||
@ -143,8 +142,7 @@ impl<Idx: ~const PartialOrd<Idx>> Range<Idx> {
|
||||
/// assert!( (f32::NAN..5.0).is_empty());
|
||||
/// ```
|
||||
#[stable(feature = "range_is_empty", since = "1.47.0")]
|
||||
#[rustc_const_unstable(feature = "const_range_bounds", issue = "108082")]
|
||||
pub const fn is_empty(&self) -> bool {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
!(self.start < self.end)
|
||||
}
|
||||
}
|
||||
@ -201,7 +199,7 @@ impl<Idx: fmt::Debug> fmt::Debug for RangeFrom<Idx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<Idx: ~const PartialOrd<Idx>> RangeFrom<Idx> {
|
||||
impl<Idx: PartialOrd<Idx>> RangeFrom<Idx> {
|
||||
/// Returns `true` if `item` is contained in the range.
|
||||
///
|
||||
/// # Examples
|
||||
@ -216,11 +214,10 @@ impl<Idx: ~const PartialOrd<Idx>> RangeFrom<Idx> {
|
||||
/// assert!(!(f32::NAN..).contains(&0.5));
|
||||
/// ```
|
||||
#[stable(feature = "range_contains", since = "1.35.0")]
|
||||
#[rustc_const_unstable(feature = "const_range_bounds", issue = "108082")]
|
||||
pub const fn contains<U>(&self, item: &U) -> bool
|
||||
pub fn contains<U>(&self, item: &U) -> bool
|
||||
where
|
||||
Idx: ~const PartialOrd<U>,
|
||||
U: ?Sized + ~const PartialOrd<Idx>,
|
||||
Idx: PartialOrd<U>,
|
||||
U: ?Sized + PartialOrd<Idx>,
|
||||
{
|
||||
<Self as RangeBounds<Idx>>::contains(self, item)
|
||||
}
|
||||
@ -283,7 +280,7 @@ impl<Idx: fmt::Debug> fmt::Debug for RangeTo<Idx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<Idx: ~const PartialOrd<Idx>> RangeTo<Idx> {
|
||||
impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
|
||||
/// Returns `true` if `item` is contained in the range.
|
||||
///
|
||||
/// # Examples
|
||||
@ -298,11 +295,10 @@ impl<Idx: ~const PartialOrd<Idx>> RangeTo<Idx> {
|
||||
/// assert!(!(..f32::NAN).contains(&0.5));
|
||||
/// ```
|
||||
#[stable(feature = "range_contains", since = "1.35.0")]
|
||||
#[rustc_const_unstable(feature = "const_range_bounds", issue = "108082")]
|
||||
pub const fn contains<U>(&self, item: &U) -> bool
|
||||
pub fn contains<U>(&self, item: &U) -> bool
|
||||
where
|
||||
Idx: ~const PartialOrd<U>,
|
||||
U: ?Sized + ~const PartialOrd<Idx>,
|
||||
Idx: PartialOrd<U>,
|
||||
U: ?Sized + PartialOrd<Idx>,
|
||||
{
|
||||
<Self as RangeBounds<Idx>>::contains(self, item)
|
||||
}
|
||||
@ -474,7 +470,7 @@ impl<Idx: fmt::Debug> fmt::Debug for RangeInclusive<Idx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<Idx: ~const PartialOrd<Idx>> RangeInclusive<Idx> {
|
||||
impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
|
||||
/// Returns `true` if `item` is contained in the range.
|
||||
///
|
||||
/// # Examples
|
||||
@ -505,11 +501,10 @@ impl<Idx: ~const PartialOrd<Idx>> RangeInclusive<Idx> {
|
||||
/// assert!(!r.contains(&3) && !r.contains(&5));
|
||||
/// ```
|
||||
#[stable(feature = "range_contains", since = "1.35.0")]
|
||||
#[rustc_const_unstable(feature = "const_range_bounds", issue = "108082")]
|
||||
pub const fn contains<U>(&self, item: &U) -> bool
|
||||
pub fn contains<U>(&self, item: &U) -> bool
|
||||
where
|
||||
Idx: ~const PartialOrd<U>,
|
||||
U: ?Sized + ~const PartialOrd<Idx>,
|
||||
Idx: PartialOrd<U>,
|
||||
U: ?Sized + PartialOrd<Idx>,
|
||||
{
|
||||
<Self as RangeBounds<Idx>>::contains(self, item)
|
||||
}
|
||||
@ -541,9 +536,8 @@ impl<Idx: ~const PartialOrd<Idx>> RangeInclusive<Idx> {
|
||||
/// assert!(r.is_empty());
|
||||
/// ```
|
||||
#[stable(feature = "range_is_empty", since = "1.47.0")]
|
||||
#[rustc_const_unstable(feature = "const_range_bounds", issue = "108082")]
|
||||
#[inline]
|
||||
pub const fn is_empty(&self) -> bool {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.exhausted || !(self.start <= self.end)
|
||||
}
|
||||
}
|
||||
@ -605,7 +599,7 @@ impl<Idx: fmt::Debug> fmt::Debug for RangeToInclusive<Idx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<Idx: ~const PartialOrd<Idx>> RangeToInclusive<Idx> {
|
||||
impl<Idx: PartialOrd<Idx>> RangeToInclusive<Idx> {
|
||||
/// Returns `true` if `item` is contained in the range.
|
||||
///
|
||||
/// # Examples
|
||||
@ -620,11 +614,10 @@ impl<Idx: ~const PartialOrd<Idx>> RangeToInclusive<Idx> {
|
||||
/// assert!(!(..=f32::NAN).contains(&0.5));
|
||||
/// ```
|
||||
#[stable(feature = "range_contains", since = "1.35.0")]
|
||||
#[rustc_const_unstable(feature = "const_range_bounds", issue = "108082")]
|
||||
pub const fn contains<U>(&self, item: &U) -> bool
|
||||
pub fn contains<U>(&self, item: &U) -> bool
|
||||
where
|
||||
Idx: ~const PartialOrd<U>,
|
||||
U: ?Sized + ~const PartialOrd<Idx>,
|
||||
Idx: PartialOrd<U>,
|
||||
U: ?Sized + PartialOrd<Idx>,
|
||||
{
|
||||
<Self as RangeBounds<Idx>>::contains(self, item)
|
||||
}
|
||||
@ -765,7 +758,6 @@ impl<T: Clone> Bound<&T> {
|
||||
/// `RangeBounds` is implemented by Rust's built-in range types, produced
|
||||
/// by range syntax like `..`, `a..`, `..b`, `..=c`, `d..e`, or `f..=g`.
|
||||
#[stable(feature = "collections_range", since = "1.28.0")]
|
||||
#[const_trait]
|
||||
pub trait RangeBounds<T: ?Sized> {
|
||||
/// Start index bound.
|
||||
///
|
||||
@ -818,8 +810,8 @@ pub trait RangeBounds<T: ?Sized> {
|
||||
#[stable(feature = "range_contains", since = "1.35.0")]
|
||||
fn contains<U>(&self, item: &U) -> bool
|
||||
where
|
||||
T: ~const PartialOrd<U>,
|
||||
U: ?Sized + ~const PartialOrd<T>,
|
||||
T: PartialOrd<U>,
|
||||
U: ?Sized + PartialOrd<T>,
|
||||
{
|
||||
(match self.start_bound() {
|
||||
Included(start) => start <= item,
|
||||
@ -836,8 +828,7 @@ pub trait RangeBounds<T: ?Sized> {
|
||||
use self::Bound::{Excluded, Included, Unbounded};
|
||||
|
||||
#[stable(feature = "collections_range", since = "1.28.0")]
|
||||
#[rustc_const_unstable(feature = "const_range_bounds", issue = "108082")]
|
||||
impl<T: ?Sized> const RangeBounds<T> for RangeFull {
|
||||
impl<T: ?Sized> RangeBounds<T> for RangeFull {
|
||||
fn start_bound(&self) -> Bound<&T> {
|
||||
Unbounded
|
||||
}
|
||||
@ -847,8 +838,7 @@ impl<T: ?Sized> const RangeBounds<T> for RangeFull {
|
||||
}
|
||||
|
||||
#[stable(feature = "collections_range", since = "1.28.0")]
|
||||
#[rustc_const_unstable(feature = "const_range_bounds", issue = "108082")]
|
||||
impl<T> const RangeBounds<T> for RangeFrom<T> {
|
||||
impl<T> RangeBounds<T> for RangeFrom<T> {
|
||||
fn start_bound(&self) -> Bound<&T> {
|
||||
Included(&self.start)
|
||||
}
|
||||
@ -858,8 +848,7 @@ impl<T> const RangeBounds<T> for RangeFrom<T> {
|
||||
}
|
||||
|
||||
#[stable(feature = "collections_range", since = "1.28.0")]
|
||||
#[rustc_const_unstable(feature = "const_range_bounds", issue = "108082")]
|
||||
impl<T> const RangeBounds<T> for RangeTo<T> {
|
||||
impl<T> RangeBounds<T> for RangeTo<T> {
|
||||
fn start_bound(&self) -> Bound<&T> {
|
||||
Unbounded
|
||||
}
|
||||
@ -869,8 +858,7 @@ impl<T> const RangeBounds<T> for RangeTo<T> {
|
||||
}
|
||||
|
||||
#[stable(feature = "collections_range", since = "1.28.0")]
|
||||
#[rustc_const_unstable(feature = "const_range_bounds", issue = "108082")]
|
||||
impl<T> const RangeBounds<T> for Range<T> {
|
||||
impl<T> RangeBounds<T> for Range<T> {
|
||||
fn start_bound(&self) -> Bound<&T> {
|
||||
Included(&self.start)
|
||||
}
|
||||
@ -880,8 +868,7 @@ impl<T> const RangeBounds<T> for Range<T> {
|
||||
}
|
||||
|
||||
#[stable(feature = "collections_range", since = "1.28.0")]
|
||||
#[rustc_const_unstable(feature = "const_range_bounds", issue = "108082")]
|
||||
impl<T> const RangeBounds<T> for RangeInclusive<T> {
|
||||
impl<T> RangeBounds<T> for RangeInclusive<T> {
|
||||
fn start_bound(&self) -> Bound<&T> {
|
||||
Included(&self.start)
|
||||
}
|
||||
@ -897,8 +884,7 @@ impl<T> const RangeBounds<T> for RangeInclusive<T> {
|
||||
}
|
||||
|
||||
#[stable(feature = "collections_range", since = "1.28.0")]
|
||||
#[rustc_const_unstable(feature = "const_range_bounds", issue = "108082")]
|
||||
impl<T> const RangeBounds<T> for RangeToInclusive<T> {
|
||||
impl<T> RangeBounds<T> for RangeToInclusive<T> {
|
||||
fn start_bound(&self) -> Bound<&T> {
|
||||
Unbounded
|
||||
}
|
||||
@ -908,8 +894,7 @@ impl<T> const RangeBounds<T> for RangeToInclusive<T> {
|
||||
}
|
||||
|
||||
#[stable(feature = "collections_range", since = "1.28.0")]
|
||||
#[rustc_const_unstable(feature = "const_range_bounds", issue = "108082")]
|
||||
impl<T> const RangeBounds<T> for (Bound<T>, Bound<T>) {
|
||||
impl<T> RangeBounds<T> for (Bound<T>, Bound<T>) {
|
||||
fn start_bound(&self) -> Bound<&T> {
|
||||
match *self {
|
||||
(Included(ref start), _) => Included(start),
|
||||
@ -928,8 +913,7 @@ impl<T> const RangeBounds<T> for (Bound<T>, Bound<T>) {
|
||||
}
|
||||
|
||||
#[stable(feature = "collections_range", since = "1.28.0")]
|
||||
#[rustc_const_unstable(feature = "const_range_bounds", issue = "108082")]
|
||||
impl<'a, T: ?Sized + 'a> const RangeBounds<T> for (Bound<&'a T>, Bound<&'a T>) {
|
||||
impl<'a, T: ?Sized + 'a> RangeBounds<T> for (Bound<&'a T>, Bound<&'a T>) {
|
||||
fn start_bound(&self) -> Bound<&T> {
|
||||
self.0
|
||||
}
|
||||
@ -940,8 +924,7 @@ impl<'a, T: ?Sized + 'a> const RangeBounds<T> for (Bound<&'a T>, Bound<&'a T>) {
|
||||
}
|
||||
|
||||
#[stable(feature = "collections_range", since = "1.28.0")]
|
||||
#[rustc_const_unstable(feature = "const_range_bounds", issue = "108082")]
|
||||
impl<T> const RangeBounds<T> for RangeFrom<&T> {
|
||||
impl<T> RangeBounds<T> for RangeFrom<&T> {
|
||||
fn start_bound(&self) -> Bound<&T> {
|
||||
Included(self.start)
|
||||
}
|
||||
@ -951,8 +934,7 @@ impl<T> const RangeBounds<T> for RangeFrom<&T> {
|
||||
}
|
||||
|
||||
#[stable(feature = "collections_range", since = "1.28.0")]
|
||||
#[rustc_const_unstable(feature = "const_range_bounds", issue = "108082")]
|
||||
impl<T> const RangeBounds<T> for RangeTo<&T> {
|
||||
impl<T> RangeBounds<T> for RangeTo<&T> {
|
||||
fn start_bound(&self) -> Bound<&T> {
|
||||
Unbounded
|
||||
}
|
||||
@ -962,8 +944,7 @@ impl<T> const RangeBounds<T> for RangeTo<&T> {
|
||||
}
|
||||
|
||||
#[stable(feature = "collections_range", since = "1.28.0")]
|
||||
#[rustc_const_unstable(feature = "const_range_bounds", issue = "108082")]
|
||||
impl<T> const RangeBounds<T> for Range<&T> {
|
||||
impl<T> RangeBounds<T> for Range<&T> {
|
||||
fn start_bound(&self) -> Bound<&T> {
|
||||
Included(self.start)
|
||||
}
|
||||
@ -973,8 +954,7 @@ impl<T> const RangeBounds<T> for Range<&T> {
|
||||
}
|
||||
|
||||
#[stable(feature = "collections_range", since = "1.28.0")]
|
||||
#[rustc_const_unstable(feature = "const_range_bounds", issue = "108082")]
|
||||
impl<T> const RangeBounds<T> for RangeInclusive<&T> {
|
||||
impl<T> RangeBounds<T> for RangeInclusive<&T> {
|
||||
fn start_bound(&self) -> Bound<&T> {
|
||||
Included(self.start)
|
||||
}
|
||||
@ -984,8 +964,7 @@ impl<T> const RangeBounds<T> for RangeInclusive<&T> {
|
||||
}
|
||||
|
||||
#[stable(feature = "collections_range", since = "1.28.0")]
|
||||
#[rustc_const_unstable(feature = "const_range_bounds", issue = "108082")]
|
||||
impl<T> const RangeBounds<T> for RangeToInclusive<&T> {
|
||||
impl<T> RangeBounds<T> for RangeToInclusive<&T> {
|
||||
fn start_bound(&self) -> Bound<&T> {
|
||||
Unbounded
|
||||
}
|
||||
|
@ -128,8 +128,7 @@ use crate::ops::ControlFlow;
|
||||
)]
|
||||
#[doc(alias = "?")]
|
||||
#[lang = "Try"]
|
||||
#[const_trait]
|
||||
pub trait Try: ~const FromResidual {
|
||||
pub trait Try: FromResidual {
|
||||
/// The type of the value produced by `?` when *not* short-circuiting.
|
||||
#[unstable(feature = "try_trait_v2", issue = "84277")]
|
||||
type Output;
|
||||
@ -305,7 +304,6 @@ pub trait Try: ~const FromResidual {
|
||||
)]
|
||||
#[rustc_diagnostic_item = "FromResidual"]
|
||||
#[unstable(feature = "try_trait_v2", issue = "84277")]
|
||||
#[const_trait]
|
||||
pub trait FromResidual<R = <Self as Try>::Residual> {
|
||||
/// Constructs the type from a compatible `Residual` type.
|
||||
///
|
||||
@ -358,11 +356,10 @@ where
|
||||
/// and in the other direction,
|
||||
/// `<Result<Infallible, E> as Residual<T>>::TryType = Result<T, E>`.
|
||||
#[unstable(feature = "try_trait_v2_residual", issue = "91285")]
|
||||
#[const_trait]
|
||||
pub trait Residual<O> {
|
||||
/// The "return" type of this meta-function.
|
||||
#[unstable(feature = "try_trait_v2_residual", issue = "91285")]
|
||||
type TryType: ~const Try<Output = O, Residual = Self>;
|
||||
type TryType: Try<Output = O, Residual = Self>;
|
||||
}
|
||||
|
||||
#[unstable(feature = "pub_crate_should_not_need_unstable_attr", issue = "none")]
|
||||
@ -389,16 +386,14 @@ impl<T> NeverShortCircuit<T> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn wrap_mut_2<A, B>(
|
||||
mut f: impl ~const FnMut(A, B) -> T,
|
||||
) -> impl ~const FnMut(A, B) -> Self {
|
||||
const move |a, b| NeverShortCircuit(f(a, b))
|
||||
pub fn wrap_mut_2<A, B>(mut f: impl FnMut(A, B) -> T) -> impl FnMut(A, B) -> Self {
|
||||
move |a, b| NeverShortCircuit(f(a, b))
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) enum NeverShortCircuitResidual {}
|
||||
|
||||
impl<T> const Try for NeverShortCircuit<T> {
|
||||
impl<T> Try for NeverShortCircuit<T> {
|
||||
type Output = T;
|
||||
type Residual = NeverShortCircuitResidual;
|
||||
|
||||
@ -413,14 +408,14 @@ impl<T> const Try for NeverShortCircuit<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> const FromResidual for NeverShortCircuit<T> {
|
||||
impl<T> FromResidual for NeverShortCircuit<T> {
|
||||
#[inline]
|
||||
fn from_residual(never: NeverShortCircuitResidual) -> Self {
|
||||
match never {}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> const Residual<T> for NeverShortCircuitResidual {
|
||||
impl<T> Residual<T> for NeverShortCircuitResidual {
|
||||
type TryType = NeverShortCircuit<T>;
|
||||
}
|
||||
|
||||
|
@ -547,7 +547,6 @@
|
||||
#![stable(feature = "rust1", since = "1.0.0")]
|
||||
|
||||
use crate::iter::{self, FromIterator, FusedIterator, TrustedLen};
|
||||
use crate::marker::Destruct;
|
||||
use crate::panicking::{panic, panic_str};
|
||||
use crate::pin::Pin;
|
||||
use crate::{
|
||||
@ -967,11 +966,7 @@ impl<T> Option<T> {
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
|
||||
pub const fn unwrap_or(self, default: T) -> T
|
||||
where
|
||||
T: ~const Destruct,
|
||||
{
|
||||
pub fn unwrap_or(self, default: T) -> T {
|
||||
match self {
|
||||
Some(x) => x,
|
||||
None => default,
|
||||
@ -989,11 +984,9 @@ impl<T> Option<T> {
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
|
||||
pub const fn unwrap_or_else<F>(self, f: F) -> T
|
||||
pub fn unwrap_or_else<F>(self, f: F) -> T
|
||||
where
|
||||
F: ~const FnOnce() -> T,
|
||||
F: ~const Destruct,
|
||||
F: FnOnce() -> T,
|
||||
{
|
||||
match self {
|
||||
Some(x) => x,
|
||||
@ -1022,10 +1015,9 @@ impl<T> Option<T> {
|
||||
/// [`FromStr`]: crate::str::FromStr
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
|
||||
pub const fn unwrap_or_default(self) -> T
|
||||
pub fn unwrap_or_default(self) -> T
|
||||
where
|
||||
T: ~const Default,
|
||||
T: Default,
|
||||
{
|
||||
match self {
|
||||
Some(x) => x,
|
||||
@ -1089,11 +1081,9 @@ impl<T> Option<T> {
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
|
||||
pub const fn map<U, F>(self, f: F) -> Option<U>
|
||||
pub fn map<U, F>(self, f: F) -> Option<U>
|
||||
where
|
||||
F: ~const FnOnce(T) -> U,
|
||||
F: ~const Destruct,
|
||||
F: FnOnce(T) -> U,
|
||||
{
|
||||
match self {
|
||||
Some(x) => Some(f(x)),
|
||||
@ -1118,11 +1108,9 @@ impl<T> Option<T> {
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "result_option_inspect", issue = "91345")]
|
||||
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
|
||||
pub const fn inspect<F>(self, f: F) -> Self
|
||||
pub fn inspect<F>(self, f: F) -> Self
|
||||
where
|
||||
F: ~const FnOnce(&T),
|
||||
F: ~const Destruct,
|
||||
F: FnOnce(&T),
|
||||
{
|
||||
if let Some(ref x) = self {
|
||||
f(x);
|
||||
@ -1151,12 +1139,9 @@ impl<T> Option<T> {
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
|
||||
pub const fn map_or<U, F>(self, default: U, f: F) -> U
|
||||
pub fn map_or<U, F>(self, default: U, f: F) -> U
|
||||
where
|
||||
F: ~const FnOnce(T) -> U,
|
||||
F: ~const Destruct,
|
||||
U: ~const Destruct,
|
||||
F: FnOnce(T) -> U,
|
||||
{
|
||||
match self {
|
||||
Some(t) => f(t),
|
||||
@ -1180,13 +1165,10 @@ impl<T> Option<T> {
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
|
||||
pub const fn map_or_else<U, D, F>(self, default: D, f: F) -> U
|
||||
pub fn map_or_else<U, D, F>(self, default: D, f: F) -> U
|
||||
where
|
||||
D: ~const FnOnce() -> U,
|
||||
D: ~const Destruct,
|
||||
F: ~const FnOnce(T) -> U,
|
||||
F: ~const Destruct,
|
||||
D: FnOnce() -> U,
|
||||
F: FnOnce(T) -> U,
|
||||
{
|
||||
match self {
|
||||
Some(t) => f(t),
|
||||
@ -1217,11 +1199,7 @@ impl<T> Option<T> {
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
|
||||
pub const fn ok_or<E>(self, err: E) -> Result<T, E>
|
||||
where
|
||||
E: ~const Destruct,
|
||||
{
|
||||
pub fn ok_or<E>(self, err: E) -> Result<T, E> {
|
||||
match self {
|
||||
Some(v) => Ok(v),
|
||||
None => Err(err),
|
||||
@ -1246,11 +1224,9 @@ impl<T> Option<T> {
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
|
||||
pub const fn ok_or_else<E, F>(self, err: F) -> Result<T, E>
|
||||
pub fn ok_or_else<E, F>(self, err: F) -> Result<T, E>
|
||||
where
|
||||
F: ~const FnOnce() -> E,
|
||||
F: ~const Destruct,
|
||||
F: FnOnce() -> E,
|
||||
{
|
||||
match self {
|
||||
Some(v) => Ok(v),
|
||||
@ -1274,10 +1250,9 @@ impl<T> Option<T> {
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "option_deref", since = "1.40.0")]
|
||||
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
|
||||
pub const fn as_deref(&self) -> Option<&T::Target>
|
||||
pub fn as_deref(&self) -> Option<&T::Target>
|
||||
where
|
||||
T: ~const Deref,
|
||||
T: Deref,
|
||||
{
|
||||
match self.as_ref() {
|
||||
Some(t) => Some(t.deref()),
|
||||
@ -1301,10 +1276,9 @@ impl<T> Option<T> {
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "option_deref", since = "1.40.0")]
|
||||
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
|
||||
pub const fn as_deref_mut(&mut self) -> Option<&mut T::Target>
|
||||
pub fn as_deref_mut(&mut self) -> Option<&mut T::Target>
|
||||
where
|
||||
T: ~const DerefMut,
|
||||
T: DerefMut,
|
||||
{
|
||||
match self.as_mut() {
|
||||
Some(t) => Some(t.deref_mut()),
|
||||
@ -1388,12 +1362,7 @@ impl<T> Option<T> {
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
|
||||
pub const fn and<U>(self, optb: Option<U>) -> Option<U>
|
||||
where
|
||||
T: ~const Destruct,
|
||||
U: ~const Destruct,
|
||||
{
|
||||
pub fn and<U>(self, optb: Option<U>) -> Option<U> {
|
||||
match self {
|
||||
Some(_) => optb,
|
||||
None => None,
|
||||
@ -1430,11 +1399,9 @@ impl<T> Option<T> {
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
|
||||
pub const fn and_then<U, F>(self, f: F) -> Option<U>
|
||||
pub fn and_then<U, F>(self, f: F) -> Option<U>
|
||||
where
|
||||
F: ~const FnOnce(T) -> Option<U>,
|
||||
F: ~const Destruct,
|
||||
F: FnOnce(T) -> Option<U>,
|
||||
{
|
||||
match self {
|
||||
Some(x) => f(x),
|
||||
@ -1468,12 +1435,9 @@ impl<T> Option<T> {
|
||||
/// [`Some(t)`]: Some
|
||||
#[inline]
|
||||
#[stable(feature = "option_filter", since = "1.27.0")]
|
||||
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
|
||||
pub const fn filter<P>(self, predicate: P) -> Self
|
||||
pub fn filter<P>(self, predicate: P) -> Self
|
||||
where
|
||||
T: ~const Destruct,
|
||||
P: ~const FnOnce(&T) -> bool,
|
||||
P: ~const Destruct,
|
||||
P: FnOnce(&T) -> bool,
|
||||
{
|
||||
if let Some(x) = self {
|
||||
if predicate(&x) {
|
||||
@ -1512,11 +1476,7 @@ impl<T> Option<T> {
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
|
||||
pub const fn or(self, optb: Option<T>) -> Option<T>
|
||||
where
|
||||
T: ~const Destruct,
|
||||
{
|
||||
pub fn or(self, optb: Option<T>) -> Option<T> {
|
||||
match self {
|
||||
Some(x) => Some(x),
|
||||
None => optb,
|
||||
@ -1538,11 +1498,9 @@ impl<T> Option<T> {
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
|
||||
pub const fn or_else<F>(self, f: F) -> Option<T>
|
||||
pub fn or_else<F>(self, f: F) -> Option<T>
|
||||
where
|
||||
F: ~const FnOnce() -> Option<T>,
|
||||
F: ~const Destruct,
|
||||
F: FnOnce() -> Option<T>,
|
||||
{
|
||||
match self {
|
||||
Some(x) => Some(x),
|
||||
@ -1573,11 +1531,7 @@ impl<T> Option<T> {
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "option_xor", since = "1.37.0")]
|
||||
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
|
||||
pub const fn xor(self, optb: Option<T>) -> Option<T>
|
||||
where
|
||||
T: ~const Destruct,
|
||||
{
|
||||
pub fn xor(self, optb: Option<T>) -> Option<T> {
|
||||
match (self, optb) {
|
||||
(Some(a), None) => Some(a),
|
||||
(None, Some(b)) => Some(b),
|
||||
@ -1611,11 +1565,7 @@ impl<T> Option<T> {
|
||||
#[must_use = "if you intended to set a value, consider assignment instead"]
|
||||
#[inline]
|
||||
#[stable(feature = "option_insert", since = "1.53.0")]
|
||||
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
|
||||
pub const fn insert(&mut self, value: T) -> &mut T
|
||||
where
|
||||
T: ~const Destruct,
|
||||
{
|
||||
pub fn insert(&mut self, value: T) -> &mut T {
|
||||
*self = Some(value);
|
||||
|
||||
// SAFETY: the code above just filled the option
|
||||
@ -1644,11 +1594,7 @@ impl<T> Option<T> {
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "option_entry", since = "1.20.0")]
|
||||
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
|
||||
pub const fn get_or_insert(&mut self, value: T) -> &mut T
|
||||
where
|
||||
T: ~const Destruct,
|
||||
{
|
||||
pub fn get_or_insert(&mut self, value: T) -> &mut T {
|
||||
if let None = *self {
|
||||
*self = Some(value);
|
||||
}
|
||||
@ -1679,12 +1625,11 @@ impl<T> Option<T> {
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "option_get_or_insert_default", issue = "82901")]
|
||||
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
|
||||
pub const fn get_or_insert_default(&mut self) -> &mut T
|
||||
pub fn get_or_insert_default(&mut self) -> &mut T
|
||||
where
|
||||
T: ~const Default,
|
||||
T: Default,
|
||||
{
|
||||
const fn default<T: ~const Default>() -> T {
|
||||
fn default<T: Default>() -> T {
|
||||
T::default()
|
||||
}
|
||||
|
||||
@ -1710,11 +1655,9 @@ impl<T> Option<T> {
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "option_entry", since = "1.20.0")]
|
||||
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
|
||||
pub const fn get_or_insert_with<F>(&mut self, f: F) -> &mut T
|
||||
pub fn get_or_insert_with<F>(&mut self, f: F) -> &mut T
|
||||
where
|
||||
F: ~const FnOnce() -> T,
|
||||
F: ~const Destruct,
|
||||
F: FnOnce() -> T,
|
||||
{
|
||||
if let None = *self {
|
||||
// the compiler isn't smart enough to know that we are not dropping a `T`
|
||||
@ -1794,12 +1737,7 @@ impl<T> Option<T> {
|
||||
/// assert_eq!(x.zip(z), None);
|
||||
/// ```
|
||||
#[stable(feature = "option_zip_option", since = "1.46.0")]
|
||||
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
|
||||
pub const fn zip<U>(self, other: Option<U>) -> Option<(T, U)>
|
||||
where
|
||||
T: ~const Destruct,
|
||||
U: ~const Destruct,
|
||||
{
|
||||
pub fn zip<U>(self, other: Option<U>) -> Option<(T, U)> {
|
||||
match (self, other) {
|
||||
(Some(a), Some(b)) => Some((a, b)),
|
||||
_ => None,
|
||||
@ -1835,13 +1773,9 @@ impl<T> Option<T> {
|
||||
/// assert_eq!(x.zip_with(None, Point::new), None);
|
||||
/// ```
|
||||
#[unstable(feature = "option_zip", issue = "70086")]
|
||||
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
|
||||
pub const fn zip_with<U, F, R>(self, other: Option<U>, f: F) -> Option<R>
|
||||
pub fn zip_with<U, F, R>(self, other: Option<U>, f: F) -> Option<R>
|
||||
where
|
||||
F: ~const FnOnce(T, U) -> R,
|
||||
F: ~const Destruct,
|
||||
T: ~const Destruct,
|
||||
U: ~const Destruct,
|
||||
F: FnOnce(T, U) -> R,
|
||||
{
|
||||
match (self, other) {
|
||||
(Some(a), Some(b)) => Some(f(a, b)),
|
||||
@ -1867,12 +1801,7 @@ impl<T, U> Option<(T, U)> {
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "unzip_option", since = "1.66.0")]
|
||||
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
|
||||
pub const fn unzip(self) -> (Option<T>, Option<U>)
|
||||
where
|
||||
T: ~const Destruct,
|
||||
U: ~const Destruct,
|
||||
{
|
||||
pub fn unzip(self) -> (Option<T>, Option<U>) {
|
||||
match self {
|
||||
Some((a, b)) => (Some(a), Some(b)),
|
||||
None => (None, None),
|
||||
@ -1922,10 +1851,9 @@ impl<T> Option<&T> {
|
||||
/// ```
|
||||
#[must_use = "`self` will be dropped if the result is not used"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_option_cloned", issue = "91582")]
|
||||
pub const fn cloned(self) -> Option<T>
|
||||
pub fn cloned(self) -> Option<T>
|
||||
where
|
||||
T: ~const Clone,
|
||||
T: Clone,
|
||||
{
|
||||
match self {
|
||||
Some(t) => Some(t.clone()),
|
||||
@ -1974,10 +1902,9 @@ impl<T> Option<&mut T> {
|
||||
/// ```
|
||||
#[must_use = "`self` will be dropped if the result is not used"]
|
||||
#[stable(since = "1.26.0", feature = "option_ref_mut_cloned")]
|
||||
#[rustc_const_unstable(feature = "const_option_cloned", issue = "91582")]
|
||||
pub const fn cloned(self) -> Option<T>
|
||||
pub fn cloned(self) -> Option<T>
|
||||
where
|
||||
T: ~const Clone,
|
||||
T: Clone,
|
||||
{
|
||||
match self {
|
||||
Some(t) => Some(t.clone()),
|
||||
@ -2030,10 +1957,9 @@ const fn expect_failed(msg: &str) -> ! {
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_clone", issue = "91805")]
|
||||
impl<T> const Clone for Option<T>
|
||||
impl<T> Clone for Option<T>
|
||||
where
|
||||
T: ~const Clone + ~const Destruct,
|
||||
T: Clone,
|
||||
{
|
||||
#[inline]
|
||||
fn clone(&self) -> Self {
|
||||
@ -2053,8 +1979,7 @@ where
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
|
||||
impl<T> const Default for Option<T> {
|
||||
impl<T> Default for Option<T> {
|
||||
/// Returns [`None`][Option::None].
|
||||
///
|
||||
/// # Examples
|
||||
@ -2114,8 +2039,7 @@ impl<'a, T> IntoIterator for &'a mut Option<T> {
|
||||
}
|
||||
|
||||
#[stable(since = "1.12.0", feature = "option_from")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl<T> const From<T> for Option<T> {
|
||||
impl<T> From<T> for Option<T> {
|
||||
/// Moves `val` into a new [`Some`].
|
||||
///
|
||||
/// # Examples
|
||||
@ -2131,8 +2055,7 @@ impl<T> const From<T> for Option<T> {
|
||||
}
|
||||
|
||||
#[stable(feature = "option_ref_from_ref_option", since = "1.30.0")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl<'a, T> const From<&'a Option<T>> for Option<&'a T> {
|
||||
impl<'a, T> From<&'a Option<T>> for Option<&'a T> {
|
||||
/// Converts from `&Option<T>` to `Option<&T>`.
|
||||
///
|
||||
/// # Examples
|
||||
@ -2159,8 +2082,7 @@ impl<'a, T> const From<&'a Option<T>> for Option<&'a T> {
|
||||
}
|
||||
|
||||
#[stable(feature = "option_ref_from_ref_option", since = "1.30.0")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl<'a, T> const From<&'a mut Option<T>> for Option<&'a mut T> {
|
||||
impl<'a, T> From<&'a mut Option<T>> for Option<&'a mut T> {
|
||||
/// Converts from `&mut Option<T>` to `Option<&mut T>`
|
||||
///
|
||||
/// # Examples
|
||||
@ -2507,8 +2429,7 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
|
||||
}
|
||||
|
||||
#[unstable(feature = "try_trait_v2", issue = "84277")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl<T> const ops::Try for Option<T> {
|
||||
impl<T> ops::Try for Option<T> {
|
||||
type Output = T;
|
||||
type Residual = Option<convert::Infallible>;
|
||||
|
||||
@ -2527,8 +2448,7 @@ impl<T> const ops::Try for Option<T> {
|
||||
}
|
||||
|
||||
#[unstable(feature = "try_trait_v2", issue = "84277")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl<T> const ops::FromResidual for Option<T> {
|
||||
impl<T> ops::FromResidual for Option<T> {
|
||||
#[inline]
|
||||
fn from_residual(residual: Option<convert::Infallible>) -> Self {
|
||||
match residual {
|
||||
@ -2546,8 +2466,7 @@ impl<T> ops::FromResidual<ops::Yeet<()>> for Option<T> {
|
||||
}
|
||||
|
||||
#[unstable(feature = "try_trait_v2_residual", issue = "91285")]
|
||||
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
|
||||
impl<T> const ops::Residual<T> for Option<convert::Infallible> {
|
||||
impl<T> ops::Residual<T> for Option<convert::Infallible> {
|
||||
type TryType = Option<T>;
|
||||
}
|
||||
|
||||
|
@ -9,8 +9,7 @@ use crate::{cmp, fmt, hash, mem, num};
|
||||
/// Note that particularly large alignments, while representable in this type,
|
||||
/// are likely not to be supported by actual allocators and linkers.
|
||||
#[unstable(feature = "ptr_alignment_type", issue = "102070")]
|
||||
#[derive(Copy, Clone, Eq)]
|
||||
#[derive_const(PartialEq)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
#[repr(transparent)]
|
||||
pub struct Alignment(AlignmentEnum);
|
||||
|
||||
@ -170,7 +169,7 @@ impl From<Alignment> for usize {
|
||||
|
||||
#[rustc_const_unstable(feature = "const_alloc_layout", issue = "67521")]
|
||||
#[unstable(feature = "ptr_alignment_type", issue = "102070")]
|
||||
impl const cmp::Ord for Alignment {
|
||||
impl cmp::Ord for Alignment {
|
||||
#[inline]
|
||||
fn cmp(&self, other: &Self) -> cmp::Ordering {
|
||||
self.as_nonzero().get().cmp(&other.as_nonzero().get())
|
||||
@ -179,7 +178,7 @@ impl const cmp::Ord for Alignment {
|
||||
|
||||
#[rustc_const_unstable(feature = "const_alloc_layout", issue = "67521")]
|
||||
#[unstable(feature = "ptr_alignment_type", issue = "102070")]
|
||||
impl const cmp::PartialOrd for Alignment {
|
||||
impl cmp::PartialOrd for Alignment {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
|
||||
Some(self.cmp(other))
|
||||
@ -201,8 +200,7 @@ type AlignmentEnum = AlignmentEnum32;
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
type AlignmentEnum = AlignmentEnum64;
|
||||
|
||||
#[derive(Copy, Clone, Eq)]
|
||||
#[derive_const(PartialEq)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
#[repr(u16)]
|
||||
enum AlignmentEnum16 {
|
||||
_Align1Shl0 = 1 << 0,
|
||||
@ -223,8 +221,7 @@ enum AlignmentEnum16 {
|
||||
_Align1Shl15 = 1 << 15,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Eq)]
|
||||
#[derive_const(PartialEq)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
enum AlignmentEnum32 {
|
||||
_Align1Shl0 = 1 << 0,
|
||||
@ -261,8 +258,7 @@ enum AlignmentEnum32 {
|
||||
_Align1Shl31 = 1 << 31,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Eq)]
|
||||
#[derive_const(PartialEq)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
#[repr(u64)]
|
||||
enum AlignmentEnum64 {
|
||||
_Align1Shl0 = 1 << 0,
|
||||
|
@ -1650,11 +1650,10 @@ impl<T> *const [T] {
|
||||
/// }
|
||||
/// ```
|
||||
#[unstable(feature = "slice_ptr_get", issue = "74265")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
#[inline]
|
||||
pub const unsafe fn get_unchecked<I>(self, index: I) -> *const I::Output
|
||||
pub unsafe fn get_unchecked<I>(self, index: I) -> *const I::Output
|
||||
where
|
||||
I: ~const SliceIndex<[T]>,
|
||||
I: SliceIndex<[T]>,
|
||||
{
|
||||
// SAFETY: the caller ensures that `self` is dereferenceable and `index` in-bounds.
|
||||
unsafe { index.get_unchecked(self) }
|
||||
|
@ -1764,7 +1764,12 @@ pub(crate) const unsafe fn align_offset<T: Sized>(p: *const T, a: usize) -> usiz
|
||||
// miracles, given the situations this case has to deal with.
|
||||
|
||||
// SAFETY: a is power-of-two hence non-zero. stride == 0 case is handled above.
|
||||
let gcdpow = unsafe { cttz_nonzero(stride).min(cttz_nonzero(a)) };
|
||||
// FIXME(const-hack) replace with min
|
||||
let gcdpow = unsafe {
|
||||
let x = cttz_nonzero(stride);
|
||||
let y = cttz_nonzero(a);
|
||||
if x < y { x } else { y }
|
||||
};
|
||||
// SAFETY: gcdpow has an upper-bound that’s at most the number of bits in a usize.
|
||||
let gcd = unsafe { unchecked_shl(1usize, gcdpow) };
|
||||
// SAFETY: gcd is always greater or equal to 1.
|
||||
|
@ -2036,11 +2036,10 @@ impl<T> *mut [T] {
|
||||
/// }
|
||||
/// ```
|
||||
#[unstable(feature = "slice_ptr_get", issue = "74265")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
#[inline(always)]
|
||||
pub const unsafe fn get_unchecked_mut<I>(self, index: I) -> *mut I::Output
|
||||
pub unsafe fn get_unchecked_mut<I>(self, index: I) -> *mut I::Output
|
||||
where
|
||||
I: ~const SliceIndex<[T]>,
|
||||
I: SliceIndex<[T]>,
|
||||
{
|
||||
// SAFETY: the caller ensures that `self` is dereferenceable and `index` in-bounds.
|
||||
unsafe { index.get_unchecked_mut(self) }
|
||||
|
@ -676,11 +676,10 @@ impl<T> NonNull<[T]> {
|
||||
/// }
|
||||
/// ```
|
||||
#[unstable(feature = "slice_ptr_get", issue = "74265")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
#[inline]
|
||||
pub const unsafe fn get_unchecked_mut<I>(self, index: I) -> NonNull<I::Output>
|
||||
pub unsafe fn get_unchecked_mut<I>(self, index: I) -> NonNull<I::Output>
|
||||
where
|
||||
I: ~const SliceIndex<[T]>,
|
||||
I: SliceIndex<[T]>,
|
||||
{
|
||||
// SAFETY: the caller ensures that `self` is dereferenceable and `index` in-bounds.
|
||||
// As a consequence, the resulting pointer cannot be null.
|
||||
@ -689,8 +688,7 @@ impl<T> NonNull<[T]> {
|
||||
}
|
||||
|
||||
#[stable(feature = "nonnull", since = "1.25.0")]
|
||||
#[rustc_const_unstable(feature = "const_clone", issue = "91805")]
|
||||
impl<T: ?Sized> const Clone for NonNull<T> {
|
||||
impl<T: ?Sized> Clone for NonNull<T> {
|
||||
#[inline(always)]
|
||||
fn clone(&self) -> Self {
|
||||
*self
|
||||
@ -756,8 +754,7 @@ impl<T: ?Sized> hash::Hash for NonNull<T> {
|
||||
}
|
||||
|
||||
#[unstable(feature = "ptr_internals", issue = "none")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl<T: ?Sized> const From<Unique<T>> for NonNull<T> {
|
||||
impl<T: ?Sized> From<Unique<T>> for NonNull<T> {
|
||||
#[inline]
|
||||
fn from(unique: Unique<T>) -> Self {
|
||||
// SAFETY: A Unique pointer cannot be null, so the conditions for
|
||||
@ -767,8 +764,7 @@ impl<T: ?Sized> const From<Unique<T>> for NonNull<T> {
|
||||
}
|
||||
|
||||
#[stable(feature = "nonnull", since = "1.25.0")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl<T: ?Sized> const From<&mut T> for NonNull<T> {
|
||||
impl<T: ?Sized> From<&mut T> for NonNull<T> {
|
||||
/// Converts a `&mut T` to a `NonNull<T>`.
|
||||
///
|
||||
/// This conversion is safe and infallible since references cannot be null.
|
||||
@ -780,8 +776,7 @@ impl<T: ?Sized> const From<&mut T> for NonNull<T> {
|
||||
}
|
||||
|
||||
#[stable(feature = "nonnull", since = "1.25.0")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl<T: ?Sized> const From<&T> for NonNull<T> {
|
||||
impl<T: ?Sized> From<&T> for NonNull<T> {
|
||||
/// Converts a `&T` to a `NonNull<T>`.
|
||||
///
|
||||
/// This conversion is safe and infallible since references cannot be null.
|
||||
|
@ -70,7 +70,8 @@ impl<T: Sized> Unique<T> {
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn dangling() -> Self {
|
||||
Self::from(NonNull::dangling())
|
||||
// FIXME(const-hack) replace with `From`
|
||||
Unique { pointer: NonNull::dangling(), _marker: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,13 +135,14 @@ impl<T: ?Sized> Unique<T> {
|
||||
#[must_use = "`self` will be dropped if the result is not used"]
|
||||
#[inline]
|
||||
pub const fn cast<U>(self) -> Unique<U> {
|
||||
Unique::from(self.pointer.cast())
|
||||
// FIXME(const-hack): replace with `From`
|
||||
// SAFETY: is `NonNull`
|
||||
unsafe { Unique::new_unchecked(self.pointer.cast().as_ptr()) }
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "ptr_internals", issue = "none")]
|
||||
#[rustc_const_unstable(feature = "const_clone", issue = "91805")]
|
||||
impl<T: ?Sized> const Clone for Unique<T> {
|
||||
impl<T: ?Sized> Clone for Unique<T> {
|
||||
#[inline]
|
||||
fn clone(&self) -> Self {
|
||||
*self
|
||||
@ -171,7 +173,7 @@ impl<T: ?Sized> fmt::Pointer for Unique<T> {
|
||||
}
|
||||
|
||||
#[unstable(feature = "ptr_internals", issue = "none")]
|
||||
impl<T: ?Sized> const From<&mut T> for Unique<T> {
|
||||
impl<T: ?Sized> From<&mut T> for Unique<T> {
|
||||
/// Converts a `&mut T` to a `Unique<T>`.
|
||||
///
|
||||
/// This conversion is infallible since references cannot be null.
|
||||
@ -182,7 +184,7 @@ impl<T: ?Sized> const From<&mut T> for Unique<T> {
|
||||
}
|
||||
|
||||
#[unstable(feature = "ptr_internals", issue = "none")]
|
||||
impl<T: ?Sized> const From<NonNull<T>> for Unique<T> {
|
||||
impl<T: ?Sized> From<NonNull<T>> for Unique<T> {
|
||||
/// Converts a `NonNull<T>` to a `Unique<T>`.
|
||||
///
|
||||
/// This conversion is infallible since `NonNull` cannot be null.
|
||||
|
@ -489,7 +489,6 @@
|
||||
#![stable(feature = "rust1", since = "1.0.0")]
|
||||
|
||||
use crate::iter::{self, FromIterator, FusedIterator, TrustedLen};
|
||||
use crate::marker::Destruct;
|
||||
use crate::ops::{self, ControlFlow, Deref, DerefMut};
|
||||
use crate::{convert, fmt, hint};
|
||||
|
||||
@ -629,16 +628,10 @@ impl<T, E> Result<T, E> {
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_result_drop", issue = "92384")]
|
||||
pub const fn ok(self) -> Option<T>
|
||||
where
|
||||
E: ~const Destruct,
|
||||
{
|
||||
pub fn ok(self) -> Option<T> {
|
||||
match self {
|
||||
Ok(x) => Some(x),
|
||||
// FIXME: ~const Drop doesn't quite work right yet
|
||||
#[allow(unused_variables)]
|
||||
Err(x) => None,
|
||||
Err(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
@ -658,15 +651,9 @@ impl<T, E> Result<T, E> {
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_result_drop", issue = "92384")]
|
||||
pub const fn err(self) -> Option<E>
|
||||
where
|
||||
T: ~const Destruct,
|
||||
{
|
||||
pub fn err(self) -> Option<E> {
|
||||
match self {
|
||||
// FIXME: ~const Drop doesn't quite work right yet
|
||||
#[allow(unused_variables)]
|
||||
Ok(x) => None,
|
||||
Ok(_) => None,
|
||||
Err(x) => Some(x),
|
||||
}
|
||||
}
|
||||
@ -1287,18 +1274,10 @@ impl<T, E> Result<T, E> {
|
||||
/// assert_eq!(x.and(y), Ok("different result type"));
|
||||
/// ```
|
||||
#[inline]
|
||||
#[rustc_const_unstable(feature = "const_result_drop", issue = "92384")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const fn and<U>(self, res: Result<U, E>) -> Result<U, E>
|
||||
where
|
||||
T: ~const Destruct,
|
||||
U: ~const Destruct,
|
||||
E: ~const Destruct,
|
||||
{
|
||||
pub fn and<U>(self, res: Result<U, E>) -> Result<U, E> {
|
||||
match self {
|
||||
// FIXME: ~const Drop doesn't quite work right yet
|
||||
#[allow(unused_variables)]
|
||||
Ok(x) => res,
|
||||
Ok(_) => res,
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
@ -1370,19 +1349,11 @@ impl<T, E> Result<T, E> {
|
||||
/// assert_eq!(x.or(y), Ok(2));
|
||||
/// ```
|
||||
#[inline]
|
||||
#[rustc_const_unstable(feature = "const_result_drop", issue = "92384")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const fn or<F>(self, res: Result<T, F>) -> Result<T, F>
|
||||
where
|
||||
T: ~const Destruct,
|
||||
E: ~const Destruct,
|
||||
F: ~const Destruct,
|
||||
{
|
||||
pub fn or<F>(self, res: Result<T, F>) -> Result<T, F> {
|
||||
match self {
|
||||
Ok(v) => Ok(v),
|
||||
// FIXME: ~const Drop doesn't quite work right yet
|
||||
#[allow(unused_variables)]
|
||||
Err(e) => res,
|
||||
Err(_) => res,
|
||||
}
|
||||
}
|
||||
|
||||
@ -1430,18 +1401,11 @@ impl<T, E> Result<T, E> {
|
||||
/// assert_eq!(x.unwrap_or(default), default);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[rustc_const_unstable(feature = "const_result_drop", issue = "92384")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const fn unwrap_or(self, default: T) -> T
|
||||
where
|
||||
T: ~const Destruct,
|
||||
E: ~const Destruct,
|
||||
{
|
||||
pub fn unwrap_or(self, default: T) -> T {
|
||||
match self {
|
||||
Ok(t) => t,
|
||||
// FIXME: ~const Drop doesn't quite work right yet
|
||||
#[allow(unused_variables)]
|
||||
Err(e) => default,
|
||||
Err(_) => default,
|
||||
}
|
||||
}
|
||||
|
||||
@ -1704,11 +1668,10 @@ fn unwrap_failed<T>(_msg: &str, _error: &T) -> ! {
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_clone", issue = "91805")]
|
||||
impl<T, E> const Clone for Result<T, E>
|
||||
impl<T, E> Clone for Result<T, E>
|
||||
where
|
||||
T: ~const Clone + ~const Destruct,
|
||||
E: ~const Clone + ~const Destruct,
|
||||
T: Clone,
|
||||
E: Clone,
|
||||
{
|
||||
#[inline]
|
||||
fn clone(&self) -> Self {
|
||||
@ -1971,8 +1934,7 @@ impl<A, E, V: FromIterator<A>> FromIterator<Result<A, E>> for Result<V, E> {
|
||||
}
|
||||
|
||||
#[unstable(feature = "try_trait_v2", issue = "84277")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl<T, E> const ops::Try for Result<T, E> {
|
||||
impl<T, E> ops::Try for Result<T, E> {
|
||||
type Output = T;
|
||||
type Residual = Result<convert::Infallible, E>;
|
||||
|
||||
@ -1991,10 +1953,7 @@ impl<T, E> const ops::Try for Result<T, E> {
|
||||
}
|
||||
|
||||
#[unstable(feature = "try_trait_v2", issue = "84277")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl<T, E, F: ~const From<E>> const ops::FromResidual<Result<convert::Infallible, E>>
|
||||
for Result<T, F>
|
||||
{
|
||||
impl<T, E, F: From<E>> ops::FromResidual<Result<convert::Infallible, E>> for Result<T, F> {
|
||||
#[inline]
|
||||
#[track_caller]
|
||||
fn from_residual(residual: Result<convert::Infallible, E>) -> Self {
|
||||
@ -2013,7 +1972,6 @@ impl<T, E, F: From<E>> ops::FromResidual<ops::Yeet<E>> for Result<T, F> {
|
||||
}
|
||||
|
||||
#[unstable(feature = "try_trait_v2_residual", issue = "91285")]
|
||||
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
|
||||
impl<T, E> const ops::Residual<T> for Result<convert::Infallible, E> {
|
||||
impl<T, E> ops::Residual<T> for Result<convert::Infallible, E> {
|
||||
type TryType = Result<T, E>;
|
||||
}
|
||||
|
@ -7,10 +7,9 @@ use crate::ops;
|
||||
use crate::ptr;
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
impl<T, I> const ops::Index<I> for [T]
|
||||
impl<T, I> ops::Index<I> for [T]
|
||||
where
|
||||
I: ~const SliceIndex<[T]>,
|
||||
I: SliceIndex<[T]>,
|
||||
{
|
||||
type Output = I::Output;
|
||||
|
||||
@ -21,10 +20,9 @@ where
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
impl<T, I> const ops::IndexMut<I> for [T]
|
||||
impl<T, I> ops::IndexMut<I> for [T]
|
||||
where
|
||||
I: ~const SliceIndex<[T]>,
|
||||
I: SliceIndex<[T]>,
|
||||
{
|
||||
#[inline]
|
||||
fn index_mut(&mut self, index: I) -> &mut I::Output {
|
||||
@ -162,7 +160,6 @@ mod private_slice_index {
|
||||
message = "the type `{T}` cannot be indexed by `{Self}`",
|
||||
label = "slice indices are of type `usize` or ranges of `usize`"
|
||||
)]
|
||||
#[const_trait]
|
||||
pub unsafe trait SliceIndex<T: ?Sized>: private_slice_index::Sealed {
|
||||
/// The output type returned by methods.
|
||||
#[stable(feature = "slice_get_slice", since = "1.28.0")]
|
||||
@ -211,7 +208,7 @@ pub unsafe trait SliceIndex<T: ?Sized>: private_slice_index::Sealed {
|
||||
|
||||
#[stable(feature = "slice_get_slice_impls", since = "1.15.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
unsafe impl<T> const SliceIndex<[T]> for usize {
|
||||
unsafe impl<T> SliceIndex<[T]> for usize {
|
||||
type Output = T;
|
||||
|
||||
#[inline]
|
||||
@ -271,7 +268,7 @@ unsafe impl<T> const SliceIndex<[T]> for usize {
|
||||
/// Because `IndexRange` guarantees `start <= end`, fewer checks are needed here
|
||||
/// than there are for a general `Range<usize>` (which might be `100..3`).
|
||||
#[rustc_const_unstable(feature = "const_index_range_slice_index", issue = "none")]
|
||||
unsafe impl<T> const SliceIndex<[T]> for ops::IndexRange {
|
||||
unsafe impl<T> SliceIndex<[T]> for ops::IndexRange {
|
||||
type Output = [T];
|
||||
|
||||
#[inline]
|
||||
@ -347,7 +344,7 @@ unsafe impl<T> const SliceIndex<[T]> for ops::IndexRange {
|
||||
|
||||
#[stable(feature = "slice_get_slice_impls", since = "1.15.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
unsafe impl<T> const SliceIndex<[T]> for ops::Range<usize> {
|
||||
unsafe impl<T> SliceIndex<[T]> for ops::Range<usize> {
|
||||
type Output = [T];
|
||||
|
||||
#[inline]
|
||||
@ -428,7 +425,7 @@ unsafe impl<T> const SliceIndex<[T]> for ops::Range<usize> {
|
||||
|
||||
#[stable(feature = "slice_get_slice_impls", since = "1.15.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
unsafe impl<T> const SliceIndex<[T]> for ops::RangeTo<usize> {
|
||||
unsafe impl<T> SliceIndex<[T]> for ops::RangeTo<usize> {
|
||||
type Output = [T];
|
||||
|
||||
#[inline]
|
||||
@ -466,7 +463,7 @@ unsafe impl<T> const SliceIndex<[T]> for ops::RangeTo<usize> {
|
||||
|
||||
#[stable(feature = "slice_get_slice_impls", since = "1.15.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
unsafe impl<T> const SliceIndex<[T]> for ops::RangeFrom<usize> {
|
||||
unsafe impl<T> SliceIndex<[T]> for ops::RangeFrom<usize> {
|
||||
type Output = [T];
|
||||
|
||||
#[inline]
|
||||
@ -512,7 +509,7 @@ unsafe impl<T> const SliceIndex<[T]> for ops::RangeFrom<usize> {
|
||||
|
||||
#[stable(feature = "slice_get_slice_impls", since = "1.15.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
unsafe impl<T> const SliceIndex<[T]> for ops::RangeFull {
|
||||
unsafe impl<T> SliceIndex<[T]> for ops::RangeFull {
|
||||
type Output = [T];
|
||||
|
||||
#[inline]
|
||||
@ -548,7 +545,7 @@ unsafe impl<T> const SliceIndex<[T]> for ops::RangeFull {
|
||||
|
||||
#[stable(feature = "inclusive_range", since = "1.26.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
unsafe impl<T> const SliceIndex<[T]> for ops::RangeInclusive<usize> {
|
||||
unsafe impl<T> SliceIndex<[T]> for ops::RangeInclusive<usize> {
|
||||
type Output = [T];
|
||||
|
||||
#[inline]
|
||||
@ -592,7 +589,7 @@ unsafe impl<T> const SliceIndex<[T]> for ops::RangeInclusive<usize> {
|
||||
|
||||
#[stable(feature = "inclusive_range", since = "1.26.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
unsafe impl<T> const SliceIndex<[T]> for ops::RangeToInclusive<usize> {
|
||||
unsafe impl<T> SliceIndex<[T]> for ops::RangeToInclusive<usize> {
|
||||
type Output = [T];
|
||||
|
||||
#[inline]
|
||||
|
@ -1,7 +1,6 @@
|
||||
// Original implementation taken from rust-memchr.
|
||||
// Copyright 2015 Andrew Gallant, bluss and Nicolas Koch
|
||||
|
||||
use crate::cmp;
|
||||
use crate::mem;
|
||||
|
||||
const LO_USIZE: usize = usize::repeat_u8(0x01);
|
||||
@ -83,8 +82,12 @@ const fn memchr_aligned(x: u8, text: &[u8]) -> Option<usize> {
|
||||
let mut offset = ptr.align_offset(USIZE_BYTES);
|
||||
|
||||
if offset > 0 {
|
||||
offset = cmp::min(offset, len);
|
||||
if let Some(index) = memchr_naive(x, &text[..offset]) {
|
||||
// FIXME(const-hack, fee1-dead): replace with min
|
||||
offset = if offset < len { offset } else { len };
|
||||
// FIXME(const-hack, fee1-dead): replace with range slicing
|
||||
// SAFETY: offset is within bounds
|
||||
let slice = unsafe { super::from_raw_parts(text.as_ptr(), offset) };
|
||||
if let Some(index) = memchr_naive(x, slice) {
|
||||
return Some(index);
|
||||
}
|
||||
}
|
||||
@ -110,7 +113,10 @@ const fn memchr_aligned(x: u8, text: &[u8]) -> Option<usize> {
|
||||
|
||||
// Find the byte after the point the body loop stopped.
|
||||
// FIXME(const-hack): Use `?` instead.
|
||||
if let Some(i) = memchr_naive(x, &text[offset..]) { Some(offset + i) } else { None }
|
||||
// FIXME(const-hack, fee1-dead): use range slicing
|
||||
// SAFETY: offset is within bounds
|
||||
let slice = unsafe { super::from_raw_parts(text.as_ptr().add(offset), text.len() - offset) };
|
||||
if let Some(i) = memchr_naive(x, slice) { Some(offset + i) } else { None }
|
||||
}
|
||||
|
||||
/// Returns the last index matching the byte `x` in `text`.
|
||||
|
@ -333,12 +333,11 @@ impl<T> [T] {
|
||||
/// assert_eq!(None, v.get(0..4));
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const fn get<I>(&self, index: I) -> Option<&I::Output>
|
||||
pub fn get<I>(&self, index: I) -> Option<&I::Output>
|
||||
where
|
||||
I: ~const SliceIndex<Self>,
|
||||
I: SliceIndex<Self>,
|
||||
{
|
||||
index.get(self)
|
||||
}
|
||||
@ -359,12 +358,11 @@ impl<T> [T] {
|
||||
/// assert_eq!(x, &[0, 42, 2]);
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const fn get_mut<I>(&mut self, index: I) -> Option<&mut I::Output>
|
||||
pub fn get_mut<I>(&mut self, index: I) -> Option<&mut I::Output>
|
||||
where
|
||||
I: ~const SliceIndex<Self>,
|
||||
I: SliceIndex<Self>,
|
||||
{
|
||||
index.get_mut(self)
|
||||
}
|
||||
@ -392,12 +390,11 @@ impl<T> [T] {
|
||||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const unsafe fn get_unchecked<I>(&self, index: I) -> &I::Output
|
||||
pub unsafe fn get_unchecked<I>(&self, index: I) -> &I::Output
|
||||
where
|
||||
I: ~const SliceIndex<Self>,
|
||||
I: SliceIndex<Self>,
|
||||
{
|
||||
// SAFETY: the caller must uphold most of the safety requirements for `get_unchecked`;
|
||||
// the slice is dereferenceable because `self` is a safe reference.
|
||||
@ -430,12 +427,11 @@ impl<T> [T] {
|
||||
/// assert_eq!(x, &[1, 13, 4]);
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const unsafe fn get_unchecked_mut<I>(&mut self, index: I) -> &mut I::Output
|
||||
pub unsafe fn get_unchecked_mut<I>(&mut self, index: I) -> &mut I::Output
|
||||
where
|
||||
I: ~const SliceIndex<Self>,
|
||||
I: SliceIndex<Self>,
|
||||
{
|
||||
// SAFETY: the caller must uphold the safety requirements for `get_unchecked_mut`;
|
||||
// the slice is dereferenceable because `self` is a safe reference.
|
||||
@ -678,9 +674,8 @@ impl<T> [T] {
|
||||
/// assert!(v == [3, 2, 1]);
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_reverse", issue = "100784")]
|
||||
#[inline]
|
||||
pub const fn reverse(&mut self) {
|
||||
pub fn reverse(&mut self) {
|
||||
let half_len = self.len() / 2;
|
||||
let Range { start, end } = self.as_mut_ptr_range();
|
||||
|
||||
@ -703,7 +698,7 @@ impl<T> [T] {
|
||||
revswap(front_half, back_half, half_len);
|
||||
|
||||
#[inline]
|
||||
const fn revswap<T>(a: &mut [T], b: &mut [T], n: usize) {
|
||||
fn revswap<T>(a: &mut [T], b: &mut [T], n: usize) {
|
||||
debug_assert!(a.len() == n);
|
||||
debug_assert!(b.len() == n);
|
||||
|
||||
@ -4404,8 +4399,7 @@ where
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
|
||||
impl<T> const Default for &[T] {
|
||||
impl<T> Default for &[T] {
|
||||
/// Creates an empty slice.
|
||||
fn default() -> Self {
|
||||
&[]
|
||||
@ -4413,8 +4407,7 @@ impl<T> const Default for &[T] {
|
||||
}
|
||||
|
||||
#[stable(feature = "mut_slice_default", since = "1.5.0")]
|
||||
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
|
||||
impl<T> const Default for &mut [T] {
|
||||
impl<T> Default for &mut [T] {
|
||||
/// Creates a mutable empty slice.
|
||||
fn default() -> Self {
|
||||
&mut []
|
||||
|
@ -206,9 +206,8 @@ impl str {
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "is_char_boundary", since = "1.9.0")]
|
||||
#[rustc_const_unstable(feature = "const_is_char_boundary", issue = "none")]
|
||||
#[inline]
|
||||
pub const fn is_char_boundary(&self, index: usize) -> bool {
|
||||
pub fn is_char_boundary(&self, index: usize) -> bool {
|
||||
// 0 is always ok.
|
||||
// Test for 0 explicitly so that it can optimize out the check
|
||||
// easily and skip reading string data for that case.
|
||||
@ -436,9 +435,8 @@ impl str {
|
||||
/// assert!(v.get(..42).is_none());
|
||||
/// ```
|
||||
#[stable(feature = "str_checked_slicing", since = "1.20.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
#[inline]
|
||||
pub const fn get<I: ~const SliceIndex<str>>(&self, i: I) -> Option<&I::Output> {
|
||||
pub fn get<I: SliceIndex<str>>(&self, i: I) -> Option<&I::Output> {
|
||||
i.get(self)
|
||||
}
|
||||
|
||||
@ -469,9 +467,8 @@ impl str {
|
||||
/// assert_eq!("HEllo", v);
|
||||
/// ```
|
||||
#[stable(feature = "str_checked_slicing", since = "1.20.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
#[inline]
|
||||
pub const fn get_mut<I: ~const SliceIndex<str>>(&mut self, i: I) -> Option<&mut I::Output> {
|
||||
pub fn get_mut<I: SliceIndex<str>>(&mut self, i: I) -> Option<&mut I::Output> {
|
||||
i.get_mut(self)
|
||||
}
|
||||
|
||||
@ -502,9 +499,8 @@ impl str {
|
||||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "str_checked_slicing", since = "1.20.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
#[inline]
|
||||
pub const unsafe fn get_unchecked<I: ~const SliceIndex<str>>(&self, i: I) -> &I::Output {
|
||||
pub unsafe fn get_unchecked<I: SliceIndex<str>>(&self, i: I) -> &I::Output {
|
||||
// SAFETY: the caller must uphold the safety contract for `get_unchecked`;
|
||||
// the slice is dereferenceable because `self` is a safe reference.
|
||||
// The returned pointer is safe because impls of `SliceIndex` have to guarantee that it is.
|
||||
@ -538,12 +534,8 @@ impl str {
|
||||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "str_checked_slicing", since = "1.20.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
#[inline]
|
||||
pub const unsafe fn get_unchecked_mut<I: ~const SliceIndex<str>>(
|
||||
&mut self,
|
||||
i: I,
|
||||
) -> &mut I::Output {
|
||||
pub unsafe fn get_unchecked_mut<I: SliceIndex<str>>(&mut self, i: I) -> &mut I::Output {
|
||||
// SAFETY: the caller must uphold the safety contract for `get_unchecked_mut`;
|
||||
// the slice is dereferenceable because `self` is a safe reference.
|
||||
// The returned pointer is safe because impls of `SliceIndex` have to guarantee that it is.
|
||||
@ -2582,8 +2574,7 @@ impl AsRef<[u8]> for str {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
|
||||
impl const Default for &str {
|
||||
impl Default for &str {
|
||||
/// Creates an empty str
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
|
@ -50,10 +50,9 @@ impl PartialOrd for str {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
impl<I> const ops::Index<I> for str
|
||||
impl<I> ops::Index<I> for str
|
||||
where
|
||||
I: ~const SliceIndex<str>,
|
||||
I: SliceIndex<str>,
|
||||
{
|
||||
type Output = I::Output;
|
||||
|
||||
@ -64,10 +63,9 @@ where
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
impl<I> const ops::IndexMut<I> for str
|
||||
impl<I> ops::IndexMut<I> for str
|
||||
where
|
||||
I: ~const SliceIndex<str>,
|
||||
I: SliceIndex<str>,
|
||||
{
|
||||
#[inline]
|
||||
fn index_mut(&mut self, index: I) -> &mut I::Output {
|
||||
@ -96,7 +94,7 @@ const fn str_index_overflow_fail() -> ! {
|
||||
/// Equivalent to `&self[0 .. len]` or `&mut self[0 .. len]`.
|
||||
#[stable(feature = "str_checked_slicing", since = "1.20.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
unsafe impl const SliceIndex<str> for ops::RangeFull {
|
||||
unsafe impl SliceIndex<str> for ops::RangeFull {
|
||||
type Output = str;
|
||||
#[inline]
|
||||
fn get(self, slice: &str) -> Option<&Self::Output> {
|
||||
@ -161,7 +159,7 @@ unsafe impl const SliceIndex<str> for ops::RangeFull {
|
||||
/// ```
|
||||
#[stable(feature = "str_checked_slicing", since = "1.20.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
unsafe impl const SliceIndex<str> for ops::Range<usize> {
|
||||
unsafe impl SliceIndex<str> for ops::Range<usize> {
|
||||
type Output = str;
|
||||
#[inline]
|
||||
fn get(self, slice: &str) -> Option<&Self::Output> {
|
||||
@ -271,7 +269,7 @@ unsafe impl const SliceIndex<str> for ops::Range<usize> {
|
||||
/// character (as defined by `is_char_boundary`), or if `end > len`.
|
||||
#[stable(feature = "str_checked_slicing", since = "1.20.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
unsafe impl const SliceIndex<str> for ops::RangeTo<usize> {
|
||||
unsafe impl SliceIndex<str> for ops::RangeTo<usize> {
|
||||
type Output = str;
|
||||
#[inline]
|
||||
fn get(self, slice: &str) -> Option<&Self::Output> {
|
||||
@ -340,7 +338,7 @@ unsafe impl const SliceIndex<str> for ops::RangeTo<usize> {
|
||||
/// a character (as defined by `is_char_boundary`), or if `begin > len`.
|
||||
#[stable(feature = "str_checked_slicing", since = "1.20.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
unsafe impl const SliceIndex<str> for ops::RangeFrom<usize> {
|
||||
unsafe impl SliceIndex<str> for ops::RangeFrom<usize> {
|
||||
type Output = str;
|
||||
#[inline]
|
||||
fn get(self, slice: &str) -> Option<&Self::Output> {
|
||||
@ -412,7 +410,7 @@ unsafe impl const SliceIndex<str> for ops::RangeFrom<usize> {
|
||||
/// byte offset or equal to `len`), if `begin > end`, or if `end >= len`.
|
||||
#[stable(feature = "inclusive_range", since = "1.26.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
unsafe impl const SliceIndex<str> for ops::RangeInclusive<usize> {
|
||||
unsafe impl SliceIndex<str> for ops::RangeInclusive<usize> {
|
||||
type Output = str;
|
||||
#[inline]
|
||||
fn get(self, slice: &str) -> Option<&Self::Output> {
|
||||
@ -464,7 +462,7 @@ unsafe impl const SliceIndex<str> for ops::RangeInclusive<usize> {
|
||||
/// `is_char_boundary`, or equal to `len`), or if `end >= len`.
|
||||
#[stable(feature = "inclusive_range", since = "1.26.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
unsafe impl const SliceIndex<str> for ops::RangeToInclusive<usize> {
|
||||
unsafe impl SliceIndex<str> for ops::RangeToInclusive<usize> {
|
||||
type Output = str;
|
||||
#[inline]
|
||||
fn get(self, slice: &str) -> Option<&Self::Output> {
|
||||
|
@ -147,8 +147,7 @@ pub struct AtomicBool {
|
||||
|
||||
#[cfg(target_has_atomic_load_store = "8")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
|
||||
impl const Default for AtomicBool {
|
||||
impl Default for AtomicBool {
|
||||
/// Creates an `AtomicBool` initialized to `false`.
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
@ -179,8 +178,7 @@ pub struct AtomicPtr<T> {
|
||||
|
||||
#[cfg(target_has_atomic_load_store = "ptr")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
|
||||
impl<T> const Default for AtomicPtr<T> {
|
||||
impl<T> Default for AtomicPtr<T> {
|
||||
/// Creates a null `AtomicPtr<T>`.
|
||||
fn default() -> AtomicPtr<T> {
|
||||
AtomicPtr::new(crate::ptr::null_mut())
|
||||
@ -1916,8 +1914,7 @@ impl<T> AtomicPtr<T> {
|
||||
|
||||
#[cfg(target_has_atomic_load_store = "8")]
|
||||
#[stable(feature = "atomic_bool_from", since = "1.24.0")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl const From<bool> for AtomicBool {
|
||||
impl From<bool> for AtomicBool {
|
||||
/// Converts a `bool` into an `AtomicBool`.
|
||||
///
|
||||
/// # Examples
|
||||
@ -1935,8 +1932,7 @@ impl const From<bool> for AtomicBool {
|
||||
|
||||
#[cfg(target_has_atomic_load_store = "ptr")]
|
||||
#[stable(feature = "atomic_from", since = "1.23.0")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl<T> const From<*mut T> for AtomicPtr<T> {
|
||||
impl<T> From<*mut T> for AtomicPtr<T> {
|
||||
/// Converts a `*mut T` into an `AtomicPtr<T>`.
|
||||
#[inline]
|
||||
fn from(p: *mut T) -> Self {
|
||||
@ -2002,8 +1998,7 @@ macro_rules! atomic_int {
|
||||
pub const $atomic_init: $atomic_type = $atomic_type::new(0);
|
||||
|
||||
#[$stable]
|
||||
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
|
||||
impl const Default for $atomic_type {
|
||||
impl Default for $atomic_type {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
Self::new(Default::default())
|
||||
@ -2011,8 +2006,7 @@ macro_rules! atomic_int {
|
||||
}
|
||||
|
||||
#[$stable_from]
|
||||
#[rustc_const_unstable(feature = "const_num_from_num", issue = "87852")]
|
||||
impl const From<$int_type> for $atomic_type {
|
||||
impl From<$int_type> for $atomic_type {
|
||||
#[doc = concat!("Converts an `", stringify!($int_type), "` into an `", stringify!($atomic_type), "`.")]
|
||||
#[inline]
|
||||
fn from(v: $int_type) -> Self { Self::new(v) }
|
||||
|
@ -247,8 +247,7 @@ impl<T, E> Poll<Option<Result<T, E>>> {
|
||||
}
|
||||
|
||||
#[stable(feature = "futures_api", since = "1.36.0")]
|
||||
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||
impl<T> const From<T> for Poll<T> {
|
||||
impl<T> From<T> for Poll<T> {
|
||||
/// Moves the value into a [`Poll::Ready`] to make a `Poll<T>`.
|
||||
///
|
||||
/// # Example
|
||||
|
@ -735,8 +735,7 @@ impl Duration {
|
||||
#[stable(feature = "duration_float", since = "1.38.0")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
|
||||
pub const fn from_secs_f64(secs: f64) -> Duration {
|
||||
pub fn from_secs_f64(secs: f64) -> Duration {
|
||||
match Duration::try_from_secs_f64(secs) {
|
||||
Ok(v) => v,
|
||||
Err(e) => panic!("{}", e.description()),
|
||||
@ -773,8 +772,7 @@ impl Duration {
|
||||
#[stable(feature = "duration_float", since = "1.38.0")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
|
||||
pub const fn from_secs_f32(secs: f32) -> Duration {
|
||||
pub fn from_secs_f32(secs: f32) -> Duration {
|
||||
match Duration::try_from_secs_f32(secs) {
|
||||
Ok(v) => v,
|
||||
Err(e) => panic!("{}", e.description()),
|
||||
@ -798,8 +796,7 @@ impl Duration {
|
||||
#[must_use = "this returns the result of the operation, \
|
||||
without modifying the original"]
|
||||
#[inline]
|
||||
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
|
||||
pub const fn mul_f64(self, rhs: f64) -> Duration {
|
||||
pub fn mul_f64(self, rhs: f64) -> Duration {
|
||||
Duration::from_secs_f64(rhs * self.as_secs_f64())
|
||||
}
|
||||
|
||||
@ -820,8 +817,7 @@ impl Duration {
|
||||
#[must_use = "this returns the result of the operation, \
|
||||
without modifying the original"]
|
||||
#[inline]
|
||||
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
|
||||
pub const fn mul_f32(self, rhs: f32) -> Duration {
|
||||
pub fn mul_f32(self, rhs: f32) -> Duration {
|
||||
Duration::from_secs_f32(rhs * self.as_secs_f32())
|
||||
}
|
||||
|
||||
@ -842,8 +838,7 @@ impl Duration {
|
||||
#[must_use = "this returns the result of the operation, \
|
||||
without modifying the original"]
|
||||
#[inline]
|
||||
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
|
||||
pub const fn div_f64(self, rhs: f64) -> Duration {
|
||||
pub fn div_f64(self, rhs: f64) -> Duration {
|
||||
Duration::from_secs_f64(self.as_secs_f64() / rhs)
|
||||
}
|
||||
|
||||
@ -866,8 +861,7 @@ impl Duration {
|
||||
#[must_use = "this returns the result of the operation, \
|
||||
without modifying the original"]
|
||||
#[inline]
|
||||
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
|
||||
pub const fn div_f32(self, rhs: f32) -> Duration {
|
||||
pub fn div_f32(self, rhs: f32) -> Duration {
|
||||
Duration::from_secs_f32(self.as_secs_f32() / rhs)
|
||||
}
|
||||
|
||||
@ -1402,9 +1396,8 @@ impl Duration {
|
||||
/// assert_eq!(res, Ok(Duration::new(1, 2_929_688)));
|
||||
/// ```
|
||||
#[stable(feature = "duration_checked_float", since = "1.66.0")]
|
||||
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
|
||||
#[inline]
|
||||
pub const fn try_from_secs_f32(secs: f32) -> Result<Duration, TryFromFloatSecsError> {
|
||||
pub fn try_from_secs_f32(secs: f32) -> Result<Duration, TryFromFloatSecsError> {
|
||||
try_from_secs!(
|
||||
secs = secs,
|
||||
mantissa_bits = 23,
|
||||
@ -1479,9 +1472,8 @@ impl Duration {
|
||||
/// assert_eq!(res, Ok(Duration::new(1, 2_929_688)));
|
||||
/// ```
|
||||
#[stable(feature = "duration_checked_float", since = "1.66.0")]
|
||||
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
|
||||
#[inline]
|
||||
pub const fn try_from_secs_f64(secs: f64) -> Result<Duration, TryFromFloatSecsError> {
|
||||
pub fn try_from_secs_f64(secs: f64) -> Result<Duration, TryFromFloatSecsError> {
|
||||
try_from_secs!(
|
||||
secs = secs,
|
||||
mantissa_bits = 52,
|
||||
|
@ -22,8 +22,7 @@ macro_rules! tuple_impls {
|
||||
maybe_tuple_doc! {
|
||||
$($T)+ @
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
|
||||
impl<$($T: ~const PartialEq),+> const PartialEq for ($($T,)+)
|
||||
impl<$($T: PartialEq),+> PartialEq for ($($T,)+)
|
||||
where
|
||||
last_type!($($T,)+): ?Sized
|
||||
{
|
||||
@ -50,8 +49,7 @@ macro_rules! tuple_impls {
|
||||
maybe_tuple_doc! {
|
||||
$($T)+ @
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
|
||||
impl<$($T: ~const PartialOrd + ~const PartialEq),+> const PartialOrd for ($($T,)+)
|
||||
impl<$($T: PartialOrd),+> PartialOrd for ($($T,)+)
|
||||
where
|
||||
last_type!($($T,)+): ?Sized
|
||||
{
|
||||
@ -81,8 +79,7 @@ macro_rules! tuple_impls {
|
||||
maybe_tuple_doc! {
|
||||
$($T)+ @
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
|
||||
impl<$($T: ~const Ord),+> const Ord for ($($T,)+)
|
||||
impl<$($T: Ord),+> Ord for ($($T,)+)
|
||||
where
|
||||
last_type!($($T,)+): ?Sized
|
||||
{
|
||||
@ -96,8 +93,7 @@ macro_rules! tuple_impls {
|
||||
maybe_tuple_doc! {
|
||||
$($T)+ @
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
|
||||
impl<$($T: ~const Default),+> const Default for ($($T,)+) {
|
||||
impl<$($T: Default),+> Default for ($($T,)+) {
|
||||
#[inline]
|
||||
fn default() -> ($($T,)+) {
|
||||
($({ let x: $T = Default::default(); x},)+)
|
||||
|
@ -306,9 +306,11 @@ fn atomic_compare_exchange() {
|
||||
ATOMIC.compare_exchange_weak(0, 1, SeqCst, SeqCst).ok();
|
||||
}
|
||||
|
||||
/* FIXME(#110395)
|
||||
#[test]
|
||||
fn atomic_const_from() {
|
||||
const _ATOMIC_U8: AtomicU8 = AtomicU8::from(1);
|
||||
const _ATOMIC_BOOL: AtomicBool = AtomicBool::from(true);
|
||||
const _ATOMIC_PTR: AtomicPtr<u32> = AtomicPtr::from(core::ptr::null_mut());
|
||||
}
|
||||
*/
|
||||
|
@ -89,6 +89,7 @@ fn test_bool_to_option() {
|
||||
assert_eq!(false.then(|| 0), None);
|
||||
assert_eq!(true.then(|| 0), Some(0));
|
||||
|
||||
/* FIXME(#110395)
|
||||
const fn zero() -> i32 {
|
||||
0
|
||||
}
|
||||
@ -102,4 +103,5 @@ fn test_bool_to_option() {
|
||||
assert_eq!(B, Some(0));
|
||||
assert_eq!(C, None);
|
||||
assert_eq!(D, Some(0));
|
||||
*/
|
||||
}
|
||||
|
@ -468,6 +468,7 @@ fn const_cells() {
|
||||
const CELL: Cell<i32> = Cell::new(3);
|
||||
const _: i32 = CELL.into_inner();
|
||||
|
||||
/* FIXME(#110395)
|
||||
const UNSAFE_CELL_FROM: UnsafeCell<i32> = UnsafeCell::from(3);
|
||||
const _: i32 = UNSAFE_CELL.into_inner();
|
||||
|
||||
@ -476,4 +477,5 @@ fn const_cells() {
|
||||
|
||||
const CELL_FROM: Cell<i32> = Cell::from(3);
|
||||
const _: i32 = CELL.into_inner();
|
||||
*/
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ fn test_convert() {
|
||||
assert!(char::try_from(0xFFFF_FFFF_u32).is_err());
|
||||
}
|
||||
|
||||
/* FIXME(#110395)
|
||||
#[test]
|
||||
const fn test_convert_const() {
|
||||
assert!(u32::from('a') == 0x61);
|
||||
@ -30,6 +31,7 @@ const fn test_convert_const() {
|
||||
assert!(char::from(b'a') == 'a');
|
||||
assert!(char::from(b'\xFF') == '\u{FF}');
|
||||
}
|
||||
*/
|
||||
|
||||
#[test]
|
||||
fn test_from_str() {
|
||||
|
@ -217,18 +217,19 @@ fn cmp_default() {
|
||||
assert_eq!(Fool(false), Fool(true));
|
||||
}
|
||||
|
||||
/* FIXME(#110395)
|
||||
mod const_cmp {
|
||||
use super::*;
|
||||
|
||||
struct S(i32);
|
||||
|
||||
impl const PartialEq for S {
|
||||
impl PartialEq for S {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.0 == other.0
|
||||
}
|
||||
}
|
||||
|
||||
impl const PartialOrd for S {
|
||||
impl PartialOrd for S {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
let ret = match (self.0, other.0) {
|
||||
(a, b) if a > b => Ordering::Greater,
|
||||
@ -248,3 +249,4 @@ mod const_cmp {
|
||||
const _: () = assert!(S(0) < S(1));
|
||||
const _: () = assert!(S(1) > S(0));
|
||||
}
|
||||
*/
|
||||
|
@ -1,3 +1,4 @@
|
||||
/* FIXME(#110395)
|
||||
#[test]
|
||||
fn convert() {
|
||||
const fn from(x: i32) -> i32 {
|
||||
@ -14,3 +15,4 @@ fn convert() {
|
||||
const BAR: Vec<String> = into(Vec::new());
|
||||
assert_eq!(BAR, Vec::<String>::new());
|
||||
}
|
||||
*/
|
||||
|
@ -9,13 +9,13 @@ struct MyHasher {
|
||||
hash: u64,
|
||||
}
|
||||
|
||||
impl const Default for MyHasher {
|
||||
impl Default for MyHasher {
|
||||
fn default() -> MyHasher {
|
||||
MyHasher { hash: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
impl const Hasher for MyHasher {
|
||||
impl Hasher for MyHasher {
|
||||
fn write(&mut self, buf: &[u8]) {
|
||||
// FIXME(const_trait_impl): change to for loop
|
||||
let mut i = 0;
|
||||
@ -35,13 +35,14 @@ impl const Hasher for MyHasher {
|
||||
|
||||
#[test]
|
||||
fn test_writer_hasher() {
|
||||
const fn hash<T: ~const Hash>(t: &T) -> u64 {
|
||||
// FIXME(#110395)
|
||||
/* const */ fn hash<T: Hash>(t: &T) -> u64 {
|
||||
let mut s = MyHasher { hash: 0 };
|
||||
t.hash(&mut s);
|
||||
s.finish()
|
||||
}
|
||||
|
||||
const {
|
||||
/* const {
|
||||
// FIXME(fee1-dead): assert_eq
|
||||
assert!(hash(&()) == 0);
|
||||
assert!(hash(&5_u8) == 5);
|
||||
@ -52,7 +53,7 @@ fn test_writer_hasher() {
|
||||
|
||||
let s: &str = "a";
|
||||
assert!(hash(&s) == 97 + 0xFF);
|
||||
};
|
||||
}; */
|
||||
|
||||
assert_eq!(hash(&()), 0);
|
||||
|
||||
@ -113,7 +114,7 @@ struct CustomHasher {
|
||||
output: u64,
|
||||
}
|
||||
|
||||
impl const Hasher for CustomHasher {
|
||||
impl Hasher for CustomHasher {
|
||||
fn finish(&self) -> u64 {
|
||||
self.output
|
||||
}
|
||||
@ -125,21 +126,22 @@ impl const Hasher for CustomHasher {
|
||||
}
|
||||
}
|
||||
|
||||
impl const Default for CustomHasher {
|
||||
impl Default for CustomHasher {
|
||||
fn default() -> CustomHasher {
|
||||
CustomHasher { output: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
impl const Hash for Custom {
|
||||
fn hash<H: ~const Hasher>(&self, state: &mut H) {
|
||||
impl Hash for Custom {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
state.write_u64(self.hash);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_custom_state() {
|
||||
const fn hash<T: ~const Hash>(t: &T) -> u64 {
|
||||
// FIXME(#110395)
|
||||
/* const */ fn hash<T: Hash>(t: &T) -> u64 {
|
||||
let mut c = CustomHasher { output: 0 };
|
||||
t.hash(&mut c);
|
||||
c.finish()
|
||||
@ -147,7 +149,7 @@ fn test_custom_state() {
|
||||
|
||||
assert_eq!(hash(&Custom { hash: 5 }), 5);
|
||||
|
||||
const { assert!(hash(&Custom { hash: 6 }) == 6) };
|
||||
// const { assert!(hash(&Custom { hash: 6 }) == 6) };
|
||||
}
|
||||
|
||||
// FIXME: Instantiated functions with i128 in the signature is not supported in Emscripten.
|
||||
|
@ -23,12 +23,13 @@ fn hash<T: Hash>(x: &T) -> u64 {
|
||||
hash_with(SipHasher::new(), x)
|
||||
}
|
||||
|
||||
/* FIXME(#110395)
|
||||
#[test]
|
||||
const fn test_const_sip() {
|
||||
let val1 = 0x45;
|
||||
let val2 = 0xfeed;
|
||||
|
||||
const fn const_hash<T: ~const Hash>(x: &T) -> u64 {
|
||||
const fn const_hash<T: Hash>(x: &T) -> u64 {
|
||||
let mut st = SipHasher::new();
|
||||
x.hash(&mut st);
|
||||
st.finish()
|
||||
@ -36,6 +37,7 @@ const fn test_const_sip() {
|
||||
|
||||
assert!(const_hash(&(val1)) != const_hash(&(val2)));
|
||||
}
|
||||
*/
|
||||
|
||||
#[test]
|
||||
#[allow(unused_must_use)]
|
||||
|
@ -46,11 +46,13 @@ fn unsync_once_cell_drop_empty() {
|
||||
drop(x);
|
||||
}
|
||||
|
||||
/* FIXME(#110395)
|
||||
#[test]
|
||||
const fn once_cell_const() {
|
||||
let _once_cell: OnceCell<u32> = OnceCell::new();
|
||||
let _once_cell: OnceCell<u32> = OnceCell::from(32);
|
||||
}
|
||||
*/
|
||||
|
||||
#[test]
|
||||
fn clone() {
|
||||
|
@ -8,16 +8,13 @@
|
||||
#![feature(const_assume)]
|
||||
#![feature(const_align_of_val_raw)]
|
||||
#![feature(const_black_box)]
|
||||
#![feature(const_bool_to_option)]
|
||||
#![feature(const_caller_location)]
|
||||
#![feature(const_cell_into_inner)]
|
||||
#![feature(const_convert)]
|
||||
#![feature(const_hash)]
|
||||
#![feature(const_heap)]
|
||||
#![feature(const_maybe_uninit_as_mut_ptr)]
|
||||
#![feature(const_maybe_uninit_assume_init_read)]
|
||||
#![feature(const_nonnull_new)]
|
||||
#![feature(const_num_from_num)]
|
||||
#![feature(const_pointer_byte_offsets)]
|
||||
#![feature(const_pointer_is_aligned)]
|
||||
#![feature(const_ptr_as_ref)]
|
||||
|
@ -215,11 +215,13 @@ fn nonzero_const() {
|
||||
const ONE: Option<NonZeroU8> = NonZeroU8::new(1);
|
||||
assert!(ONE.is_some());
|
||||
|
||||
/* FIXME(#110395)
|
||||
const FROM_NONZERO_U8: u8 = u8::from(NONZERO_U8);
|
||||
assert_eq!(FROM_NONZERO_U8, 5);
|
||||
|
||||
const NONZERO_CONVERT: NonZeroU32 = NonZeroU32::from(NONZERO_U8);
|
||||
assert_eq!(NONZERO_CONVERT.get(), 5);
|
||||
*/
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1,3 +1,4 @@
|
||||
/* FIXME(#110395)
|
||||
#[test]
|
||||
fn from() {
|
||||
use core::convert::TryFrom;
|
||||
@ -23,3 +24,4 @@ fn from() {
|
||||
const I16_FROM_U16: Result<i16, TryFromIntError> = i16::try_from(1u16);
|
||||
assert_eq!(I16_FROM_U16, Ok(1i16));
|
||||
}
|
||||
*/
|
||||
|
@ -88,6 +88,7 @@ fn test_and() {
|
||||
assert_eq!(x.and(Some(2)), None);
|
||||
assert_eq!(x.and(None::<isize>), None);
|
||||
|
||||
/* FIXME(#110395)
|
||||
const FOO: Option<isize> = Some(1);
|
||||
const A: Option<isize> = FOO.and(Some(2));
|
||||
const B: Option<isize> = FOO.and(None);
|
||||
@ -99,6 +100,7 @@ fn test_and() {
|
||||
const D: Option<isize> = BAR.and(None);
|
||||
assert_eq!(C, None);
|
||||
assert_eq!(D, None);
|
||||
*/
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -119,6 +121,7 @@ fn test_and_then() {
|
||||
assert_eq!(x.and_then(plus_one), None);
|
||||
assert_eq!(x.and_then(none), None);
|
||||
|
||||
/* FIXME(#110395)
|
||||
const FOO: Option<isize> = Some(1);
|
||||
const A: Option<isize> = FOO.and_then(plus_one);
|
||||
const B: Option<isize> = FOO.and_then(none);
|
||||
@ -130,6 +133,7 @@ fn test_and_then() {
|
||||
const D: Option<isize> = BAR.and_then(none);
|
||||
assert_eq!(C, None);
|
||||
assert_eq!(D, None);
|
||||
*/
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -142,6 +146,7 @@ fn test_or() {
|
||||
assert_eq!(x.or(Some(2)), Some(2));
|
||||
assert_eq!(x.or(None), None);
|
||||
|
||||
/* FIXME(#110395)
|
||||
const FOO: Option<isize> = Some(1);
|
||||
const A: Option<isize> = FOO.or(Some(2));
|
||||
const B: Option<isize> = FOO.or(None);
|
||||
@ -153,6 +158,7 @@ fn test_or() {
|
||||
const D: Option<isize> = BAR.or(None);
|
||||
assert_eq!(C, Some(2));
|
||||
assert_eq!(D, None);
|
||||
*/
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -173,6 +179,7 @@ fn test_or_else() {
|
||||
assert_eq!(x.or_else(two), Some(2));
|
||||
assert_eq!(x.or_else(none), None);
|
||||
|
||||
/* FIXME(#110395)
|
||||
const FOO: Option<isize> = Some(1);
|
||||
const A: Option<isize> = FOO.or_else(two);
|
||||
const B: Option<isize> = FOO.or_else(none);
|
||||
@ -184,6 +191,7 @@ fn test_or_else() {
|
||||
const D: Option<isize> = BAR.or_else(none);
|
||||
assert_eq!(C, Some(2));
|
||||
assert_eq!(D, None);
|
||||
*/
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -215,10 +223,12 @@ fn test_unwrap_or() {
|
||||
let x: Option<isize> = None;
|
||||
assert_eq!(x.unwrap_or(2), 2);
|
||||
|
||||
/* FIXME(#110395)
|
||||
const A: isize = Some(1).unwrap_or(2);
|
||||
const B: isize = None.unwrap_or(2);
|
||||
assert_eq!(A, 1);
|
||||
assert_eq!(B, 2);
|
||||
*/
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -233,10 +243,12 @@ fn test_unwrap_or_else() {
|
||||
let x: Option<isize> = None;
|
||||
assert_eq!(x.unwrap_or_else(two), 2);
|
||||
|
||||
/* FIXME(#110395)
|
||||
const A: isize = Some(1).unwrap_or_else(two);
|
||||
const B: isize = None.unwrap_or_else(two);
|
||||
assert_eq!(A, 1);
|
||||
assert_eq!(B, 2);
|
||||
*/
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -439,14 +451,15 @@ fn option_const() {
|
||||
const OPTION: Option<usize> = Some(32);
|
||||
assert_eq!(OPTION, Some(32));
|
||||
|
||||
const OPTION_FROM: Option<usize> = Option::from(32);
|
||||
assert_eq!(OPTION_FROM, Some(32));
|
||||
// FIXME(#110395)
|
||||
// const OPTION_FROM: Option<usize> = Option::from(32);
|
||||
// assert_eq!(OPTION_FROM, Some(32));
|
||||
|
||||
const REF: Option<&usize> = OPTION.as_ref();
|
||||
assert_eq!(REF, Some(&32));
|
||||
|
||||
const REF_FROM: Option<&usize> = Option::from(&OPTION);
|
||||
assert_eq!(REF_FROM, Some(&32));
|
||||
// const REF_FROM: Option<&usize> = Option::from(&OPTION);
|
||||
// assert_eq!(REF_FROM, Some(&32));
|
||||
|
||||
const IS_SOME: bool = OPTION.is_some();
|
||||
assert!(IS_SOME);
|
||||
@ -474,7 +487,7 @@ const fn option_const_mut() {
|
||||
None => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
/* FIXME(const-hack)
|
||||
{
|
||||
let as_mut: Option<&mut usize> = Option::from(&mut option);
|
||||
match as_mut {
|
||||
@ -482,6 +495,7 @@ const fn option_const_mut() {
|
||||
None => unreachable!(),
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -425,14 +425,16 @@ fn duration_const() {
|
||||
const SECONDS_F32: f32 = Duration::SECOND.as_secs_f32();
|
||||
assert_eq!(SECONDS_F32, 1.0);
|
||||
|
||||
const FROM_SECONDS_F32: Duration = Duration::from_secs_f32(1.0);
|
||||
assert_eq!(FROM_SECONDS_F32, Duration::SECOND);
|
||||
// FIXME(#110395)
|
||||
// const FROM_SECONDS_F32: Duration = Duration::from_secs_f32(1.0);
|
||||
// assert_eq!(FROM_SECONDS_F32, Duration::SECOND);
|
||||
|
||||
const SECONDS_F64: f64 = Duration::SECOND.as_secs_f64();
|
||||
assert_eq!(SECONDS_F64, 1.0);
|
||||
|
||||
const FROM_SECONDS_F64: Duration = Duration::from_secs_f64(1.0);
|
||||
assert_eq!(FROM_SECONDS_F64, Duration::SECOND);
|
||||
// FIXME(#110395)
|
||||
// const FROM_SECONDS_F64: Duration = Duration::from_secs_f64(1.0);
|
||||
// assert_eq!(FROM_SECONDS_F64, Duration::SECOND);
|
||||
|
||||
const MILLIS: u128 = Duration::SECOND.as_millis();
|
||||
assert_eq!(MILLIS, 1_000);
|
||||
@ -463,6 +465,7 @@ fn duration_const() {
|
||||
const CHECKED_MUL: Option<Duration> = Duration::SECOND.checked_mul(1);
|
||||
assert_eq!(CHECKED_MUL, Some(Duration::SECOND));
|
||||
|
||||
/* FIXME(#110395)
|
||||
const MUL_F32: Duration = Duration::SECOND.mul_f32(1.0);
|
||||
assert_eq!(MUL_F32, Duration::SECOND);
|
||||
|
||||
@ -477,6 +480,7 @@ fn duration_const() {
|
||||
|
||||
const DIV_F64: Duration = Duration::SECOND.div_f64(1.0);
|
||||
assert_eq!(DIV_F64, Duration::SECOND);
|
||||
*/
|
||||
|
||||
const DIV_DURATION_F32: f32 = Duration::SECOND.div_duration_f32(Duration::SECOND);
|
||||
assert_eq!(DIV_DURATION_F32, 1.0);
|
||||
|
@ -3168,8 +3168,7 @@ impl DefaultHasher {
|
||||
}
|
||||
|
||||
#[stable(feature = "hashmap_default_hasher", since = "1.13.0")]
|
||||
#[rustc_const_unstable(feature = "const_hash", issue = "104061")]
|
||||
impl const Default for DefaultHasher {
|
||||
impl Default for DefaultHasher {
|
||||
/// Creates a new `DefaultHasher` using [`new`].
|
||||
/// See its documentation for more.
|
||||
///
|
||||
@ -3181,8 +3180,7 @@ impl const Default for DefaultHasher {
|
||||
}
|
||||
|
||||
#[stable(feature = "hashmap_default_hasher", since = "1.13.0")]
|
||||
#[rustc_const_unstable(feature = "const_hash", issue = "104061")]
|
||||
impl const Hasher for DefaultHasher {
|
||||
impl Hasher for DefaultHasher {
|
||||
// The underlying `SipHasher13` doesn't override the other
|
||||
// `write_*` methods, so it's ok not to forward them here.
|
||||
|
||||
|
@ -344,8 +344,7 @@ impl<T: RefUnwindSafe + UnwindSafe> RefUnwindSafe for OnceLock<T> {}
|
||||
impl<T: UnwindSafe> UnwindSafe for OnceLock<T> {}
|
||||
|
||||
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
|
||||
impl<T> const Default for OnceLock<T> {
|
||||
impl<T> Default for OnceLock<T> {
|
||||
/// Creates a new empty cell.
|
||||
///
|
||||
/// # Example
|
||||
|
@ -10,51 +10,9 @@
|
||||
+ scope 1 (inlined core::num::<impl u16>::unchecked_shl) { // at $DIR/unchecked_shifts.rs:11:7: 11:23
|
||||
+ debug self => _3; // in scope 1 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
+ debug rhs => _4; // in scope 1 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
+ let mut _5: u16; // in scope 1 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
+ let mut _6: std::option::Option<u16>; // in scope 1 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
+ let mut _7: std::result::Result<u16, std::num::TryFromIntError>; // in scope 1 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
+ let mut _5: u16; // in scope 1 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
+ let mut _6: (u32,); // in scope 1 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
+ scope 2 {
|
||||
+ scope 3 (inlined <u32 as TryInto<u16>>::try_into) { // at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
+ debug self => _4; // in scope 3 at $SRC_DIR/core/src/convert/mod.rs:LL:COL
|
||||
+ scope 4 (inlined convert::num::<impl TryFrom<u32> for u16>::try_from) { // at $SRC_DIR/core/src/convert/mod.rs:LL:COL
|
||||
+ debug u => _4; // in scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ let mut _8: bool; // in scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ let mut _9: u32; // in scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ let mut _10: u16; // in scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ }
|
||||
+ }
|
||||
+ scope 5 (inlined Result::<u16, TryFromIntError>::ok) { // at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
+ debug self => _7; // in scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
+ let mut _11: isize; // in scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
+ let _12: u16; // in scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
+ scope 6 {
|
||||
+ debug x => _12; // in scope 6 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
+ }
|
||||
+ scope 7 {
|
||||
+ scope 8 {
|
||||
+ debug x => const TryFromIntError(()); // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ scope 9 (inlined #[track_caller] Option::<u16>::unwrap_unchecked) { // at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
+ debug self => _6; // in scope 9 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
+ let mut _13: &std::option::Option<u16>; // in scope 9 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
+ let mut _14: isize; // in scope 9 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
+ scope 10 {
|
||||
+ debug val => _5; // in scope 10 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
+ }
|
||||
+ scope 11 {
|
||||
+ scope 13 (inlined unreachable_unchecked) { // at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
+ scope 14 {
|
||||
+ scope 15 (inlined unreachable_unchecked::runtime) { // at $SRC_DIR/core/src/intrinsics.rs:LL:COL
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ scope 12 (inlined Option::<u16>::is_some) { // at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
+ debug self => _13; // in scope 12 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
|
||||
@ -64,26 +22,23 @@
|
||||
StorageLive(_4); // scope 0 at $DIR/unchecked_shifts.rs:+1:21: +1:22
|
||||
_4 = _2; // scope 0 at $DIR/unchecked_shifts.rs:+1:21: +1:22
|
||||
- _0 = core::num::<impl u16>::unchecked_shl(move _3, move _4) -> bb1; // scope 0 at $DIR/unchecked_shifts.rs:+1:5: +1:23
|
||||
- // mir::Constant
|
||||
+ StorageLive(_5); // scope 2 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
+ StorageLive(_6); // scope 2 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
+ _6 = (_4,); // scope 2 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
+ _5 = core::num::<impl u16>::unchecked_shl::conv(move (_6.0: u32)) -> bb1; // scope 2 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
// mir::Constant
|
||||
- // + span: $DIR/unchecked_shifts.rs:11:7: 11:20
|
||||
- // + literal: Const { ty: unsafe fn(u16, u32) -> u16 {core::num::<impl u16>::unchecked_shl}, val: Value(<ZST>) }
|
||||
+ StorageLive(_5); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
+ StorageLive(_6); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
+ StorageLive(_7); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
+ StorageLive(_8); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ StorageLive(_9); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ _9 = const 65535_u32; // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ _8 = Gt(_4, move _9); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ StorageDead(_9); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ switchInt(move _8) -> [0: bb4, otherwise: bb3]; // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ // + span: $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
+ // + literal: Const { ty: fn(u32) -> u16 {core::num::<impl u16>::unchecked_shl::conv}, val: Value(<ZST>) }
|
||||
}
|
||||
|
||||
bb1: {
|
||||
+ StorageDead(_12); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
+ StorageDead(_7); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
+ StorageLive(_13); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
+ _14 = discriminant(_6); // scope 9 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
+ switchInt(move _14) -> [1: bb9, otherwise: bb7]; // scope 9 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
+ StorageDead(_6); // scope 2 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
+ _0 = unchecked_shl::<u16>(_3, move _5) -> [return: bb2, unwind unreachable]; // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
+ // mir::Constant
|
||||
+ // + span: $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
+ // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(u16, u16) -> u16 {unchecked_shl::<u16>}, val: Value(<ZST>) }
|
||||
+ }
|
||||
+
|
||||
+ bb2: {
|
||||
@ -91,54 +46,6 @@
|
||||
StorageDead(_4); // scope 0 at $DIR/unchecked_shifts.rs:+1:22: +1:23
|
||||
StorageDead(_3); // scope 0 at $DIR/unchecked_shifts.rs:+1:22: +1:23
|
||||
return; // scope 0 at $DIR/unchecked_shifts.rs:+2:2: +2:2
|
||||
+ }
|
||||
+
|
||||
+ bb3: {
|
||||
+ _7 = Result::<u16, TryFromIntError>::Err(const TryFromIntError(())); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ // mir::Constant
|
||||
+ // + span: no-location
|
||||
+ // + literal: Const { ty: TryFromIntError, val: Value(<ZST>) }
|
||||
+ goto -> bb5; // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ }
|
||||
+
|
||||
+ bb4: {
|
||||
+ StorageLive(_10); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ _10 = _4 as u16 (IntToInt); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ _7 = Result::<u16, TryFromIntError>::Ok(move _10); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ StorageDead(_10); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ goto -> bb5; // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ }
|
||||
+
|
||||
+ bb5: {
|
||||
+ StorageDead(_8); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ StorageLive(_12); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
+ _11 = discriminant(_7); // scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
+ switchInt(move _11) -> [0: bb8, 1: bb6, otherwise: bb7]; // scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
+ }
|
||||
+
|
||||
+ bb6: {
|
||||
+ _6 = Option::<u16>::None; // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
+ goto -> bb1; // scope 7 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
+ }
|
||||
+
|
||||
+ bb7: {
|
||||
+ unreachable; // scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
+ }
|
||||
+
|
||||
+ bb8: {
|
||||
+ _12 = move ((_7 as Ok).0: u16); // scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
+ _6 = Option::<u16>::Some(move _12); // scope 6 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
+ goto -> bb1; // scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
+ }
|
||||
+
|
||||
+ bb9: {
|
||||
+ _5 = move ((_6 as Some).0: u16); // scope 9 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
+ StorageDead(_13); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
+ StorageDead(_6); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
+ _0 = unchecked_shl::<u16>(_3, move _5) -> [return: bb2, unwind unreachable]; // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
+ // mir::Constant
|
||||
+ // + span: $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
+ // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(u16, u16) -> u16 {unchecked_shl::<u16>}, val: Value(<ZST>) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,124 +7,32 @@ fn unchecked_shl_unsigned_smaller(_1: u16, _2: u32) -> u16 {
|
||||
scope 1 (inlined core::num::<impl u16>::unchecked_shl) { // at $DIR/unchecked_shifts.rs:11:7: 11:23
|
||||
debug self => _1; // in scope 1 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
debug rhs => _2; // in scope 1 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
let mut _3: u16; // in scope 1 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
let mut _4: std::option::Option<u16>; // in scope 1 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
let mut _5: std::result::Result<u16, std::num::TryFromIntError>; // in scope 1 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
let mut _3: u16; // in scope 1 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
let mut _4: (u32,); // in scope 1 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
scope 2 {
|
||||
scope 3 (inlined <u32 as TryInto<u16>>::try_into) { // at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
debug self => _2; // in scope 3 at $SRC_DIR/core/src/convert/mod.rs:LL:COL
|
||||
scope 4 (inlined convert::num::<impl TryFrom<u32> for u16>::try_from) { // at $SRC_DIR/core/src/convert/mod.rs:LL:COL
|
||||
debug u => _2; // in scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
let mut _6: bool; // in scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
let mut _7: u32; // in scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
let mut _8: u16; // in scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
}
|
||||
}
|
||||
scope 5 (inlined Result::<u16, TryFromIntError>::ok) { // at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
debug self => _5; // in scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
let mut _9: isize; // in scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
let _10: u16; // in scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
scope 6 {
|
||||
debug x => _10; // in scope 6 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
}
|
||||
scope 7 {
|
||||
scope 8 {
|
||||
debug x => const TryFromIntError(()); // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
}
|
||||
}
|
||||
}
|
||||
scope 9 (inlined #[track_caller] Option::<u16>::unwrap_unchecked) { // at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
debug self => _4; // in scope 9 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
let mut _11: &std::option::Option<u16>; // in scope 9 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
let mut _12: isize; // in scope 9 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
scope 10 {
|
||||
debug val => _3; // in scope 10 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
}
|
||||
scope 11 {
|
||||
scope 13 (inlined unreachable_unchecked) { // at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
scope 14 {
|
||||
scope 15 (inlined unreachable_unchecked::runtime) { // at $SRC_DIR/core/src/intrinsics.rs:LL:COL
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
scope 12 (inlined Option::<u16>::is_some) { // at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
debug self => _11; // in scope 12 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bb0: {
|
||||
StorageLive(_3); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
StorageLive(_4); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
StorageLive(_5); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
StorageLive(_6); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
StorageLive(_7); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
_7 = const 65535_u32; // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
_6 = Gt(_2, move _7); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
StorageDead(_7); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
switchInt(move _6) -> [0: bb4, otherwise: bb3]; // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
StorageLive(_3); // scope 2 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
StorageLive(_4); // scope 2 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
_4 = (_2,); // scope 2 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
_3 = core::num::<impl u16>::unchecked_shl::conv(move (_4.0: u32)) -> bb1; // scope 2 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
// mir::Constant
|
||||
// + span: $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
// + literal: Const { ty: fn(u32) -> u16 {core::num::<impl u16>::unchecked_shl::conv}, val: Value(<ZST>) }
|
||||
}
|
||||
|
||||
bb1: {
|
||||
StorageDead(_10); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
StorageDead(_5); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
StorageLive(_11); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
_12 = discriminant(_4); // scope 9 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
switchInt(move _12) -> [1: bb9, otherwise: bb7]; // scope 9 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
StorageDead(_4); // scope 2 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
_0 = unchecked_shl::<u16>(_1, move _3) -> [return: bb2, unwind unreachable]; // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
// mir::Constant
|
||||
// + span: $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
// + literal: Const { ty: unsafe extern "rust-intrinsic" fn(u16, u16) -> u16 {unchecked_shl::<u16>}, val: Value(<ZST>) }
|
||||
}
|
||||
|
||||
bb2: {
|
||||
StorageDead(_3); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
return; // scope 0 at $DIR/unchecked_shifts.rs:+2:2: +2:2
|
||||
}
|
||||
|
||||
bb3: {
|
||||
_5 = Result::<u16, TryFromIntError>::Err(const TryFromIntError(())); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
// mir::Constant
|
||||
// + span: no-location
|
||||
// + literal: Const { ty: TryFromIntError, val: Value(<ZST>) }
|
||||
goto -> bb5; // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
}
|
||||
|
||||
bb4: {
|
||||
StorageLive(_8); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
_8 = _2 as u16 (IntToInt); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
_5 = Result::<u16, TryFromIntError>::Ok(move _8); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
StorageDead(_8); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
goto -> bb5; // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
}
|
||||
|
||||
bb5: {
|
||||
StorageDead(_6); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
StorageLive(_10); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
_9 = discriminant(_5); // scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
switchInt(move _9) -> [0: bb8, 1: bb6, otherwise: bb7]; // scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
}
|
||||
|
||||
bb6: {
|
||||
_4 = Option::<u16>::None; // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
goto -> bb1; // scope 7 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
}
|
||||
|
||||
bb7: {
|
||||
unreachable; // scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
}
|
||||
|
||||
bb8: {
|
||||
_10 = move ((_5 as Ok).0: u16); // scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
_4 = Option::<u16>::Some(move _10); // scope 6 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
goto -> bb1; // scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
}
|
||||
|
||||
bb9: {
|
||||
_3 = move ((_4 as Some).0: u16); // scope 9 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
StorageDead(_11); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
StorageDead(_4); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
_0 = unchecked_shl::<u16>(_1, move _3) -> [return: bb2, unwind unreachable]; // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
// mir::Constant
|
||||
// + span: $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
|
||||
// + literal: Const { ty: unsafe extern "rust-intrinsic" fn(u16, u16) -> u16 {unchecked_shl::<u16>}, val: Value(<ZST>) }
|
||||
}
|
||||
}
|
||||
|
@ -10,51 +10,9 @@
|
||||
+ scope 1 (inlined core::num::<impl i16>::unchecked_shr) { // at $DIR/unchecked_shifts.rs:17:7: 17:23
|
||||
+ debug self => _3; // in scope 1 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
+ debug rhs => _4; // in scope 1 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
+ let mut _5: i16; // in scope 1 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
+ let mut _6: std::option::Option<i16>; // in scope 1 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
+ let mut _7: std::result::Result<i16, std::num::TryFromIntError>; // in scope 1 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
+ let mut _5: i16; // in scope 1 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
+ let mut _6: (u32,); // in scope 1 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
+ scope 2 {
|
||||
+ scope 3 (inlined <u32 as TryInto<i16>>::try_into) { // at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
+ debug self => _4; // in scope 3 at $SRC_DIR/core/src/convert/mod.rs:LL:COL
|
||||
+ scope 4 (inlined convert::num::<impl TryFrom<u32> for i16>::try_from) { // at $SRC_DIR/core/src/convert/mod.rs:LL:COL
|
||||
+ debug u => _4; // in scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ let mut _8: bool; // in scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ let mut _9: u32; // in scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ let mut _10: i16; // in scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ }
|
||||
+ }
|
||||
+ scope 5 (inlined Result::<i16, TryFromIntError>::ok) { // at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
+ debug self => _7; // in scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
+ let mut _11: isize; // in scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
+ let _12: i16; // in scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
+ scope 6 {
|
||||
+ debug x => _12; // in scope 6 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
+ }
|
||||
+ scope 7 {
|
||||
+ scope 8 {
|
||||
+ debug x => const TryFromIntError(()); // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ scope 9 (inlined #[track_caller] Option::<i16>::unwrap_unchecked) { // at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
+ debug self => _6; // in scope 9 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
+ let mut _13: &std::option::Option<i16>; // in scope 9 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
+ let mut _14: isize; // in scope 9 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
+ scope 10 {
|
||||
+ debug val => _5; // in scope 10 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
+ }
|
||||
+ scope 11 {
|
||||
+ scope 13 (inlined unreachable_unchecked) { // at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
+ scope 14 {
|
||||
+ scope 15 (inlined unreachable_unchecked::runtime) { // at $SRC_DIR/core/src/intrinsics.rs:LL:COL
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ scope 12 (inlined Option::<i16>::is_some) { // at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
+ debug self => _13; // in scope 12 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
|
||||
@ -64,26 +22,23 @@
|
||||
StorageLive(_4); // scope 0 at $DIR/unchecked_shifts.rs:+1:21: +1:22
|
||||
_4 = _2; // scope 0 at $DIR/unchecked_shifts.rs:+1:21: +1:22
|
||||
- _0 = core::num::<impl i16>::unchecked_shr(move _3, move _4) -> bb1; // scope 0 at $DIR/unchecked_shifts.rs:+1:5: +1:23
|
||||
- // mir::Constant
|
||||
+ StorageLive(_5); // scope 2 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
+ StorageLive(_6); // scope 2 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
+ _6 = (_4,); // scope 2 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
+ _5 = core::num::<impl i16>::unchecked_shr::conv(move (_6.0: u32)) -> bb1; // scope 2 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
// mir::Constant
|
||||
- // + span: $DIR/unchecked_shifts.rs:17:7: 17:20
|
||||
- // + literal: Const { ty: unsafe fn(i16, u32) -> i16 {core::num::<impl i16>::unchecked_shr}, val: Value(<ZST>) }
|
||||
+ StorageLive(_5); // scope 2 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
+ StorageLive(_6); // scope 2 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
+ StorageLive(_7); // scope 2 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
+ StorageLive(_8); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ StorageLive(_9); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ _9 = const 32767_u32; // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ _8 = Gt(_4, move _9); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ StorageDead(_9); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ switchInt(move _8) -> [0: bb4, otherwise: bb3]; // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ // + span: $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
+ // + literal: Const { ty: fn(u32) -> i16 {core::num::<impl i16>::unchecked_shr::conv}, val: Value(<ZST>) }
|
||||
}
|
||||
|
||||
bb1: {
|
||||
+ StorageDead(_12); // scope 2 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
+ StorageDead(_7); // scope 2 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
+ StorageLive(_13); // scope 2 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
+ _14 = discriminant(_6); // scope 9 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
+ switchInt(move _14) -> [1: bb9, otherwise: bb7]; // scope 9 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
+ StorageDead(_6); // scope 2 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
+ _0 = unchecked_shr::<i16>(_3, move _5) -> [return: bb2, unwind unreachable]; // scope 2 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
+ // mir::Constant
|
||||
+ // + span: $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
+ // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(i16, i16) -> i16 {unchecked_shr::<i16>}, val: Value(<ZST>) }
|
||||
+ }
|
||||
+
|
||||
+ bb2: {
|
||||
@ -91,54 +46,6 @@
|
||||
StorageDead(_4); // scope 0 at $DIR/unchecked_shifts.rs:+1:22: +1:23
|
||||
StorageDead(_3); // scope 0 at $DIR/unchecked_shifts.rs:+1:22: +1:23
|
||||
return; // scope 0 at $DIR/unchecked_shifts.rs:+2:2: +2:2
|
||||
+ }
|
||||
+
|
||||
+ bb3: {
|
||||
+ _7 = Result::<i16, TryFromIntError>::Err(const TryFromIntError(())); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ // mir::Constant
|
||||
+ // + span: no-location
|
||||
+ // + literal: Const { ty: TryFromIntError, val: Value(<ZST>) }
|
||||
+ goto -> bb5; // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ }
|
||||
+
|
||||
+ bb4: {
|
||||
+ StorageLive(_10); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ _10 = _4 as i16 (IntToInt); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ _7 = Result::<i16, TryFromIntError>::Ok(move _10); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ StorageDead(_10); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ goto -> bb5; // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ }
|
||||
+
|
||||
+ bb5: {
|
||||
+ StorageDead(_8); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
+ StorageLive(_12); // scope 2 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
+ _11 = discriminant(_7); // scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
+ switchInt(move _11) -> [0: bb8, 1: bb6, otherwise: bb7]; // scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
+ }
|
||||
+
|
||||
+ bb6: {
|
||||
+ _6 = Option::<i16>::None; // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
+ goto -> bb1; // scope 7 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
+ }
|
||||
+
|
||||
+ bb7: {
|
||||
+ unreachable; // scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
+ }
|
||||
+
|
||||
+ bb8: {
|
||||
+ _12 = move ((_7 as Ok).0: i16); // scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
+ _6 = Option::<i16>::Some(move _12); // scope 6 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
+ goto -> bb1; // scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
+ }
|
||||
+
|
||||
+ bb9: {
|
||||
+ _5 = move ((_6 as Some).0: i16); // scope 9 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
+ StorageDead(_13); // scope 2 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
+ StorageDead(_6); // scope 2 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
+ _0 = unchecked_shr::<i16>(_3, move _5) -> [return: bb2, unwind unreachable]; // scope 2 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
+ // mir::Constant
|
||||
+ // + span: $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
+ // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(i16, i16) -> i16 {unchecked_shr::<i16>}, val: Value(<ZST>) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,124 +7,32 @@ fn unchecked_shr_signed_smaller(_1: i16, _2: u32) -> i16 {
|
||||
scope 1 (inlined core::num::<impl i16>::unchecked_shr) { // at $DIR/unchecked_shifts.rs:17:7: 17:23
|
||||
debug self => _1; // in scope 1 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
debug rhs => _2; // in scope 1 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
let mut _3: i16; // in scope 1 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
let mut _4: std::option::Option<i16>; // in scope 1 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
let mut _5: std::result::Result<i16, std::num::TryFromIntError>; // in scope 1 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
let mut _3: i16; // in scope 1 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
let mut _4: (u32,); // in scope 1 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
scope 2 {
|
||||
scope 3 (inlined <u32 as TryInto<i16>>::try_into) { // at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
debug self => _2; // in scope 3 at $SRC_DIR/core/src/convert/mod.rs:LL:COL
|
||||
scope 4 (inlined convert::num::<impl TryFrom<u32> for i16>::try_from) { // at $SRC_DIR/core/src/convert/mod.rs:LL:COL
|
||||
debug u => _2; // in scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
let mut _6: bool; // in scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
let mut _7: u32; // in scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
let mut _8: i16; // in scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
}
|
||||
}
|
||||
scope 5 (inlined Result::<i16, TryFromIntError>::ok) { // at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
debug self => _5; // in scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
let mut _9: isize; // in scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
let _10: i16; // in scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
scope 6 {
|
||||
debug x => _10; // in scope 6 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
}
|
||||
scope 7 {
|
||||
scope 8 {
|
||||
debug x => const TryFromIntError(()); // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
}
|
||||
}
|
||||
}
|
||||
scope 9 (inlined #[track_caller] Option::<i16>::unwrap_unchecked) { // at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
debug self => _4; // in scope 9 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
let mut _11: &std::option::Option<i16>; // in scope 9 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
let mut _12: isize; // in scope 9 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
scope 10 {
|
||||
debug val => _3; // in scope 10 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
}
|
||||
scope 11 {
|
||||
scope 13 (inlined unreachable_unchecked) { // at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
scope 14 {
|
||||
scope 15 (inlined unreachable_unchecked::runtime) { // at $SRC_DIR/core/src/intrinsics.rs:LL:COL
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
scope 12 (inlined Option::<i16>::is_some) { // at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
debug self => _11; // in scope 12 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bb0: {
|
||||
StorageLive(_3); // scope 2 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
StorageLive(_4); // scope 2 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
StorageLive(_5); // scope 2 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
StorageLive(_6); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
StorageLive(_7); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
_7 = const 32767_u32; // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
_6 = Gt(_2, move _7); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
StorageDead(_7); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
switchInt(move _6) -> [0: bb4, otherwise: bb3]; // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
StorageLive(_3); // scope 2 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
StorageLive(_4); // scope 2 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
_4 = (_2,); // scope 2 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
_3 = core::num::<impl i16>::unchecked_shr::conv(move (_4.0: u32)) -> bb1; // scope 2 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
// mir::Constant
|
||||
// + span: $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
// + literal: Const { ty: fn(u32) -> i16 {core::num::<impl i16>::unchecked_shr::conv}, val: Value(<ZST>) }
|
||||
}
|
||||
|
||||
bb1: {
|
||||
StorageDead(_10); // scope 2 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
StorageDead(_5); // scope 2 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
StorageLive(_11); // scope 2 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
_12 = discriminant(_4); // scope 9 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
switchInt(move _12) -> [1: bb9, otherwise: bb7]; // scope 9 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
StorageDead(_4); // scope 2 at $SRC_DIR/core/src/num/mod.rs:LL:COL
|
||||
_0 = unchecked_shr::<i16>(_1, move _3) -> [return: bb2, unwind unreachable]; // scope 2 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
// mir::Constant
|
||||
// + span: $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
// + literal: Const { ty: unsafe extern "rust-intrinsic" fn(i16, i16) -> i16 {unchecked_shr::<i16>}, val: Value(<ZST>) }
|
||||
}
|
||||
|
||||
bb2: {
|
||||
StorageDead(_3); // scope 2 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
return; // scope 0 at $DIR/unchecked_shifts.rs:+2:2: +2:2
|
||||
}
|
||||
|
||||
bb3: {
|
||||
_5 = Result::<i16, TryFromIntError>::Err(const TryFromIntError(())); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
// mir::Constant
|
||||
// + span: no-location
|
||||
// + literal: Const { ty: TryFromIntError, val: Value(<ZST>) }
|
||||
goto -> bb5; // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
}
|
||||
|
||||
bb4: {
|
||||
StorageLive(_8); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
_8 = _2 as i16 (IntToInt); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
_5 = Result::<i16, TryFromIntError>::Ok(move _8); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
StorageDead(_8); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
goto -> bb5; // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
}
|
||||
|
||||
bb5: {
|
||||
StorageDead(_6); // scope 4 at $SRC_DIR/core/src/convert/num.rs:LL:COL
|
||||
StorageLive(_10); // scope 2 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
_9 = discriminant(_5); // scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
switchInt(move _9) -> [0: bb8, 1: bb6, otherwise: bb7]; // scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
}
|
||||
|
||||
bb6: {
|
||||
_4 = Option::<i16>::None; // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
goto -> bb1; // scope 7 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
}
|
||||
|
||||
bb7: {
|
||||
unreachable; // scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
}
|
||||
|
||||
bb8: {
|
||||
_10 = move ((_5 as Ok).0: i16); // scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
_4 = Option::<i16>::Some(move _10); // scope 6 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
goto -> bb1; // scope 5 at $SRC_DIR/core/src/result.rs:LL:COL
|
||||
}
|
||||
|
||||
bb9: {
|
||||
_3 = move ((_4 as Some).0: i16); // scope 9 at $SRC_DIR/core/src/option.rs:LL:COL
|
||||
StorageDead(_11); // scope 2 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
StorageDead(_4); // scope 2 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
_0 = unchecked_shr::<i16>(_1, move _3) -> [return: bb2, unwind unreachable]; // scope 2 at $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
// mir::Constant
|
||||
// + span: $SRC_DIR/core/src/num/int_macros.rs:LL:COL
|
||||
// + literal: Const { ty: unsafe extern "rust-intrinsic" fn(i16, i16) -> i16 {unchecked_shr::<i16>}, val: Value(<ZST>) }
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,6 @@
|
||||
// FIXME #110395
|
||||
// ignore-llvm-cov-show-diffs
|
||||
|
||||
#![allow(unused_assignments, unused_variables)]
|
||||
// compile-flags: -C opt-level=3 # validates coverage now works with optimizations
|
||||
extern crate used_crate;
|
||||
|
@ -1,3 +1,6 @@
|
||||
// FIXME #110395
|
||||
// ignore-llvm-cov-show-diffs
|
||||
|
||||
#![allow(unused_assignments, unused_variables)]
|
||||
|
||||
// compile-flags: -C opt-level=3 # validates coverage now works with optimizations
|
||||
|
@ -29,7 +29,7 @@ pub trait Stage {
|
||||
//
|
||||
// @has - '//*[@id="associatedconstant.ARRAY1"]' \
|
||||
// 'const ARRAY1: [u8; { _ }]'
|
||||
const ARRAY1: [u8; Struct::new(/* ... */) + Self::ABSTRACT * 1_000];
|
||||
const ARRAY1: [u8; Struct::new(/* ... */).do_something(Self::ABSTRACT * 1_000)];
|
||||
|
||||
// @has - '//*[@id="associatedconstant.VERBOSE"]' \
|
||||
// 'const VERBOSE: [u16; { _ }]'
|
||||
@ -73,10 +73,14 @@ pub struct Struct { private: () }
|
||||
|
||||
impl Struct {
|
||||
const fn new() -> Self { Self { private: () } }
|
||||
const fn do_something(self, x: usize) -> usize {
|
||||
x
|
||||
}
|
||||
}
|
||||
|
||||
/* FIXME(const-trait): readd this
|
||||
impl const std::ops::Add<usize> for Struct {
|
||||
type Output = usize;
|
||||
|
||||
fn add(self, _: usize) -> usize { 0 }
|
||||
}
|
||||
*/
|
||||
|
@ -13,57 +13,57 @@ use std::marker::Destruct;
|
||||
pub struct S<T>(T);
|
||||
|
||||
// @!has foo/trait.Tr.html '//pre[@class="rust item-decl"]/code/a[@class="trait"]' '~const'
|
||||
// @has - '//pre[@class="rust item-decl"]/code/a[@class="trait"]' 'Clone'
|
||||
// @has - '//pre[@class="rust item-decl"]/code/a[@class="trait"]' 'Fn'
|
||||
// @!has - '//pre[@class="rust item-decl"]/code/span[@class="where"]' '~const'
|
||||
// @has - '//pre[@class="rust item-decl"]/code/span[@class="where"]' ': Clone'
|
||||
// @has - '//pre[@class="rust item-decl"]/code/span[@class="where"]' ': Fn'
|
||||
#[const_trait]
|
||||
pub trait Tr<T> {
|
||||
// @!has - '//section[@id="method.a"]/h4[@class="code-header"]' '~const'
|
||||
// @has - '//section[@id="method.a"]/h4[@class="code-header"]/a[@class="trait"]' 'Clone'
|
||||
// @has - '//section[@id="method.a"]/h4[@class="code-header"]/a[@class="trait"]' 'Fn'
|
||||
// @!has - '//section[@id="method.a"]/h4[@class="code-header"]/span[@class="where"]' '~const'
|
||||
// @has - '//section[@id="method.a"]/h4[@class="code-header"]/span[@class="where fmt-newline"]' ': Clone'
|
||||
fn a<A: ~const Clone + ~const Destruct>()
|
||||
// @has - '//section[@id="method.a"]/h4[@class="code-header"]/span[@class="where fmt-newline"]' ': Fn'
|
||||
fn a<A: ~const Fn() + ~const Destruct>()
|
||||
where
|
||||
Option<A>: ~const Clone + ~const Destruct,
|
||||
Option<A>: ~const Fn() + ~const Destruct,
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// @has - '//section[@id="impl-Tr%3CT%3E-for-T"]' ''
|
||||
// @!has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header"]' '~const'
|
||||
// @has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header"]/a[@class="trait"]' 'Clone'
|
||||
// @has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header"]/a[@class="trait"]' 'Fn'
|
||||
// @!has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header"]/span[@class="where"]' '~const'
|
||||
// @has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header"]/span[@class="where fmt-newline"]' ': Clone'
|
||||
impl<T: ~const Clone + ~const Destruct> const Tr<T> for T
|
||||
// @has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header"]/span[@class="where fmt-newline"]' ': Fn'
|
||||
impl<T: ~const Fn() + ~const Destruct> const Tr<T> for T
|
||||
where
|
||||
Option<T>: ~const Clone + ~const Destruct,
|
||||
Option<T>: ~const Fn() + ~const Destruct,
|
||||
{
|
||||
fn a<A: ~const Clone + ~const Destruct>()
|
||||
fn a<A: ~const Fn() + ~const Destruct>()
|
||||
where
|
||||
Option<A>: ~const Clone + ~const Destruct,
|
||||
Option<A>: ~const Fn() + ~const Destruct,
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// @!has foo/fn.foo.html '//pre[@class="rust item-decl"]/code/a[@class="trait"]' '~const'
|
||||
// @has - '//pre[@class="rust item-decl"]/code/a[@class="trait"]' 'Clone'
|
||||
// @has - '//pre[@class="rust item-decl"]/code/a[@class="trait"]' 'Fn'
|
||||
// @!has - '//pre[@class="rust item-decl"]/code/span[@class="where fmt-newline"]' '~const'
|
||||
// @has - '//pre[@class="rust item-decl"]/code/span[@class="where fmt-newline"]' ': Clone'
|
||||
pub const fn foo<F: ~const Clone + ~const Destruct>()
|
||||
// @has - '//pre[@class="rust item-decl"]/code/span[@class="where fmt-newline"]' ': Fn'
|
||||
pub const fn foo<F: ~const Fn() + ~const Destruct>()
|
||||
where
|
||||
Option<F>: ~const Clone + ~const Destruct,
|
||||
Option<F>: ~const Fn() + ~const Destruct,
|
||||
{
|
||||
F::a()
|
||||
}
|
||||
|
||||
impl<T> S<T> {
|
||||
// @!has foo/struct.S.html '//section[@id="method.foo"]/h4[@class="code-header"]' '~const'
|
||||
// @has - '//section[@id="method.foo"]/h4[@class="code-header"]/a[@class="trait"]' 'Clone'
|
||||
// @has - '//section[@id="method.foo"]/h4[@class="code-header"]/a[@class="trait"]' 'Fn'
|
||||
// @!has - '//section[@id="method.foo"]/h4[@class="code-header"]/span[@class="where"]' '~const'
|
||||
// @has - '//section[@id="method.foo"]/h4[@class="code-header"]/span[@class="where fmt-newline"]' ': Clone'
|
||||
pub const fn foo<B, C: ~const Clone + ~const Destruct>()
|
||||
// @has - '//section[@id="method.foo"]/h4[@class="code-header"]/span[@class="where fmt-newline"]' ': Fn'
|
||||
pub const fn foo<B, C: ~const Fn() + ~const Destruct>()
|
||||
where
|
||||
B: ~const Clone + ~const Destruct,
|
||||
B: ~const Fn() + ~const Destruct,
|
||||
{
|
||||
B::a()
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
// known-bug: #110395
|
||||
|
||||
#![feature(generic_const_exprs, adt_const_params, const_trait_impl)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
@ -26,7 +28,6 @@ struct Evaluatable2<const N: usize>;
|
||||
|
||||
fn foo2<const N: usize>(a: Evaluatable2<{ N + N }>) {
|
||||
bar2::<{ std::ops::Add::add(N, N) }>();
|
||||
//~^ error: unconstrained generic constant
|
||||
// FIXME(generic_const_exprs) make this not an error
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
error: unconstrained generic constant
|
||||
--> $DIR/unify-op-with-fn-call.rs:28:12
|
||||
error: const `impl` for trait `Add` which is not marked with `#[const_trait]`
|
||||
--> $DIR/unify-op-with-fn-call.rs:10:12
|
||||
|
|
||||
LL | bar2::<{ std::ops::Add::add(N, N) }>();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | impl const std::ops::Add for Foo {
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= help: try adding a `where` bound using this expression: `where [(); { std::ops::Add::add(N, N) }]:`
|
||||
= note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
|
||||
= note: adding a non-const method body in the future would be a breaking change
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -4,13 +4,13 @@ error[E0308]: mismatched types
|
||||
LL | = [0; (i8::MAX + 1u8) as usize];
|
||||
| ^^^ expected `i8`, found `u8`
|
||||
|
||||
error[E0277]: cannot add `u8` to `i8` in const contexts
|
||||
error[E0277]: cannot add `u8` to `i8`
|
||||
--> $DIR/const-eval-overflow-3b.rs:16:20
|
||||
|
|
||||
LL | = [0; (i8::MAX + 1u8) as usize];
|
||||
| ^ no implementation for `i8 + u8`
|
||||
|
|
||||
= help: the trait `~const Add<u8>` is not implemented for `i8`
|
||||
= help: the trait `Add<u8>` is not implemented for `i8`
|
||||
= help: the following other types implement trait `Add<Rhs>`:
|
||||
<&'a i8 as Add<i8>>
|
||||
<&i8 as Add<&i8>>
|
||||
|
@ -4,13 +4,13 @@ error[E0308]: mismatched types
|
||||
LL | : [u32; (i8::MAX as i8 + 1u8) as usize]
|
||||
| ^^^ expected `i8`, found `u8`
|
||||
|
||||
error[E0277]: cannot add `u8` to `i8` in const contexts
|
||||
error[E0277]: cannot add `u8` to `i8`
|
||||
--> $DIR/const-eval-overflow-4b.rs:9:28
|
||||
|
|
||||
LL | : [u32; (i8::MAX as i8 + 1u8) as usize]
|
||||
| ^ no implementation for `i8 + u8`
|
||||
|
|
||||
= help: the trait `~const Add<u8>` is not implemented for `i8`
|
||||
= help: the trait `Add<u8>` is not implemented for `i8`
|
||||
= help: the following other types implement trait `Add<Rhs>`:
|
||||
<&'a i8 as Add<i8>>
|
||||
<&i8 as Add<&i8>>
|
||||
|
@ -1,6 +1,6 @@
|
||||
fn main() {}
|
||||
|
||||
// unconst and bad, will thus error in miri
|
||||
const X: bool = unsafe { &1 as *const i32 == &2 as *const i32 }; //~ ERROR can't compare
|
||||
const X: bool = unsafe { &1 as *const i32 == &2 as *const i32 }; //~ ERROR pointers cannot
|
||||
// unconst and bad, will thus error in miri
|
||||
const X2: bool = unsafe { 42 as *const i32 == 43 as *const i32 }; //~ ERROR can't compare
|
||||
const X2: bool = unsafe { 42 as *const i32 == 43 as *const i32 }; //~ ERROR pointers cannot
|
||||
|
@ -1,29 +1,18 @@
|
||||
error[E0277]: can't compare `*const i32` with `_` in const contexts
|
||||
--> $DIR/const_raw_ptr_ops.rs:4:43
|
||||
error: pointers cannot be reliably compared during const eval
|
||||
--> $DIR/const_raw_ptr_ops.rs:4:26
|
||||
|
|
||||
LL | const X: bool = unsafe { &1 as *const i32 == &2 as *const i32 };
|
||||
| ^^ no implementation for `*const i32 == _`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: the trait `~const PartialEq<_>` is not implemented for `*const i32`
|
||||
note: the trait `PartialEq<_>` is implemented for `*const i32`, but that implementation is not `const`
|
||||
--> $DIR/const_raw_ptr_ops.rs:4:43
|
||||
|
|
||||
LL | const X: bool = unsafe { &1 as *const i32 == &2 as *const i32 };
|
||||
| ^^
|
||||
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information
|
||||
|
||||
error[E0277]: can't compare `*const i32` with `_` in const contexts
|
||||
--> $DIR/const_raw_ptr_ops.rs:6:44
|
||||
error: pointers cannot be reliably compared during const eval
|
||||
--> $DIR/const_raw_ptr_ops.rs:6:27
|
||||
|
|
||||
LL | const X2: bool = unsafe { 42 as *const i32 == 43 as *const i32 };
|
||||
| ^^ no implementation for `*const i32 == _`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: the trait `~const PartialEq<_>` is not implemented for `*const i32`
|
||||
note: the trait `PartialEq<_>` is implemented for `*const i32`, but that implementation is not `const`
|
||||
--> $DIR/const_raw_ptr_ops.rs:6:44
|
||||
|
|
||||
LL | const X2: bool = unsafe { 42 as *const i32 == 43 as *const i32 };
|
||||
| ^^
|
||||
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
@ -1,3 +1,5 @@
|
||||
// known-bug: #110395
|
||||
|
||||
#![feature(const_slice_index)]
|
||||
|
||||
const A: [(); 5] = [(), (), (), (), ()];
|
||||
|
@ -1,18 +1,11 @@
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $SRC_DIR/core/src/slice/index.rs:LL:COL
|
||||
|
|
||||
= note: overflow executing `unchecked_sub`
|
||||
|
|
||||
note: inside `<std::ops::Range<usize> as SliceIndex<[()]>>::get_unchecked`
|
||||
--> $SRC_DIR/core/src/slice/index.rs:LL:COL
|
||||
note: inside `core::slice::<impl [()]>::get_unchecked::<std::ops::Range<usize>>`
|
||||
--> $SRC_DIR/core/src/slice/mod.rs:LL:COL
|
||||
note: inside `B`
|
||||
--> $DIR/ub-slice-get-unchecked.rs:7:27
|
||||
error[E0015]: cannot call non-const fn `core::slice::<impl [()]>::get_unchecked::<std::ops::Range<usize>>` in constants
|
||||
--> $DIR/ub-slice-get-unchecked.rs:9:29
|
||||
|
|
||||
LL | const B: &[()] = unsafe { A.get_unchecked(3..1) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0080`.
|
||||
For more information about this error, try `rustc --explain E0015`.
|
||||
|
@ -8,11 +8,33 @@
|
||||
// Don't promote
|
||||
const fn nop<T>(x: T) -> T { x }
|
||||
|
||||
// FIXME(const-hack): replace with PartialEq
|
||||
#[const_trait]
|
||||
trait MyEq<T> {
|
||||
fn eq(self, b: T) -> bool;
|
||||
}
|
||||
|
||||
impl const MyEq<bool> for bool {
|
||||
fn eq(self, b: bool) -> bool {
|
||||
self == b
|
||||
}
|
||||
}
|
||||
|
||||
impl const MyEq<NonDet> for bool {
|
||||
fn eq(self, _: NonDet) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
const fn eq<A: ~const MyEq<B>, B>(x: A, y: B) -> bool {
|
||||
x.eq(y)
|
||||
}
|
||||
|
||||
macro_rules! const_assert {
|
||||
($a:expr, $b:expr) => {
|
||||
{
|
||||
const _: () = assert!($a == $b);
|
||||
assert_eq!(nop($a), nop($b));
|
||||
const _: () = assert!(eq($a, $b));
|
||||
assert!(eq(nop($a), nop($b)));
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -47,15 +69,6 @@ macro_rules! suite_inner {
|
||||
#[derive(Debug)]
|
||||
struct NonDet;
|
||||
|
||||
impl const PartialEq<NonDet> for bool {
|
||||
fn eq(&self, _: &NonDet) -> bool {
|
||||
true
|
||||
}
|
||||
fn ne(&self, _: &NonDet) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
// The result of the `is_sign` methods are not checked for correctness, since LLVM does not
|
||||
// guarantee anything about the signedness of NaNs. See
|
||||
// https://github.com/rust-lang/rust/issues/55131.
|
||||
|
@ -7,7 +7,6 @@ const fn f(x: usize) -> usize {
|
||||
//~| ERROR `for` is not allowed in a `const fn`
|
||||
//~| ERROR mutable references are not allowed in constant functions
|
||||
//~| ERROR cannot call non-const fn
|
||||
//~| ERROR the trait bound
|
||||
sum += i;
|
||||
}
|
||||
sum
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user