Fix generic bound of `str::SplitInclusive`'s `DoubleEndedIterator` impl by timve...
source link: https://github.com/rust-lang/rust/pull/100806
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Conversation
Contributor
str::SplitInclusive
's DoubleEndedIterator
implementation currently uses a ReverseSearcher
bound for the corresponding searcher. A DoubleEndedSearcher
bound should have been used instead.
DoubleEndedIterator
requires that repeated next_back
calls produce the same items as repeated next
calls, in opposite order. ReverseSearcher
lets you search starting from the back of a string, but it makes no guarantees about how its matches correspond to the matches found by a forward search. DoubleEndedSearcher
is a subtrait of ReverseSearcher
and does require that the same matches are found in both directions.
This bug fix is a breaking change. Calling next_back
on "a+++b".split_inclusive("++")
is currently accepted with repeated calls producing "b"
and "a+++"
, while forward iteration yields "a++"
and "+b"
. Also see #100756 (comment) for more details.
I believe that this is the only iterator that uses this bound incorrectly — other related iterators such as str::Split
do have a DoubleEndedSearcher
bound for their DoubleEndedIterator
implementation. And slice::SplitInclusive
doesn't face this problem at all because it doesn't use patterns, only a predicate.
cc @SkiFire13
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK