Skip to content

Commit 31ffa40

Browse files
committed
Add const assert to MapWindows
Checks if const generic N is not set to 0, otherwise it prevents compilation.
1 parent 8cd8d31 commit 31ffa40

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

library/core/src/iter/adapters/map_windows.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ struct Buffer<T, const N: usize> {
4949
}
5050

5151
impl<I: Iterator, F, const N: usize> MapWindows<I, F, N> {
52-
pub(in crate::iter) fn new(iter: I, f: F) -> Self {
52+
const N_NOT_ZERO: () =
5353
assert!(N != 0, "array in `Iterator::map_windows` must contain more than 0 elements");
5454

55+
pub(in crate::iter) fn new(iter: I, f: F) -> Self {
56+
let _ = Self::N_NOT_ZERO;
57+
5558
// Only ZST arrays' length can be so large.
5659
if mem::size_of::<I::Item>() == 0 {
5760
assert!(

library/core/src/iter/traits/iterator.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,12 +1625,9 @@ pub trait Iterator {
16251625
/// [`slice::windows()`]: slice::windows
16261626
/// [`FusedIterator`]: crate::iter::FusedIterator
16271627
///
1628-
/// # Panics
1629-
///
1630-
/// Panics if `N` is 0. This check will most probably get changed to a
1631-
/// compile time error before this method gets stabilized.
1628+
/// If `N` is 0, then the code will not compile.
16321629
///
1633-
/// ```should_panic
1630+
/// ```compile_fail
16341631
/// #![feature(iter_map_windows)]
16351632
///
16361633
/// let iter = std::iter::repeat(0).map_windows(|&[]| ());

0 commit comments

Comments
 (0)