diff options
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/future/future.rs | 25 | ||||
| -rw-r--r-- | src/libcore/future/mod.rs | 3 | ||||
| -rw-r--r-- | src/libcore/intrinsics.rs | 12 | ||||
| -rw-r--r-- | src/libcore/macros/mod.rs | 4 | ||||
| -rw-r--r-- | src/libcore/marker.rs | 2 | ||||
| -rw-r--r-- | src/libcore/num/f32.rs | 2 | ||||
| -rw-r--r-- | src/libcore/num/f64.rs | 2 | ||||
| -rw-r--r-- | src/libcore/ops/function.rs | 8 | ||||
| -rw-r--r-- | src/libcore/result.rs | 2 | ||||
| -rw-r--r-- | src/libcore/slice/mod.rs | 47 |
10 files changed, 68 insertions, 39 deletions
diff --git a/src/libcore/future/future.rs b/src/libcore/future/future.rs index f14ed38b9b0..dcb819f9381 100644 --- a/src/libcore/future/future.rs +++ b/src/libcore/future/future.rs @@ -99,6 +99,21 @@ pub trait Future { fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>; } +/// Conversion into a `Future`. +#[unstable(feature = "into_future", issue = "67644")] +pub trait IntoFuture { + /// The output that the future will produce on completion. + #[unstable(feature = "into_future", issue = "67644")] + type Output; + /// Which kind of future are we turning this into? + #[unstable(feature = "into_future", issue = "67644")] + type Future: Future<Output = Self::Output>; + + /// Creates a future from a value. + #[unstable(feature = "into_future", issue = "67644")] + fn into_future(self) -> Self::Future; +} + #[stable(feature = "futures_api", since = "1.36.0")] impl<F: ?Sized + Future + Unpin> Future for &mut F { type Output = F::Output; @@ -119,3 +134,13 @@ where Pin::get_mut(self).as_mut().poll(cx) } } + +#[unstable(feature = "into_future", issue = "67644")] +impl<F: Future> IntoFuture for F { + type Output = F::Output; + type Future = F; + + fn into_future(self) -> Self::Future { + self + } +} diff --git a/src/libcore/future/mod.rs b/src/libcore/future/mod.rs index 89ea4713cfd..aecd57b9ce7 100644 --- a/src/libcore/future/mod.rs +++ b/src/libcore/future/mod.rs @@ -5,3 +5,6 @@ mod future; #[stable(feature = "futures_api", since = "1.36.0")] pub use self::future::Future; + +#[unstable(feature = "into_future", issue = "67644")] +pub use self::future::IntoFuture; diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 502090731f4..416c73f50bd 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -697,7 +697,7 @@ extern "rust-intrinsic" { #[rustc_const_stable(feature = "const_min_align_of", since = "1.40.0")] pub fn min_align_of<T>() -> usize; - #[rustc_const_unstable(feature = "const_pref_align_of", issue = "0")] + #[rustc_const_unstable(feature = "const_pref_align_of", issue = "none")] pub fn pref_align_of<T>() -> usize; /// The size of the referenced value in bytes. @@ -708,13 +708,13 @@ extern "rust-intrinsic" { pub fn min_align_of_val<T: ?Sized>(_: &T) -> usize; /// Gets a static string slice containing the name of a type. - #[rustc_const_unstable(feature = "const_type_name", issue = "0")] + #[rustc_const_unstable(feature = "const_type_name", issue = "none")] pub fn type_name<T: ?Sized>() -> &'static str; /// Gets an identifier which is globally unique to the specified type. This /// function will return the same value for a type regardless of whichever /// crate it is invoked in. - #[rustc_const_unstable(feature = "const_type_id", issue = "0")] + #[rustc_const_unstable(feature = "const_type_id", issue = "none")] pub fn type_id<T: ?Sized + 'static>() -> u64; /// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited: @@ -1222,7 +1222,7 @@ extern "rust-intrinsic" { /// let num_leading = unsafe { ctlz_nonzero(x) }; /// assert_eq!(num_leading, 3); /// ``` - #[rustc_const_unstable(feature = "constctlz", issue = "0")] + #[rustc_const_unstable(feature = "constctlz", issue = "none")] pub fn ctlz_nonzero<T>(x: T) -> T; /// Returns the number of trailing unset bits (zeroes) in an integer type `T`. @@ -1267,7 +1267,7 @@ extern "rust-intrinsic" { /// let num_trailing = unsafe { cttz_nonzero(x) }; /// assert_eq!(num_trailing, 3); /// ``` - #[rustc_const_unstable(feature = "const_cttz", issue = "0")] + #[rustc_const_unstable(feature = "const_cttz", issue = "none")] pub fn cttz_nonzero<T>(x: T) -> T; /// Reverses the bytes in an integer type `T`. @@ -1396,7 +1396,7 @@ extern "rust-intrinsic" { pub fn nontemporal_store<T>(ptr: *mut T, val: T); /// See documentation of `<*const T>::offset_from` for details. - #[rustc_const_unstable(feature = "const_ptr_offset_from", issue = "0")] + #[rustc_const_unstable(feature = "const_ptr_offset_from", issue = "none")] pub fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize; /// Internal hook used by Miri to implement unwinding. diff --git a/src/libcore/macros/mod.rs b/src/libcore/macros/mod.rs index e66d9c5bd2e..9a52823a454 100644 --- a/src/libcore/macros/mod.rs +++ b/src/libcore/macros/mod.rs @@ -252,8 +252,6 @@ macro_rules! debug_assert_ne { /// # Examples /// /// ``` -/// #![feature(matches_macro)] -/// /// let foo = 'f'; /// assert!(matches!(foo, 'A'..='Z' | 'a'..='z')); /// @@ -261,7 +259,7 @@ macro_rules! debug_assert_ne { /// assert!(matches!(bar, Some(x) if x > 2)); /// ``` #[macro_export] -#[unstable(feature = "matches_macro", issue = "65721")] +#[stable(feature = "matches_macro", since = "1.42.0")] macro_rules! matches { ($expression:expr, $( $pattern:pat )|+ $( if $guard: expr )?) => { match $expression { diff --git a/src/libcore/marker.rs b/src/libcore/marker.rs index 978d6221564..3b98bc1c272 100644 --- a/src/libcore/marker.rs +++ b/src/libcore/marker.rs @@ -142,7 +142,7 @@ pub trait Unsize<T: ?Sized> { /// In either of the two scenarios above, we reject usage of such a constant in /// a pattern match. /// -/// See also the [structural match RFC][RFC1445], and [issue 63438][] which +/// See also the [structural match RFC][RFC1445], and [issue 63438] which /// motivated migrating from attribute-based design to this trait. /// /// [RFC1445]: https://github.com/rust-lang/rfcs/blob/master/text/1445-restrict-constants-in-patterns.md diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index fd7b7cf0b34..f1f1bb13f0f 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -226,7 +226,7 @@ impl f32 { } /// Returns `true` if the number is neither zero, infinite, - /// [subnormal][subnormal], or `NaN`. + /// [subnormal], or `NaN`. /// /// ``` /// use std::f32; diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index 540c6a529d7..5f9dc541b7d 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -226,7 +226,7 @@ impl f64 { } /// Returns `true` if the number is neither zero, infinite, - /// [subnormal][subnormal], or `NaN`. + /// [subnormal], or `NaN`. /// /// ``` /// use std::f64; diff --git a/src/libcore/ops/function.rs b/src/libcore/ops/function.rs index 505a65cee3d..04c7789fa4f 100644 --- a/src/libcore/ops/function.rs +++ b/src/libcore/ops/function.rs @@ -2,12 +2,12 @@ /// /// Instances of `Fn` can be called repeatedly without mutating state. /// -/// *This trait (`Fn`) is not to be confused with [function pointers][] +/// *This trait (`Fn`) is not to be confused with [function pointers] /// (`fn`).* /// /// `Fn` is implemented automatically by closures which only take immutable /// references to captured variables or don't capture anything at all, as well -/// as (safe) [function pointers][] (with some caveats, see their documentation +/// as (safe) [function pointers] (with some caveats, see their documentation /// for more details). Additionally, for any type `F` that implements `Fn`, `&F` /// implements `Fn`, too. /// @@ -78,7 +78,7 @@ pub trait Fn<Args>: FnMut<Args> { /// /// `FnMut` is implemented automatically by closures which take mutable /// references to captured variables, as well as all types that implement -/// [`Fn`], e.g., (safe) [function pointers][] (since `FnMut` is a supertrait of +/// [`Fn`], e.g., (safe) [function pointers] (since `FnMut` is a supertrait of /// [`Fn`]). Additionally, for any type `F` that implements `FnMut`, `&mut F` /// implements `FnMut`, too. /// @@ -162,7 +162,7 @@ pub trait FnMut<Args>: FnOnce<Args> { /// /// `FnOnce` is implemented automatically by closure that might consume captured /// variables, as well as all types that implement [`FnMut`], e.g., (safe) -/// [function pointers][] (since `FnOnce` is a supertrait of [`FnMut`]). +/// [function pointers] (since `FnOnce` is a supertrait of [`FnMut`]). /// /// Since both [`Fn`] and [`FnMut`] are subtraits of `FnOnce`, any instance of /// [`Fn`] or [`FnMut`] can be used where a `FnOnce` is expected. diff --git a/src/libcore/result.rs b/src/libcore/result.rs index ce4c8995a3c..5628658c5bd 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -1370,7 +1370,7 @@ unsafe impl<A> TrustedLen for IterMut<'_, A> {} /// The iterator yields one value if the result is [`Ok`], otherwise none. /// /// This struct is created by the [`into_iter`] method on -/// [`Result`][`Result`] (provided by the [`IntoIterator`] trait). +/// [`Result`] (provided by the [`IntoIterator`] trait). /// /// [`Ok`]: enum.Result.html#variant.Ok /// [`Result`]: enum.Result.html diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 5ddf5d48965..9b4d2015732 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -34,7 +34,7 @@ use crate::mem; use crate::ops::{self, FnMut, Range}; use crate::option::Option; use crate::option::Option::{None, Some}; -use crate::ptr; +use crate::ptr::{self, NonNull}; use crate::result::Result; use crate::result::Result::{Err, Ok}; @@ -628,7 +628,7 @@ impl<T> [T] { ptr.add(self.len()) }; - Iter { ptr, end, _marker: marker::PhantomData } + Iter { ptr: NonNull::new_unchecked(ptr as *mut T), end, _marker: marker::PhantomData } } } @@ -656,7 +656,7 @@ impl<T> [T] { ptr.add(self.len()) }; - IterMut { ptr, end, _marker: marker::PhantomData } + IterMut { ptr: NonNull::new_unchecked(ptr), end, _marker: marker::PhantomData } } } @@ -3095,7 +3095,7 @@ macro_rules! is_empty { // The way we encode the length of a ZST iterator, this works both for ZST // and non-ZST. ($self: ident) => { - $self.ptr == $self.end + $self.ptr.as_ptr() as *const T == $self.end }; } // To get rid of some bounds checks (see `position`), we compute the length in a somewhat @@ -3105,17 +3105,17 @@ macro_rules! len { #![allow(unused_unsafe)] // we're sometimes used within an unsafe block let start = $self.ptr; - let size = size_from_ptr(start); + let size = size_from_ptr(start.as_ptr()); if size == 0 { // This _cannot_ use `unchecked_sub` because we depend on wrapping // to represent the length of long ZST slice iterators. - ($self.end as usize).wrapping_sub(start as usize) + ($self.end as usize).wrapping_sub(start.as_ptr() as usize) } else { // We know that `start <= end`, so can do better than `offset_from`, // which needs to deal in signed. By setting appropriate flags here // we can tell LLVM this, which helps it remove bounds checks. // SAFETY: By the type invariant, `start <= end` - let diff = unsafe { unchecked_sub($self.end as usize, start as usize) }; + let diff = unsafe { unchecked_sub($self.end as usize, start.as_ptr() as usize) }; // By also telling LLVM that the pointers are apart by an exact // multiple of the type size, it can optimize `len() == 0` down to // `start == end` instead of `(end - start) < size`. @@ -3161,7 +3161,7 @@ macro_rules! iterator { // Helper function for creating a slice from the iterator. #[inline(always)] fn make_slice(&self) -> &'a [T] { - unsafe { from_raw_parts(self.ptr, len!(self)) } + unsafe { from_raw_parts(self.ptr.as_ptr(), len!(self)) } } // Helper function for moving the start of the iterator forwards by `offset` elements, @@ -3171,10 +3171,10 @@ macro_rules! iterator { unsafe fn post_inc_start(&mut self, offset: isize) -> * $raw_mut T { if mem::size_of::<T>() == 0 { zst_shrink!(self, offset); - self.ptr + self.ptr.as_ptr() } else { - let old = self.ptr; - self.ptr = self.ptr.offset(offset); + let old = self.ptr.as_ptr(); + self.ptr = NonNull::new_unchecked(self.ptr.as_ptr().offset(offset)); old } } @@ -3186,7 +3186,7 @@ macro_rules! iterator { unsafe fn pre_dec_end(&mut self, offset: isize) -> * $raw_mut T { if mem::size_of::<T>() == 0 { zst_shrink!(self, offset); - self.ptr + self.ptr.as_ptr() } else { self.end = self.end.offset(-offset); self.end @@ -3215,7 +3215,7 @@ macro_rules! iterator { fn next(&mut self) -> Option<$elem> { // could be implemented with slices, but this avoids bounds checks unsafe { - assume(!self.ptr.is_null()); + assume(!self.ptr.as_ptr().is_null()); if mem::size_of::<T>() != 0 { assume(!self.end.is_null()); } @@ -3245,9 +3245,12 @@ macro_rules! iterator { if mem::size_of::<T>() == 0 { // We have to do it this way as `ptr` may never be 0, but `end` // could be (due to wrapping). - self.end = self.ptr; + self.end = self.ptr.as_ptr(); } else { - self.ptr = self.end; + unsafe { + // End can't be 0 if T isn't ZST because ptr isn't 0 and end >= ptr + self.ptr = NonNull::new_unchecked(self.end as *mut T); + } } return None; } @@ -3308,7 +3311,7 @@ macro_rules! iterator { fn next_back(&mut self) -> Option<$elem> { // could be implemented with slices, but this avoids bounds checks unsafe { - assume(!self.ptr.is_null()); + assume(!self.ptr.as_ptr().is_null()); if mem::size_of::<T>() != 0 { assume(!self.end.is_null()); } @@ -3324,7 +3327,7 @@ macro_rules! iterator { fn nth_back(&mut self, n: usize) -> Option<$elem> { if n >= len!(self) { // This iterator is now empty. - self.end = self.ptr; + self.end = self.ptr.as_ptr(); return None; } // We are in bounds. `pre_dec_end` does the right thing even for ZSTs. @@ -3365,7 +3368,7 @@ macro_rules! iterator { /// [slices]: ../../std/primitive.slice.html #[stable(feature = "rust1", since = "1.0.0")] pub struct Iter<'a, T: 'a> { - ptr: *const T, + ptr: NonNull<T>, end: *const T, // If T is a ZST, this is actually ptr+len. This encoding is picked so that // ptr == end is a quick test for the Iterator being empty, that works // for both ZST and non-ZST. @@ -3467,7 +3470,7 @@ impl<T> AsRef<[T]> for Iter<'_, T> { /// [slices]: ../../std/primitive.slice.html #[stable(feature = "rust1", since = "1.0.0")] pub struct IterMut<'a, T: 'a> { - ptr: *mut T, + ptr: NonNull<T>, end: *mut T, // If T is a ZST, this is actually ptr+len. This encoding is picked so that // ptr == end is a quick test for the Iterator being empty, that works // for both ZST and non-ZST. @@ -3522,7 +3525,7 @@ impl<'a, T> IterMut<'a, T> { /// ``` #[stable(feature = "iter_to_slice", since = "1.4.0")] pub fn into_slice(self) -> &'a mut [T] { - unsafe { from_raw_parts_mut(self.ptr, len!(self)) } + unsafe { from_raw_parts_mut(self.ptr.as_ptr(), len!(self)) } } /// Views the underlying data as a subslice of the original data. @@ -5682,7 +5685,7 @@ impl_marker_for!(BytewiseEquality, #[doc(hidden)] unsafe impl<'a, T> TrustedRandomAccess for Iter<'a, T> { unsafe fn get_unchecked(&mut self, i: usize) -> &'a T { - &*self.ptr.add(i) + &*self.ptr.as_ptr().add(i) } fn may_have_side_effect() -> bool { false @@ -5692,7 +5695,7 @@ unsafe impl<'a, T> TrustedRandomAccess for Iter<'a, T> { #[doc(hidden)] unsafe impl<'a, T> TrustedRandomAccess for IterMut<'a, T> { unsafe fn get_unchecked(&mut self, i: usize) -> &'a mut T { - &mut *self.ptr.add(i) + &mut *self.ptr.as_ptr().add(i) } fn may_have_side_effect() -> bool { false |
