diff --git a/library/core/src/array/iter.rs b/library/core/src/array/iter.rs index cd2a9e00b5a6..7aed4a132406 100644 --- a/library/core/src/array/iter.rs +++ b/library/core/src/array/iter.rs @@ -23,11 +23,13 @@ pub struct IntoIter { impl IntoIter { #[inline] - fn unsize(&self) -> &InnerUnsized { + #[rustc_const_unstable(feature = "const_iter", issue = "92476")] + const fn unsize(&self) -> &InnerUnsized { self.inner.deref() } #[inline] - fn unsize_mut(&mut self) -> &mut InnerUnsized { + #[rustc_const_unstable(feature = "const_iter", issue = "92476")] + const fn unsize_mut(&mut self) -> &mut InnerUnsized { self.inner.deref_mut() } } @@ -219,7 +221,8 @@ pub fn as_slice(&self) -> &[T] { /// Returns a mutable slice of all elements that have not been yielded yet. #[stable(feature = "array_value_iter", since = "1.51.0")] #[inline] - pub fn as_mut_slice(&mut self) -> &mut [T] { + #[rustc_const_unstable(feature = "const_iter", issue = "92476")] + pub const fn as_mut_slice(&mut self) -> &mut [T] { self.unsize_mut().as_mut_slice() } } diff --git a/library/core/src/array/iter/iter_inner.rs b/library/core/src/array/iter/iter_inner.rs index 3c2343591f8c..fa4ccf507e2f 100644 --- a/library/core/src/array/iter/iter_inner.rs +++ b/library/core/src/array/iter/iter_inner.rs @@ -134,7 +134,8 @@ pub(super) fn as_slice(&self) -> &[T] { } #[inline] - pub(super) fn as_mut_slice(&mut self) -> &mut [T] { + #[rustc_const_unstable(feature = "const_iter", issue = "92476")] + pub(super) const fn as_mut_slice(&mut self) -> &mut [T] { // SAFETY: We know that all elements within `alive` are properly initialized. unsafe { let slice = self.data.get_unchecked_mut(self.alive.clone()); diff --git a/library/core/src/iter/traits/marker.rs b/library/core/src/iter/traits/marker.rs index 2e756a6dd67c..542d283fe95a 100644 --- a/library/core/src/iter/traits/marker.rs +++ b/library/core/src/iter/traits/marker.rs @@ -63,9 +63,11 @@ impl FusedIterator for &mut I {} /// of this trait must inspect [`Iterator::size_hint()`]’s upper bound. #[unstable(feature = "trusted_len", issue = "37572")] #[rustc_unsafe_specialization_marker] -pub unsafe trait TrustedLen: Iterator {} +#[rustc_const_unstable(feature = "const_iter", issue = "92476")] +pub const unsafe trait TrustedLen: [const] Iterator {} #[unstable(feature = "trusted_len", issue = "37572")] +#[rustc_const_unstable(feature = "const_iter", issue = "92476")] unsafe impl TrustedLen for &mut I {} /// An iterator that when yielding an item will have taken at least one element diff --git a/library/core/src/ops/control_flow.rs b/library/core/src/ops/control_flow.rs index 5f8974133a94..f279ef0bb85d 100644 --- a/library/core/src/ops/control_flow.rs +++ b/library/core/src/ops/control_flow.rs @@ -427,7 +427,11 @@ pub const fn into_value(self) -> T { impl ControlFlow { /// Creates a `ControlFlow` from any type implementing `Try`. #[inline] - pub(crate) fn from_try(r: R) -> Self { + #[rustc_const_unstable(feature = "const_control_flow", issue = "148739")] + pub(crate) const fn from_try(r: R) -> Self + where + R: [const] ops::Try, + { match R::branch(r) { ControlFlow::Continue(v) => ControlFlow::Continue(v), ControlFlow::Break(v) => ControlFlow::Break(R::from_residual(v)), @@ -436,7 +440,11 @@ pub(crate) fn from_try(r: R) -> Self { /// Converts a `ControlFlow` into any type implementing `Try`. #[inline] - pub(crate) fn into_try(self) -> R { + #[rustc_const_unstable(feature = "const_control_flow", issue = "148739")] + pub(crate) const fn into_try(self) -> R + where + R: [const] ops::Try, + { match self { ControlFlow::Continue(v) => R::from_output(v), ControlFlow::Break(v) => v, diff --git a/library/core/src/ops/try_trait.rs b/library/core/src/ops/try_trait.rs index aaa71786854d..420927864a1a 100644 --- a/library/core/src/ops/try_trait.rs +++ b/library/core/src/ops/try_trait.rs @@ -416,8 +416,14 @@ pub(crate) const fn wrap_mut_1( } #[inline] - pub(crate) fn wrap_mut_2(mut f: impl FnMut(A, B) -> T) -> impl FnMut(A, B) -> Self { - move |a, b| NeverShortCircuit(f(a, b)) + #[rustc_const_unstable(feature = "const_array", issue = "147606")] + pub(crate) const fn wrap_mut_2( + mut f: F, + ) -> impl [const] FnMut(A, B) -> Self + [const] Destruct + where + F: [const] FnMut(A, B) -> T + [const] Destruct, + { + const move |a, b| NeverShortCircuit(f(a, b)) } } diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 02cd88a6a434..2715981e2d66 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -1748,8 +1748,12 @@ pub const fn insert(&mut self, value: T) -> &mut T /// ``` #[inline] #[stable(feature = "option_entry", since = "1.20.0")] - pub fn get_or_insert(&mut self, value: T) -> &mut T { - self.get_or_insert_with(|| value) + #[rustc_const_unstable(feature = "const_option_ops", issue = "143956")] + pub const fn get_or_insert(&mut self, value: T) -> &mut T + where + T: [const] Destruct, + { + self.get_or_insert_with(const || value) } /// Inserts the default value into the option if it is [`None`], then @@ -2649,7 +2653,8 @@ impl ExactSizeIterator for IntoIter {} impl FusedIterator for IntoIter {} #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl TrustedLen for IntoIter {} +#[rustc_const_unstable(feature = "const_iter", issue = "92476")] +unsafe impl const TrustedLen for IntoIter {} /// The iterator produced by [`Option::into_flat_iter`]. See its documentation for more. #[derive(Clone, Debug)] diff --git a/library/core/src/result.rs b/library/core/src/result.rs index 5f438d72ac13..d2855d072350 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -1682,7 +1682,12 @@ pub const fn unwrap_or_else(self, op: F) -> T #[inline] #[track_caller] #[stable(feature = "option_result_unwrap_unchecked", since = "1.58.0")] - pub unsafe fn unwrap_err_unchecked(self) -> E { + #[rustc_const_unstable(feature = "const_result_unwrap_unchecked", issue = "148714")] + pub const unsafe fn unwrap_err_unchecked(self) -> E + where + T: [const] Destruct, + E: [const] Destruct, + { match self { // SAFETY: the safety contract must be upheld by the caller. Ok(_) => unsafe { hint::unreachable_unchecked() }, diff --git a/library/core/src/tuple.rs b/library/core/src/tuple.rs index 187e201c3cea..adfb027667fa 100644 --- a/library/core/src/tuple.rs +++ b/library/core/src/tuple.rs @@ -120,7 +120,8 @@ fn cmp(&self, other: &($($T,)+)) -> Ordering { maybe_tuple_doc! { $($T)+ @ #[stable(feature = "rust1", since = "1.0.0")] - impl<$($T: Default),+> Default for ($($T,)+) { + #[rustc_const_unstable(feature = "const_default", issue = "143894")] + impl<$($T: [const] Default),+> const Default for ($($T,)+) { #[inline] fn default() -> ($($T,)+) { ($({ let x: $T = Default::default(); x},)+)