-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
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.)
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.