refactor: don't use slicing in remove_nonstandard_footer

This commit is contained in:
link2xt
2024-11-18 13:07:01 +00:00
committed by l
parent 06eea7ebe8
commit 9e13486143

View File

@@ -53,7 +53,6 @@ pub(crate) fn remove_message_footer<'a>(
/// Returns `(lines, is_footer_removed)` tuple;
/// `is_footer_removed` is set to `true` if the footer was actually removed from `lines`
/// (which is equal to the input array otherwise).
#[allow(clippy::indexing_slicing)]
fn remove_nonstandard_footer<'a>(lines: &'a [&str]) -> (&'a [&'a str], bool) {
for (ix, &line) in lines.iter().enumerate() {
if line == "--"
@@ -63,7 +62,10 @@ fn remove_nonstandard_footer<'a>(lines: &'a [&str]) -> (&'a [&'a str], bool) {
|| line.starts_with("*****")
|| line.starts_with("~~~~~")
{
return (&lines[..ix], true);
// `get` should always return `Some` here.
if let Some(lines) = lines.get(..ix) {
return (lines, true);
}
}
}
(lines, false)