diff --git a/library/core/src/iter/adapters/map_windows.rs b/library/core/src/iter/adapters/map_windows.rs index 5f39b24583427..905d8c0aae842 100644 --- a/library/core/src/iter/adapters/map_windows.rs +++ b/library/core/src/iter/adapters/map_windows.rs @@ -49,9 +49,12 @@ struct Buffer { } impl MapWindows { - pub(in crate::iter) fn new(iter: I, f: F) -> Self { + const N_NOT_ZERO: () = assert!(N != 0, "array in `Iterator::map_windows` must contain more than 0 elements"); + pub(in crate::iter) fn new(iter: I, f: F) -> Self { + let _ = Self::N_NOT_ZERO; + // Only ZST arrays' length can be so large. if mem::size_of::() == 0 { assert!( diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index 20dd95a3a4623..48cdfffcb55ae 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -1609,17 +1609,20 @@ pub trait Iterator { /// [`slice::windows()`]: slice::windows /// [`FusedIterator`]: crate::iter::FusedIterator /// - /// # Panics - /// - /// Panics if `N` is 0. This check will most probably get changed to a - /// compile time error before this method gets stabilized. + /// If `N` is 0, then the code will not compile. /// - /// ```should_panic + /// ```compile_fail /// #![feature(iter_map_windows)] /// /// let iter = std::iter::repeat(0).map_windows(|&[]| ()); /// ``` /// + /// ```compile_fail + /// #![feature(iter_map_windows)] + /// + /// let iter = std::iter::repeat(0).map_windows(|_: &[_; 0]| ()); + /// ``` + /// /// # Examples /// /// Building the sums of neighboring numbers. diff --git a/library/core/tests/iter/adapters/map_windows.rs b/library/core/tests/iter/adapters/map_windows.rs index 7fb2408f8acb7..56841871a88c4 100644 --- a/library/core/tests/iter/adapters/map_windows.rs +++ b/library/core/tests/iter/adapters/map_windows.rs @@ -167,12 +167,6 @@ fn test_case_from_pr_82413_comment() { for () in std::iter::repeat("0".to_owned()).map_windows(|_: &[_; 3]| {}).take(4) {} } -#[test] -#[should_panic = "array in `Iterator::map_windows` must contain more than 0 elements"] -fn check_zero_window() { - let _ = std::iter::repeat(0).map_windows(|_: &[_; 0]| ()); -} - #[test] fn test_zero_sized_type() { #[derive(Copy, Clone, Debug, Eq, PartialEq)]