Skip to content

split_inclusive() on empty slice yields a single empty slice (instead of no slices at all) #89716

Closed
@martinvonz

Description

@martinvonz

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

No one assigned

    Labels

    C-bugCategory: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions