diff options
| author | Maybe Waffle <waffle.lapkin@gmail.com> | 2022-04-04 16:45:09 +0400 |
|---|---|---|
| committer | Maybe Waffle <waffle.lapkin@gmail.com> | 2022-12-16 12:57:22 +0000 |
| commit | ca4989eac278922a64139feb6c23e5e59da4dee2 (patch) | |
| tree | 3c625ee255fba23f91966c68b2799a6dde3d13e2 /library/core | |
| parent | c5351ad4dcd9f3d73241b2acbfc6b4631da845c5 (diff) | |
| download | rust-ca4989eac278922a64139feb6c23e5e59da4dee2.tar.gz rust-ca4989eac278922a64139feb6c23e5e59da4dee2.zip | |
SplitInternal: always set `finished` in `get_end`
Diffstat (limited to 'library/core')
| -rw-r--r-- | library/core/src/str/iter.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/library/core/src/str/iter.rs b/library/core/src/str/iter.rs index 24083ee6af4..21278c99316 100644 --- a/library/core/src/str/iter.rs +++ b/library/core/src/str/iter.rs @@ -585,16 +585,17 @@ where impl<'a, P: Pattern<'a>> SplitInternal<'a, P> { #[inline] fn get_end(&mut self) -> Option<&'a str> { - if !self.finished && (self.allow_trailing_empty || self.end - self.start > 0) { + if !self.finished { self.finished = true; - // SAFETY: `self.start` and `self.end` always lie on unicode boundaries. - unsafe { - let string = self.matcher.haystack().get_unchecked(self.start..self.end); - Some(string) + + if self.allow_trailing_empty || self.end - self.start > 0 { + // SAFETY: `self.start` and `self.end` always lie on unicode boundaries. + let string = unsafe { self.matcher.haystack().get_unchecked(self.start..self.end) }; + return Some(string); } - } else { - None } + + None } #[inline] |
