Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
fredizzimo committed Apr 13, 2024
1 parent fcf5e87 commit 35b8c5d
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 37 deletions.
8 changes: 7 additions & 1 deletion src/bridge/api_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ impl From<&str> for ApiInfoParseError {
}
}

#[allow(unused)]
#[derive(Debug)]
pub struct ApiVersion {
pub major: u64,
Expand All @@ -48,10 +49,11 @@ impl ApiVersion {
|| (actual_major == major && actual_minor > minor)
|| (actual_major == major && actual_minor == minor && actual_patch >= patch);
log::trace!("has desired nvim version: {ret}");
return ret;
ret
}
}

#[allow(unused)]
#[derive(Debug)]
pub struct ApiFunction {
pub name: String,
Expand All @@ -76,6 +78,7 @@ impl PartialEq for ApiFunction {

impl Eq for ApiFunction {}

#[allow(unused)]
#[derive(Debug)]
pub enum ApiParameterType {
Nil,
Expand Down Expand Up @@ -133,12 +136,14 @@ impl ApiParameterType {
}
}

#[allow(unused)]
#[derive(Debug)]
pub struct ApiParameter {
pub name: String,
pub parameter_type: ApiParameterType,
}

#[allow(unused)]
#[derive(Debug)]
pub struct ApiEvent {
pub name: String,
Expand All @@ -160,6 +165,7 @@ impl PartialEq for ApiEvent {

impl Eq for ApiEvent {}

#[allow(unused)]
#[derive(Debug)]
pub struct ApiInformation {
pub channel: u64,
Expand Down
21 changes: 21 additions & 0 deletions src/bridge/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ impl MessageKind {
}
}

#[allow(unused)]
#[derive(Clone, Debug)]
pub enum GuiOption {
ArabicShape(bool),
Expand Down Expand Up @@ -208,9 +209,11 @@ pub enum RedrawEvent {
anchor_grid: u64,
anchor_row: f64,
anchor_column: f64,
#[allow(unused)]
focusable: bool,
sort_order: Option<u64>,
},
#[allow(unused)]
WindowExternalPosition {
grid: u64,
},
Expand All @@ -224,14 +227,20 @@ pub enum RedrawEvent {
grid: u64,
row: u64,
scrolled: bool,
#[allow(unused)]
separator_character: String,
},
WindowViewport {
grid: u64,
#[allow(unused)]
top_line: f64,
#[allow(unused)]
bottom_line: f64,
#[allow(unused)]
current_line: f64,
#[allow(unused)]
current_column: f64,
#[allow(unused)]
line_count: Option<f64>,
scroll_delta: Option<f64>,
},
Expand All @@ -242,6 +251,7 @@ pub enum RedrawEvent {
left: u64,
right: u64,
},
#[allow(unused)]
CommandLineShow {
content: StyledContent,
position: u64,
Expand All @@ -250,38 +260,49 @@ pub enum RedrawEvent {
indent: u64,
level: u64,
},
#[allow(unused)]
CommandLinePosition {
position: u64,
level: u64,
},
#[allow(unused)]
CommandLineSpecialCharacter {
character: String,
shift: bool,
level: u64,
},
#[allow(unused)]
CommandLineHide,
#[allow(unused)]
CommandLineBlockShow {
lines: Vec<StyledContent>,
},
#[allow(unused)]
CommandLineBlockAppend {
line: StyledContent,
},
#[allow(unused)]
CommandLineBlockHide,
#[allow(unused)]
MessageShow {
kind: MessageKind,
content: StyledContent,
replace_last: bool,
},
MessageClear,
#[allow(unused)]
MessageShowMode {
content: StyledContent,
},
#[allow(unused)]
MessageShowCommand {
content: StyledContent,
},
#[allow(unused)]
MessageRuler {
content: StyledContent,
},
#[allow(unused)]
MessageHistoryShow {
entries: Vec<(MessageKind, StyledContent)>,
},
Expand Down
6 changes: 5 additions & 1 deletion src/cmd_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ fn get_styles() -> Styles {
}

fn is_tty_str() -> &'static str {
is_tty().then_some("1").unwrap_or("0")
if is_tty() {
"1"
} else {
"0"
}
}

#[derive(Clone, Debug, Parser)]
Expand Down
2 changes: 1 addition & 1 deletion src/editor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ impl Editor {
anchor_type: WindowAnchor::NorthWest,
anchor_left: 0.0,
anchor_top: grid_top as f64,
sort_order: std::u64::MAX,
sort_order: u64::MAX,
};

if let Some(window) = self.windows.get_mut(&grid) {
Expand Down
15 changes: 0 additions & 15 deletions src/error_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,6 @@ impl<T, E: ToString> ResultPanicExplanation<T, E> for Result<T, E> {
}
}

pub trait OptionPanicExplanation<T> {
fn unwrap_or_explained_panic(self, explanation: &str) -> T;
}

impl<T> OptionPanicExplanation<T> for Option<T> {
fn unwrap_or_explained_panic(self, explanation: &str) -> T {
match self {
None => {
show_error(explanation);
}
Some(content) => content,
}
}
}

fn format_and_log_error_message(err: Error) -> String {
let msg = format!("\
Neovide just crashed :(
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ fn setup(
let window_size = determine_window_size(window_settings.as_ref());
let grid_size = match window_size {
WindowSize::Grid(grid_size) => Some(grid_size),
// Clippy wrongly suggests to use unwrap or default here
#[allow(clippy::manual_unwrap_or_default)]
_ => match window_settings {
Some(PersistentWindowSettings::Windowed { grid_size, .. }) => grid_size,
_ => None,
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/animation_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn ease_in_expo(t: f32) -> f32 {

#[allow(dead_code)]
pub fn ease_out_expo(t: f32) -> f32 {
if (t - 1.0).abs() < std::f32::EPSILON {
if (t - 1.0).abs() < f32::EPSILON {
1.0
} else {
1.0 - 2.0f32.powf(-10.0 * t)
Expand Down Expand Up @@ -103,7 +103,7 @@ impl CriticallyDampedSpringAnimation {
self.scroll_t = 0.0;
}

if 1.0 - self.scroll_t < std::f32::EPSILON {
if self.scroll_t > 1.0 - f32::EPSILON {
// We are at destination, move t out of 0-1 range to stop the animation.
self.scroll_t = 2.0;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/cursor_renderer/cursor_vfx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl CursorVfx for PointHighlight {
grid_renderer: &mut GridRenderer,
cursor: &Cursor,
) {
if (self.t - 1.0).abs() < std::f32::EPSILON {
if (self.t - 1.0).abs() < f32::EPSILON {
return;
}

Expand Down
6 changes: 3 additions & 3 deletions src/renderer/cursor_renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl Corner {
}

// Check first if animation's over
if (self.t - 1.0).abs() < std::f32::EPSILON {
if (self.t - 1.0).abs() < f32::EPSILON {
return false;
}

Expand Down Expand Up @@ -147,14 +147,14 @@ impl Corner {

let direction_alignment = travel_direction.dot(corner_direction);

if (self.t - 1.0).abs() < std::f32::EPSILON {
if (self.t - 1.0).abs() < f32::EPSILON {
// We are at destination, move t out of 0-1 range to stop the animation
self.t = 2.0;
} else {
let corner_dt = dt
* lerp(
1.0,
(1.0 - settings.trail_size).max(0.0).min(1.0),
(1.0 - settings.trail_size).clamp(0.0, 1.0),
-direction_alignment,
);
self.t =
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/fonts/font_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl FontOptions {
Some(style.into_iter().unique().sorted().join(" "))
};
for font in font_options.normal.iter_mut() {
font.style = style.clone();
font.style.clone_from(&style);
}

Ok(font_options)
Expand Down Expand Up @@ -255,7 +255,7 @@ impl PartialEq for FontOptions {
&& self.bold_italic == other.bold_italic
&& self.features == other.features
&& self.edging == other.edging
&& (self.size - other.size).abs() < std::f32::EPSILON
&& (self.size - other.size).abs() < f32::EPSILON
&& self.hinting == other.hinting
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/renderer/grid_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub struct GridRenderer {
pub default_style: Arc<Style>,
pub em_size: f32,
pub font_dimensions: Dimensions,
pub scale_factor: f64,
pub is_ready: bool,
}

Expand All @@ -47,7 +46,6 @@ impl GridRenderer {
default_style,
em_size,
font_dimensions,
scale_factor,
is_ready: false,
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/renderer/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::renderer::animation_utils::lerp;
use crate::settings::SETTINGS;
use std::collections::VecDeque;
use std::sync::Arc;
use std::time::Instant;

use crate::{
profiling::tracy_zone,
Expand All @@ -16,7 +15,6 @@ pub struct Profiler {
pub font: Arc<FontPair>,
pub position: Point,
pub size: Size,
pub last_draw: Instant,
pub frametimes: VecDeque<f32>,
}

Expand All @@ -29,7 +27,6 @@ impl Profiler {
font,
position: Point::new(32.0, 32.0),
size: Size::new(200.0, 120.0),
last_draw: Instant::now(),
frametimes: VecDeque::with_capacity(FRAMETIMES_COUNT),
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/renderer/rendered_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ struct Line {
}

pub struct RenderedWindow {
pub vertical_position: f32,

pub id: u64,
pub hidden: bool,
pub anchor_info: Option<AnchorInfo>,
Expand All @@ -108,7 +106,6 @@ pub struct RenderedWindow {
pub struct WindowDrawDetails {
pub id: u64,
pub region: Rect,
pub floating_order: Option<u64>,
}

impl WindowDrawDetails {
Expand All @@ -124,7 +121,6 @@ impl WindowDrawDetails {
impl RenderedWindow {
pub fn new(id: u64, grid_position: Point, grid_size: Dimensions) -> RenderedWindow {
RenderedWindow {
vertical_position: 0.0,
id,
hidden: false,
anchor_info: None,
Expand Down Expand Up @@ -214,7 +210,7 @@ impl RenderedWindow {
) -> bool {
let mut animating = false;

if 1.0 - self.position_t < std::f32::EPSILON {
if self.position_t > 1.0 - f32::EPSILON {
// We are at destination, move t out of 0-1 range to stop the animation.
self.position_t = 2.0;
} else {
Expand Down Expand Up @@ -477,7 +473,6 @@ impl RenderedWindow {
WindowDrawDetails {
id: self.id,
region: pixel_region,
floating_order: self.anchor_info.as_ref().map(|v| v.sort_order),
}
}

Expand Down
1 change: 1 addition & 0 deletions src/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ pub fn create_event_loop() -> EventLoop<UserEvent> {
let event_loop = builder.build().expect("Failed to create winit event loop");
#[cfg(target_os = "macos")]
crate::window::macos::register_file_handler();
#[allow(clippy::let_and_return)]
event_loop
}

Expand Down

0 comments on commit 35b8c5d

Please sign in to comment.