From 1cfe6e00c5b721bf7484e911d1192d03172b2c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 2 Dec 2024 11:30:44 +0200 Subject: [PATCH] Fix various new Rust 1.83 clippy warnings --- src/cmd_line/mod.rs | 2 +- src/color.rs | 12 +++++------- src/cursor.rs | 1 - src/highlight.rs | 12 ++++-------- src/render/itemize.rs | 2 +- src/ui_model/line.rs | 4 ++-- 6 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/cmd_line/mod.rs b/src/cmd_line/mod.rs index 08626cb5..55462049 100644 --- a/src/cmd_line/mod.rs +++ b/src/cmd_line/mod.rs @@ -525,7 +525,7 @@ pub struct CmdLineContext<'a> { pub max_width: i32, } -impl<'a> CmdLineContext<'a> { +impl CmdLineContext<'_> { fn get_lines(&self, hl: &HighlightMap) -> LineContent { let mut content_line = self.content.to_attributed_content(hl); let (prompt_offset, prompt_lines) = diff --git a/src/color.rs b/src/color.rs index 03959c05..182419e5 100644 --- a/src/color.rs +++ b/src/color.rs @@ -1,5 +1,3 @@ -use std::borrow::Cow; - #[derive(Clone, Copy, PartialEq, Debug, Default)] pub struct Color(pub f64, pub f64, pub f64); @@ -67,19 +65,19 @@ impl Color { Self(1.0 - self.0, 1.0 - self.1, 1.0 - self.2) } - pub fn fade<'a>(&'a self, into: &'a Self, percentage: f64) -> Cow { + pub fn fade(&self, into: &Self, percentage: f64) -> Self { debug_assert!((0.0..=1.0).contains(&percentage)); match percentage { - _ if percentage <= 0.000001 => Cow::Borrowed(self), - _ if percentage >= 0.999999 => Cow::Borrowed(into), + _ if percentage <= 0.000001 => *self, + _ if percentage >= 0.999999 => *into, _ => { let inv = (into.0 - self.0, into.1 - self.1, into.2 - self.2); - Cow::Owned(Self( + Self( self.0 + (inv.0 * percentage), self.1 + (inv.1 * percentage), self.2 + (inv.2 * percentage), - )) + ) } } } diff --git a/src/cursor.rs b/src/cursor.rs index 7f582715..7b310589 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -229,7 +229,6 @@ impl Cursor { let bg = hl .actual_cell_bg(cell) .fade(&hl.cursor_bg(), fade_percentage) - .as_ref() .to_rgbo(filled_alpha); snapshot.append_color(&bg, &Rect::new(x, y, w, h)); true diff --git a/src/highlight.rs b/src/highlight.rs index e892aa5d..819e8fd0 100644 --- a/src/highlight.rs +++ b/src/highlight.rs @@ -1,4 +1,4 @@ -use std::{borrow::Cow, collections::HashMap, rc::Rc}; +use std::{collections::HashMap, rc::Rc}; use log::error; @@ -241,15 +241,11 @@ impl HighlightMap { } } - pub fn cursor_bg(&self) -> Cow { + pub fn cursor_bg(&self) -> Color { if self.cursor.reverse { - Cow::Borrowed(self.cursor.foreground.as_ref().unwrap_or_else(|| self.fg())) + self.cursor.foreground.unwrap_or_else(|| *self.fg()) } else { - self.cursor - .background - .as_ref() - .map(Cow::Borrowed) - .unwrap_or_else(|| Cow::Owned(self.bg().invert())) + self.cursor.background.unwrap_or_else(|| self.bg().invert()) } } } diff --git a/src/render/itemize.rs b/src/render/itemize.rs index 3c06938b..e9942bff 100644 --- a/src/render/itemize.rs +++ b/src/render/itemize.rs @@ -40,7 +40,7 @@ impl<'a> ItemizeIterator<'a> { * guaranteed to be consistent, items will ideally be per-word to speed up rendering. For Unicode, * items will be per-grapheme to ensure correct monospaced display. */ -impl<'a> Iterator for ItemizeIterator<'a> { +impl Iterator for ItemizeIterator<'_> { type Item = ItemizeResult; fn next(&mut self) -> Option { diff --git a/src/ui_model/line.rs b/src/ui_model/line.rs index a0c613a9..09faccfa 100644 --- a/src/ui_model/line.rs +++ b/src/ui_model/line.rs @@ -228,7 +228,7 @@ struct PangoItemPosition<'a> { end_cell: usize, } -impl<'a> PangoItemPosition<'a> { +impl PangoItemPosition<'_> { #[inline] fn cells_count(&self) -> i32 { (self.end_cell - self.start_cell) as i32 + 1 @@ -442,7 +442,7 @@ impl<'c> StyleAttr<'c> { } } -impl<'c> PartialEq for StyleAttr<'c> { +impl PartialEq for StyleAttr<'_> { fn eq(&self, other: &Self) -> bool { self.italic == other.italic && self.bold == other.bold