Closed
Description
I tried this code:
let empty_str = "";
let expected : Vec<&str> = vec![];
assert_eq!(empty_str.split_inclusive(|ch| ch == '\n').collect::<Vec<_>>(), expected);
let empty_slice: &[u8] = &[];
let expected : Vec<&[u8]> = vec![];
assert_eq!(empty_slice.split_inclusive(|b| *b == b'\n').collect::<Vec<_>>(), expected);
I expected to see this happen: Both assertions pass, i.e. split_inclusive()
yields no results on empty input.
Instead, this happened: The second assertion fails because split_inclusive()
on an empty slice yields a single empty element instead of no elements.
Meta
rustc --version --verbose
:
cargo 1.57.0-nightly (0121d66aa 2021-09-22)
(Skipping backtrace from template as that doesn't seem relevant.)