Skip to content

Commit

Permalink
Fix various new Rust 1.83 clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sdroege committed Dec 2, 2024
1 parent 935e0bd commit 1cfe6e0
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/cmd_line/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down
12 changes: 5 additions & 7 deletions src/color.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::borrow::Cow;

#[derive(Clone, Copy, PartialEq, Debug, Default)]
pub struct Color(pub f64, pub f64, pub f64);

Expand Down Expand Up @@ -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<Self> {
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),
))
)
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ impl<CB: CursorRedrawCb + 'static> Cursor<CB> {
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
Expand Down
12 changes: 4 additions & 8 deletions src/highlight.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{borrow::Cow, collections::HashMap, rc::Rc};
use std::{collections::HashMap, rc::Rc};

use log::error;

Expand Down Expand Up @@ -241,15 +241,11 @@ impl HighlightMap {
}
}

pub fn cursor_bg(&self) -> Cow<Color> {
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())
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/render/itemize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self::Item> {
Expand Down
4 changes: 2 additions & 2 deletions src/ui_model/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1cfe6e0

Please sign in to comment.