diff --git a/library/core/src/iter/sources/repeat_n.rs b/library/core/src/iter/sources/repeat_n.rs
index c29ab24a08357..de98d73faf4a8 100644
--- a/library/core/src/iter/sources/repeat_n.rs
+++ b/library/core/src/iter/sources/repeat_n.rs
@@ -1,5 +1,6 @@
use crate::fmt;
use crate::iter::{FusedIterator, TrustedLen, UncheckedIterator};
+use crate::marker::Destruct;
use crate::num::NonZero;
use crate::ops::Try;
@@ -85,9 +86,18 @@ pub struct RepeatN {
impl RepeatN {
/// If we haven't already dropped the element, return it in an option.
+ #[rustc_const_unstable(feature = "const_iter", issue = "92476")]
#[inline]
- fn take_element(&mut self) -> Option {
- self.inner.take().map(|inner| inner.element)
+ const fn take_element(&mut self) -> Option
+ where
+ A: [const] Destruct,
+ {
+ //FIXME(const-hack): revert this to a const closure when they are fine to use
+ #[rustc_const_unstable(feature = "const_iter", issue = "92476")]
+ const fn inner_element(inner: RepeatNInner) -> T {
+ inner.element
+ }
+ self.inner.take().map(inner_element)
}
}
@@ -103,7 +113,8 @@ impl fmt::Debug for RepeatN {
}
#[stable(feature = "iter_repeat_n", since = "1.82.0")]
-impl Iterator for RepeatN {
+#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
+impl const Iterator for RepeatN {
type Item = A;
#[inline]
@@ -156,14 +167,21 @@ impl Iterator for RepeatN {
}
#[stable(feature = "iter_repeat_n", since = "1.82.0")]
-impl ExactSizeIterator for RepeatN {
+#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
+impl const ExactSizeIterator for RepeatN {
fn len(&self) -> usize {
- self.inner.as_ref().map(|inner| inner.count.get()).unwrap_or(0)
+ //FIXME(const-hack): revert this to a const closure when they are fine to use
+ #[rustc_const_unstable(feature = "const_iter", issue = "92476")]
+ const fn inner_count(inner: &RepeatNInner) -> usize {
+ inner.count.get()
+ }
+ self.inner.as_ref().map(inner_count).unwrap_or(0)
}
}
#[stable(feature = "iter_repeat_n", since = "1.82.0")]
-impl DoubleEndedIterator for RepeatN {
+#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
+impl const DoubleEndedIterator for RepeatN {
#[inline]
fn next_back(&mut self) -> Option {
self.next()
@@ -182,8 +200,8 @@ impl DoubleEndedIterator for RepeatN {
#[inline]
fn try_rfold(&mut self, init: B, f: F) -> R
where
- F: FnMut(B, A) -> R,
- R: Try