]> git.lizzy.rs Git - rust.git/commit - src/tools/rust-analyzer
Rollup merge of #89825 - martinvonz:split-inclusive-empty, r=m-ou-se
authorMatthias Krüger <matthias.krueger@famsik.de>
Tue, 14 Dec 2021 19:47:26 +0000 (20:47 +0100)
committerGitHub <noreply@github.com>
Tue, 14 Dec 2021 19:47:26 +0000 (20:47 +0100)
commit50327d2c9169cb218834ee75db00f0b3a969c54c
treed68590fcae644e85abb03f04b073d2f4dca8d285
parent404c8471aba60c2d837fa728e7c729a0f52d5830
parentf6e4c742f41c5505c9a371ce8ef2c7aed55c35e4
Rollup merge of #89825 - martinvonz:split-inclusive-empty, r=m-ou-se

Make split_inclusive() on an empty slice yield an empty output

`[].split_inclusive()` currently yields a single, empty slice. That's
different from `"".split_inslusive()`, which yields no output at
all. I think that makes the slice version harder to use.

The case where I ran into this bug was when writing code for
generating a diff between two slices of bytes. I wanted to prefix
removed lines with "-" and a added lines with "+". Due to
`split_inclusive()`'s current behavior, that means that my code prints
just a "-" or "+" for empty files. I suspect most existing callers
have similar "bugs" (which would be fixed by this patch).

Closes #89716.
library/core/src/slice/iter.rs