From 9e134861431b009e57d28378454c6f2b47404e0e Mon Sep 17 00:00:00 2001 From: link2xt Date: Mon, 18 Nov 2024 13:07:01 +0000 Subject: [PATCH] refactor: don't use slicing in `remove_nonstandard_footer` --- src/simplify.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/simplify.rs b/src/simplify.rs index 1d714a6b8..86dbd3cde 100644 --- a/src/simplify.rs +++ b/src/simplify.rs @@ -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)