From 4dd70ba3a155d1eebe38bcd5a5c4c03ca09f2fea Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sat, 3 Jul 2021 03:06:52 +0000 Subject: [PATCH] Fix clippy warnings --- alacritty/src/config/bindings.rs | 15 ++++++----- alacritty/src/config/mod.rs | 2 +- alacritty/src/config/ui_config.rs | 4 +-- alacritty/src/display/content.rs | 2 +- alacritty/src/display/mod.rs | 24 ++++++++--------- alacritty/src/display/window.rs | 6 ++--- alacritty/src/event.rs | 14 +++++----- alacritty/src/input.rs | 38 +++++++++++++-------------- alacritty/src/logging.rs | 2 +- alacritty/src/main.rs | 2 +- alacritty/src/renderer/mod.rs | 10 +++---- alacritty/src/renderer/rects.rs | 6 ++--- alacritty_terminal/src/lib.rs | 2 +- alacritty_terminal/src/term/search.rs | 8 +++--- 14 files changed, 67 insertions(+), 68 deletions(-) diff --git a/alacritty/src/config/bindings.rs b/alacritty/src/config/bindings.rs index 12349639..c324459e 100644 --- a/alacritty/src/config/bindings.rs +++ b/alacritty/src/config/bindings.rs @@ -103,11 +103,11 @@ pub enum Action { /// Perform vi mode action. #[config(skip)] - ViAction(ViAction), + Vi(ViAction), /// Perform search mode action. #[config(skip)] - SearchAction(SearchAction), + Search(SearchAction), /// Paste contents of system clipboard. Paste, @@ -211,7 +211,7 @@ impl From<&'static str> for Action { impl From for Action { fn from(action: ViAction) -> Self { - Self::ViAction(action) + Self::Vi(action) } } @@ -223,7 +223,7 @@ impl From for Action { impl From for Action { fn from(action: SearchAction) -> Self { - Self::SearchAction(action) + Self::Search(action) } } @@ -232,7 +232,7 @@ impl Display for Action { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Action::ViMotion(motion) => motion.fmt(f), - Action::ViAction(action) => action.fmt(f), + Action::Vi(action) => action.fmt(f), _ => write!(f, "{:?}", self), } } @@ -262,6 +262,7 @@ pub enum ViAction { } /// Search mode specific actions. +#[allow(clippy::enum_variant_names)] #[derive(ConfigDeserialize, Debug, Copy, Clone, PartialEq, Eq)] pub enum SearchAction { /// Move the focus to the next search match. @@ -1081,7 +1082,7 @@ impl<'a> Deserialize<'a> for RawBinding { let action = match (action, chars, command) { (Some(action @ Action::ViMotion(_)), None, None) - | (Some(action @ Action::ViAction(_)), None, None) => { + | (Some(action @ Action::Vi(_)), None, None) => { if !mode.intersects(BindingMode::VI) || not_mode.intersects(BindingMode::VI) { return Err(V::Error::custom(format!( @@ -1091,7 +1092,7 @@ impl<'a> Deserialize<'a> for RawBinding { } action }, - (Some(action @ Action::SearchAction(_)), None, None) => { + (Some(action @ Action::Search(_)), None, None) => { if !mode.intersects(BindingMode::SEARCH) { return Err(V::Error::custom(format!( "action `{}` is only available in search mode, try adding `mode: \ diff --git a/alacritty/src/config/mod.rs b/alacritty/src/config/mod.rs index e2476bb2..840a4b68 100644 --- a/alacritty/src/config/mod.rs +++ b/alacritty/src/config/mod.rs @@ -157,7 +157,7 @@ fn load_from(path: &Path, cli_config: Value) -> Result { /// Deserialize configuration file from path. fn read_config(path: &Path, cli_config: Value) -> Result { let mut config_paths = Vec::new(); - let mut config_value = parse_config(&path, &mut config_paths, IMPORT_RECURSION_LIMIT)?; + let mut config_value = parse_config(path, &mut config_paths, IMPORT_RECURSION_LIMIT)?; // Override config with CLI options. config_value = serde_utils::merge(config_value, cli_config); diff --git a/alacritty/src/config/ui_config.rs b/alacritty/src/config/ui_config.rs index a58c1fd3..cf0f9298 100644 --- a/alacritty/src/config/ui_config.rs +++ b/alacritty/src/config/ui_config.rs @@ -121,7 +121,7 @@ impl UiConfig { #[inline] pub fn key_bindings(&self) -> &[KeyBinding] { - &self.key_bindings.0.as_slice() + self.key_bindings.0.as_slice() } #[inline] @@ -399,7 +399,7 @@ impl LazyRegexVariant { }; // Compile the regex. - let regex_search = match RegexSearch::new(®ex) { + let regex_search = match RegexSearch::new(regex) { Ok(regex_search) => regex_search, Err(error) => { error!("hint regex is invalid: {}", error); diff --git a/alacritty/src/display/content.rs b/alacritty/src/display/content.rs index 926ac7bd..05bd0438 100644 --- a/alacritty/src/display/content.rs +++ b/alacritty/src/display/content.rs @@ -44,7 +44,7 @@ impl<'a> RenderableContent<'a> { term: &'a Term, search_state: &'a SearchState, ) -> Self { - let search = search_state.dfas().map(|dfas| Regex::new(&term, dfas)); + let search = search_state.dfas().map(|dfas| Regex::new(term, dfas)); let focused_match = search_state.focused_match(); let terminal_content = term.renderable_content(); diff --git a/alacritty/src/display/mod.rs b/alacritty/src/display/mod.rs index 0947ab7e..cce3c8bd 100644 --- a/alacritty/src/display/mod.rs +++ b/alacritty/src/display/mod.rs @@ -80,7 +80,7 @@ pub enum Error { Render(renderer::Error), /// Error during buffer swap. - ContextError(glutin::ContextError), + Context(glutin::ContextError), } impl std::error::Error for Error { @@ -89,7 +89,7 @@ impl std::error::Error for Error { Error::Window(err) => err.source(), Error::Font(err) => err.source(), Error::Render(err) => err.source(), - Error::ContextError(err) => err.source(), + Error::Context(err) => err.source(), } } } @@ -100,7 +100,7 @@ impl fmt::Display for Error { Error::Window(err) => err.fmt(f), Error::Font(err) => err.fmt(f), Error::Render(err) => err.fmt(f), - Error::ContextError(err) => err.fmt(f), + Error::Context(err) => err.fmt(f), } } } @@ -125,7 +125,7 @@ impl From for Error { impl From for Error { fn from(val: glutin::ContextError) -> Self { - Error::ContextError(val) + Error::Context(val) } } @@ -242,7 +242,7 @@ impl Display { // Spawn the Alacritty window. let mut window = Window::new( event_loop, - &config, + config, estimated_size, #[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))] wayland_event_queue.as_ref(), @@ -487,7 +487,7 @@ impl Display { // Collect renderable content before the terminal is dropped. let mut content = RenderableContent::new(config, self, &terminal, search_state); let mut grid_cells = Vec::new(); - while let Some(cell) = content.next() { + for cell in &mut content { grid_cells.push(cell); } let background_color = content.color(NamedColor::Background as usize); @@ -599,7 +599,7 @@ impl Display { for (i, message_text) in text.iter().enumerate() { let point = Point::new(start_line + i, Column(0)); self.renderer.with_api(&config.ui_config, &size_info, |mut api| { - api.render_string(glyph_cache, point, fg, bg, &message_text); + api.render_string(glyph_cache, point, fg, bg, message_text); }); } } else { @@ -670,7 +670,7 @@ impl Display { let vi_highlighted_hint = if term.mode().contains(TermMode::VI) { let mods = ModifiersState::all(); let point = term.vi_mode_cursor.point; - hint::highlighted_at(&term, config, point, mods) + hint::highlighted_at(term, config, point, mods) } else { None }; @@ -686,7 +686,7 @@ impl Display { // Find highlighted hint at mouse position. let point = mouse.point(&self.size_info, term.grid().display_offset()); - let highlighted_hint = hint::highlighted_at(&term, config, point, modifiers); + let highlighted_hint = hint::highlighted_at(term, config, point, modifiers); // Update cursor shape. if highlighted_hint.is_some() { @@ -748,7 +748,7 @@ impl Display { let fg = config.ui_config.colors.search_bar_foreground(); let bg = config.ui_config.colors.search_bar_background(); - self.renderer.with_api(&config.ui_config, &size_info, |mut api| { + self.renderer.with_api(&config.ui_config, size_info, |mut api| { api.render_string(glyph_cache, point, fg, bg, &text); }); } @@ -766,7 +766,7 @@ impl Display { let fg = config.ui_config.colors.primary.background; let bg = config.ui_config.colors.normal.red; - self.renderer.with_api(&config.ui_config, &size_info, |mut api| { + self.renderer.with_api(&config.ui_config, size_info, |mut api| { api.render_string(glyph_cache, point, fg, bg, &timing); }); } @@ -789,7 +789,7 @@ impl Display { // Do not render anything if it would obscure the vi mode cursor. if vi_mode_point.map_or(true, |point| point.line != 0 || point.column < column) { let glyph_cache = &mut self.glyph_cache; - self.renderer.with_api(&config.ui_config, &size_info, |mut api| { + self.renderer.with_api(&config.ui_config, size_info, |mut api| { api.render_string(glyph_cache, Point::new(0, column), fg, bg, &text); }); } diff --git a/alacritty/src/display/window.rs b/alacritty/src/display/window.rs index 7302c687..12416700 100644 --- a/alacritty/src/display/window.rs +++ b/alacritty/src/display/window.rs @@ -177,7 +177,7 @@ impl Window { wayland_event_queue: Option<&EventQueue>, ) -> Result { let window_config = &config.ui_config.window; - let window_builder = Window::get_platform_window(&window_config.title, &window_config); + let window_builder = Window::get_platform_window(&window_config.title, window_config); // Check if we're running Wayland to disable vsync. #[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))] @@ -186,9 +186,9 @@ impl Window { let is_wayland = false; let windowed_context = - create_gl_window(window_builder.clone(), &event_loop, false, !is_wayland, size) + create_gl_window(window_builder.clone(), event_loop, false, !is_wayland, size) .or_else(|_| { - create_gl_window(window_builder, &event_loop, true, !is_wayland, size) + create_gl_window(window_builder, event_loop, true, !is_wayland, size) })?; // Text cursor. diff --git a/alacritty/src/event.rs b/alacritty/src/event.rs index 64283eb7..78cc6cb6 100644 --- a/alacritty/src/event.rs +++ b/alacritty/src/event.rs @@ -65,7 +65,7 @@ const MAX_SEARCH_HISTORY_SIZE: usize = 255; /// Events dispatched through the UI event loop. #[derive(Debug, Clone)] pub enum Event { - TerminalEvent(TerminalEvent), + Terminal(TerminalEvent), DprChanged(f64, (u32, u32)), Scroll(Scroll), ConfigReload(PathBuf), @@ -82,7 +82,7 @@ impl From for GlutinEvent<'_, Event> { impl From for Event { fn from(event: TerminalEvent) -> Self { - Event::TerminalEvent(event) + Event::Terminal(event) } } @@ -743,7 +743,7 @@ impl<'a, N: Notify + 'a, T: EventListener> ActionContext<'a, N, T> { self.search_state.dfas = None; } else { // Create search dfas for the new regex string. - self.search_state.dfas = RegexSearch::new(®ex).ok(); + self.search_state.dfas = RegexSearch::new(regex).ok(); // Update search highlighting. self.goto_match(MAX_SEARCH_WHILE_TYPING); @@ -1038,7 +1038,7 @@ impl Processor { match event { // Check for shutdown. - GlutinEvent::UserEvent(Event::TerminalEvent(TerminalEvent::Exit)) => { + GlutinEvent::UserEvent(Event::Terminal(TerminalEvent::Exit)) => { *control_flow = ControlFlow::Exit; return; }, @@ -1181,7 +1181,7 @@ impl Processor { processor.ctx.display.cursor_hidden ^= true; *processor.ctx.dirty = true; }, - Event::TerminalEvent(event) => match event { + Event::Terminal(event) => match event { TerminalEvent::Title(title) => { let ui_config = &processor.ctx.config.ui_config; if ui_config.window.dynamic_title { @@ -1347,7 +1347,7 @@ impl Processor { processor.ctx.display_update_pending.dirty = true; } - let config = match config::reload(&path, &processor.ctx.cli_options) { + let config = match config::reload(path, processor.ctx.cli_options) { Ok(config) => config, Err(_) => return, }; @@ -1493,6 +1493,6 @@ impl EventProxy { impl EventListener for EventProxy { fn send_event(&self, event: TerminalEvent) { - let _ = self.0.send_event(Event::TerminalEvent(event)); + let _ = self.0.send_event(Event::Terminal(event)); } } diff --git a/alacritty/src/input.rs b/alacritty/src/input.rs index 948ec67f..3258137c 100644 --- a/alacritty/src/input.rs +++ b/alacritty/src/input.rs @@ -148,19 +148,19 @@ impl Execute for Action { ctx.terminal_mut().vi_motion(*motion); ctx.mark_dirty(); }, - Action::ViAction(ViAction::ToggleNormalSelection) => { + Action::Vi(ViAction::ToggleNormalSelection) => { Self::toggle_selection(ctx, SelectionType::Simple); }, - Action::ViAction(ViAction::ToggleLineSelection) => { + Action::Vi(ViAction::ToggleLineSelection) => { Self::toggle_selection(ctx, SelectionType::Lines); }, - Action::ViAction(ViAction::ToggleBlockSelection) => { + Action::Vi(ViAction::ToggleBlockSelection) => { Self::toggle_selection(ctx, SelectionType::Block); }, - Action::ViAction(ViAction::ToggleSemanticSelection) => { + Action::Vi(ViAction::ToggleSemanticSelection) => { Self::toggle_selection(ctx, SelectionType::Semantic); }, - Action::ViAction(ViAction::Open) => { + Action::Vi(ViAction::Open) => { let hint = ctx.display().vi_highlighted_hint.take(); if let Some(hint) = &hint { ctx.mouse_mut().block_hint_launcher = false; @@ -168,7 +168,7 @@ impl Execute for Action { } ctx.display().vi_highlighted_hint = hint; }, - Action::ViAction(ViAction::SearchNext) => { + Action::Vi(ViAction::SearchNext) => { let terminal = ctx.terminal(); let direction = ctx.search_direction(); let vi_point = terminal.vi_mode_cursor.point; @@ -182,7 +182,7 @@ impl Execute for Action { ctx.mark_dirty(); } }, - Action::ViAction(ViAction::SearchPrevious) => { + Action::Vi(ViAction::SearchPrevious) => { let terminal = ctx.terminal(); let direction = ctx.search_direction().opposite(); let vi_point = terminal.vi_mode_cursor.point; @@ -196,7 +196,7 @@ impl Execute for Action { ctx.mark_dirty(); } }, - Action::ViAction(ViAction::SearchStart) => { + Action::Vi(ViAction::SearchStart) => { let terminal = ctx.terminal(); let origin = terminal.vi_mode_cursor.point.sub(terminal, Boundary::None, 1); @@ -205,7 +205,7 @@ impl Execute for Action { ctx.mark_dirty(); } }, - Action::ViAction(ViAction::SearchEnd) => { + Action::Vi(ViAction::SearchEnd) => { let terminal = ctx.terminal(); let origin = terminal.vi_mode_cursor.point.add(terminal, Boundary::None, 1); @@ -214,25 +214,23 @@ impl Execute for Action { ctx.mark_dirty(); } }, - Action::SearchAction(SearchAction::SearchFocusNext) => { + Action::Search(SearchAction::SearchFocusNext) => { ctx.advance_search_origin(ctx.search_direction()); }, - Action::SearchAction(SearchAction::SearchFocusPrevious) => { + Action::Search(SearchAction::SearchFocusPrevious) => { let direction = ctx.search_direction().opposite(); ctx.advance_search_origin(direction); }, - Action::SearchAction(SearchAction::SearchConfirm) => ctx.confirm_search(), - Action::SearchAction(SearchAction::SearchCancel) => ctx.cancel_search(), - Action::SearchAction(SearchAction::SearchClear) => { + Action::Search(SearchAction::SearchConfirm) => ctx.confirm_search(), + Action::Search(SearchAction::SearchCancel) => ctx.cancel_search(), + Action::Search(SearchAction::SearchClear) => { let direction = ctx.search_direction(); ctx.cancel_search(); ctx.start_search(direction); }, - Action::SearchAction(SearchAction::SearchDeleteWord) => ctx.search_pop_word(), - Action::SearchAction(SearchAction::SearchHistoryPrevious) => { - ctx.search_history_previous() - }, - Action::SearchAction(SearchAction::SearchHistoryNext) => ctx.search_history_next(), + Action::Search(SearchAction::SearchDeleteWord) => ctx.search_pop_word(), + Action::Search(SearchAction::SearchHistoryPrevious) => ctx.search_history_previous(), + Action::Search(SearchAction::SearchHistoryNext) => ctx.search_history_next(), Action::SearchForward => ctx.start_search(Direction::Right), Action::SearchBackward => ctx.start_search(Direction::Left), Action::Copy => ctx.copy_selection(ClipboardType::Clipboard), @@ -1036,7 +1034,7 @@ mod tests { } fn terminal(&self) -> &Term { - &self.terminal + self.terminal } fn terminal_mut(&mut self) -> &mut Term { diff --git a/alacritty/src/logging.rs b/alacritty/src/logging.rs index 36d20fa3..cbe2ef99 100644 --- a/alacritty/src/logging.rs +++ b/alacritty/src/logging.rs @@ -108,7 +108,7 @@ impl log::Log for Logger { } // Create log message for the given `record` and `target`. - let message = create_log_message(record, &target); + let message = create_log_message(record, target); if let Ok(mut logfile) = self.logfile.lock() { // Write to logfile. diff --git a/alacritty/src/main.rs b/alacritty/src/main.rs index 85a4fc5e..f6e3c1d0 100644 --- a/alacritty/src/main.rs +++ b/alacritty/src/main.rs @@ -1,7 +1,7 @@ //! Alacritty - The GPU Enhanced Terminal. #![warn(rust_2018_idioms, future_incompatible)] -#![deny(clippy::all, clippy::if_not_else, clippy::enum_glob_use, clippy::wrong_pub_self_convention)] +#![deny(clippy::all, clippy::if_not_else, clippy::enum_glob_use)] #![cfg_attr(feature = "cargo-clippy", deny(warnings))] // With the default subsystem, 'console', windows creates an additional console // window for the program. diff --git a/alacritty/src/renderer/mod.rs b/alacritty/src/renderer/mod.rs index 48fcbf20..5f71ddf5 100644 --- a/alacritty/src/renderer/mod.rs +++ b/alacritty/src/renderer/mod.rs @@ -191,7 +191,7 @@ impl GlyphCache { let size = font.size(); // Load regular font. - let regular_desc = Self::make_desc(&font.normal(), Slant::Normal, Weight::Normal); + let regular_desc = Self::make_desc(font.normal(), Slant::Normal, Weight::Normal); let regular = Self::load_regular_font(rasterizer, ®ular_desc, size)?; @@ -233,7 +233,7 @@ impl GlyphCache { error!("{}", err); let fallback_desc = - Self::make_desc(&Font::default().normal(), Slant::Normal, Weight::Normal); + Self::make_desc(Font::default().normal(), Slant::Normal, Weight::Normal); rasterizer.load_font(&fallback_desc, size) }, } @@ -372,7 +372,7 @@ impl GlyphCache { /// Calculate font metrics without access to a glyph cache. pub fn static_metrics(font: Font, dpr: f64) -> Result { let mut rasterizer = crossfont::Rasterizer::new(dpr as f32, font.use_thin_strokes)?; - let regular_desc = GlyphCache::make_desc(&font.normal(), Slant::Normal, Weight::Normal); + let regular_desc = GlyphCache::make_desc(font.normal(), Slant::Normal, Weight::Normal); let regular = Self::load_regular_font(&mut rasterizer, ®ular_desc, font.size())?; rasterizer.get_glyph(GlyphKey { font_key: regular, character: 'm', size: font.size() })?; @@ -1306,12 +1306,12 @@ impl Atlas { } // If there's not enough room in current row, go onto next one. - if !self.room_in_row(&glyph) { + if !self.room_in_row(glyph) { self.advance_row()?; } // If there's still not room, there's nothing that can be done here.. - if !self.room_in_row(&glyph) { + if !self.room_in_row(glyph) { return Err(AtlasInsertError::Full); } diff --git a/alacritty/src/renderer/rects.rs b/alacritty/src/renderer/rects.rs index 591c9f46..77c22011 100644 --- a/alacritty/src/renderer/rects.rs +++ b/alacritty/src/renderer/rects.rs @@ -158,9 +158,9 @@ impl RenderLines { /// Update the stored lines with the next cell info. #[inline] pub fn update(&mut self, cell: &RenderableCell) { - self.update_flag(&cell, Flags::UNDERLINE); - self.update_flag(&cell, Flags::DOUBLE_UNDERLINE); - self.update_flag(&cell, Flags::STRIKEOUT); + self.update_flag(cell, Flags::UNDERLINE); + self.update_flag(cell, Flags::DOUBLE_UNDERLINE); + self.update_flag(cell, Flags::STRIKEOUT); } /// Update the lines for a specific flag. diff --git a/alacritty_terminal/src/lib.rs b/alacritty_terminal/src/lib.rs index 5f80e283..c1ba3690 100644 --- a/alacritty_terminal/src/lib.rs +++ b/alacritty_terminal/src/lib.rs @@ -1,7 +1,7 @@ //! Alacritty - The GPU Enhanced Terminal. #![warn(rust_2018_idioms, future_incompatible)] -#![deny(clippy::all, clippy::if_not_else, clippy::enum_glob_use, clippy::wrong_pub_self_convention)] +#![deny(clippy::all, clippy::if_not_else, clippy::enum_glob_use)] #![cfg_attr(feature = "cargo-clippy", deny(warnings))] pub mod ansi; diff --git a/alacritty_terminal/src/term/search.rs b/alacritty_terminal/src/term/search.rs index bf7f43d1..ff6060af 100644 --- a/alacritty_terminal/src/term/search.rs +++ b/alacritty_terminal/src/term/search.rs @@ -88,14 +88,14 @@ impl Term { _ => end.sub(self, Boundary::None, 1), }; - let mut regex_iter = RegexIter::new(start, end, Direction::Right, &self, dfas).peekable(); + let mut regex_iter = RegexIter::new(start, end, Direction::Right, self, dfas).peekable(); // Check if there's any match at all. let first_match = regex_iter.peek()?.clone(); let regex_match = regex_iter .find(|regex_match| { - let match_point = Self::match_side(®ex_match, side); + let match_point = Self::match_side(regex_match, side); // If the match's point is beyond the origin, we're done. match_point.line < start.line @@ -127,14 +127,14 @@ impl Term { _ => end.add(self, Boundary::None, 1), }; - let mut regex_iter = RegexIter::new(start, end, Direction::Left, &self, dfas).peekable(); + let mut regex_iter = RegexIter::new(start, end, Direction::Left, self, dfas).peekable(); // Check if there's any match at all. let first_match = regex_iter.peek()?.clone(); let regex_match = regex_iter .find(|regex_match| { - let match_point = Self::match_side(®ex_match, side); + let match_point = Self::match_side(regex_match, side); // If the match's point is beyond the origin, we're done. match_point.line > start.line