-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
<[T]>::array_*
methods fail to compile on 0 len arrays
Methods updated: * `array_windows` * `array_chunks` * `array_chunks_mut` * `as_chunks` * `as_chunks_mut` * `as_chunks_unchecked` * `as_rchunks` * `as_rchunks_mut` * `as_chunks_unchecked_mut` I implemented this using compile time assertions. Example compilation error: ``` > rustc +stage1 .\improper_array_windows.rs --crate-type=rlib error[E0080]: evaluation of `core::slice::<impl [u32]>::array_windows::<0>::{constant#0}` failed --> J:\rust_lang\library\core\src\slice\mod.rs:1381:13 | 1381 | assert!(N != 0, "window size must be non-zero"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'window size must be non-zero', J:\rust_lang\library\core\src\slice\mod.rs:1381:13 | = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) note: the above error was encountered while instantiating `fn core::slice::<impl [u32]>::array_windows::<0>` --> .\improper_array_windows.rs:4:14 | 4 | for _ in s.array_windows::<0>(){ | ^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error ``` I also added doctests and adjusted documentation. Relates: #74985 #75027
- Loading branch information
1 parent
25f084d
commit 7bb2c00
Showing
1 changed file
with
121 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters