diff --git a/CHANGELOG.md b/CHANGELOG.md index 48560634..ccdcd38c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Changed + +* re-enable clippy `missing_const_for_fn` linter warning and added const to functions where applicable ([#2116](https://github.com/extrawurst/gitui/issues/2116)) + ## [0.25.1] - 2024-02-23 ### Fixes diff --git a/asyncgit/src/sync/commit_details.rs b/asyncgit/src/sync/commit_details.rs index 8de0894b..cc60a3c6 100644 --- a/asyncgit/src/sync/commit_details.rs +++ b/asyncgit/src/sync/commit_details.rs @@ -82,8 +82,6 @@ pub struct CommitDetails { impl CommitDetails { /// - #[allow(clippy::missing_const_for_fn)] - // clippy doesn't realise indexing a String is not const pub fn short_hash(&self) -> &str { &self.hash[0..7] } diff --git a/asyncgit/src/sync/tags.rs b/asyncgit/src/sync/tags.rs index 34d0f2d1..700c46fd 100644 --- a/asyncgit/src/sync/tags.rs +++ b/asyncgit/src/sync/tags.rs @@ -20,8 +20,6 @@ pub struct Tag { impl Tag { /// - #[allow(clippy::missing_const_for_fn)] - // clippy doesn't realise allocating a String is not const pub fn new(name: &str) -> Self { Self { name: name.into(), diff --git a/src/components/commitlist.rs b/src/components/commitlist.rs index 84f9c3ae..44fdb1e2 100644 --- a/src/components/commitlist.rs +++ b/src/components/commitlist.rs @@ -296,7 +296,6 @@ impl CommitList { self.current_size.get() } - #[allow(clippy::missing_const_for_fn)] fn selection_max(&self) -> usize { self.commits.len().saturating_sub(1) } @@ -664,7 +663,6 @@ impl CommitList { }) } - #[allow(clippy::missing_const_for_fn)] fn relative_selection(&self) -> usize { self.selection.saturating_sub(self.items.index_offset()) } diff --git a/src/main.rs b/src/main.rs index 91d6649a..84a7a82e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,8 +21,6 @@ clippy::bool_to_int_with_if, clippy::module_name_repetitions )] -// high number of false positives on nightly (as of Oct 2022 with 1.66.0-nightly) -#![allow(clippy::missing_const_for_fn)] //TODO: // #![deny(clippy::expect_used)] diff --git a/src/popups/blame_file.rs b/src/popups/blame_file.rs index 62d1c748..65c7c202 100644 --- a/src/popups/blame_file.rs +++ b/src/popups/blame_file.rs @@ -45,11 +45,11 @@ impl SyntaxFileBlame { &self.file_blame.path } - fn commit_id(&self) -> &CommitId { + const fn commit_id(&self) -> &CommitId { &self.file_blame.commit_id } - fn lines(&self) -> &Vec<(Option, String)> { + const fn lines(&self) -> &Vec<(Option, String)> { &self.file_blame.lines } } @@ -64,7 +64,7 @@ enum BlameProcess { } impl BlameProcess { - fn result(&self) -> Option<&SyntaxFileBlame> { + const fn result(&self) -> Option<&SyntaxFileBlame> { match self { Self::GettingBlame(_) => None, Self::SyntaxHighlighting { @@ -386,7 +386,7 @@ impl BlameFilePopup { } /// - pub fn any_work_pending(&self) -> bool { + pub const fn any_work_pending(&self) -> bool { self.blame.is_some() && !matches!(self.blame, Some(BlameProcess::Result(_))) } diff --git a/src/popups/log_search.rs b/src/popups/log_search.rs index 2513d7ec..e0c57b2c 100644 --- a/src/popups/log_search.rs +++ b/src/popups/log_search.rs @@ -267,7 +267,7 @@ impl LogSearchPopupPopup { ] } - fn option_selected(&self) -> bool { + const fn option_selected(&self) -> bool { !matches!(self.selection, Selection::EnterText) } diff --git a/src/tabs/revlog.rs b/src/tabs/revlog.rs index 524550dd..cf4f966b 100644 --- a/src/tabs/revlog.rs +++ b/src/tabs/revlog.rs @@ -342,7 +342,7 @@ impl Revlog { } } - fn is_in_search_mode(&self) -> bool { + const fn is_in_search_mode(&self) -> bool { !matches!(self.search, LogSearch::Off) } @@ -396,7 +396,7 @@ impl Revlog { ); } - fn can_close_search(&self) -> bool { + const fn can_close_search(&self) -> bool { self.is_in_search_mode() && !self.is_search_pending() } diff --git a/src/ui/scrolllist.rs b/src/ui/scrolllist.rs index 9d4f80a8..d9d369c9 100644 --- a/src/ui/scrolllist.rs +++ b/src/ui/scrolllist.rs @@ -34,7 +34,6 @@ where } } - #[allow(clippy::missing_const_for_fn)] fn block(mut self, block: Block<'b>) -> Self { self.block = Some(block); self diff --git a/src/ui/stateful_paragraph.rs b/src/ui/stateful_paragraph.rs index 4e31cb07..368c07b8 100644 --- a/src/ui/stateful_paragraph.rs +++ b/src/ui/stateful_paragraph.rs @@ -89,7 +89,6 @@ impl<'a> StatefulParagraph<'a> { } } - #[allow(clippy::missing_const_for_fn)] pub fn block(mut self, block: Block<'a>) -> Self { self.block = Some(block); self diff --git a/src/ui/style.rs b/src/ui/style.rs index c00137b7..e687e45e 100644 --- a/src/ui/style.rs +++ b/src/ui/style.rs @@ -143,7 +143,11 @@ impl Theme { self.apply_select(style, selected) } - fn apply_select(&self, style: Style, selected: bool) -> Style { + const fn apply_select( + &self, + style: Style, + selected: bool, + ) -> Style { if selected { style.bg(self.selection_bg).fg(self.selection_fg) } else {