Fix clippy warnings

This commit is contained in:
Christian Duerr 2021-07-03 03:06:52 +00:00 committed by GitHub
parent b0bc2a2440
commit 4dd70ba3a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 67 additions and 68 deletions

View File

@ -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<ViAction> for Action {
fn from(action: ViAction) -> Self {
Self::ViAction(action)
Self::Vi(action)
}
}
@ -223,7 +223,7 @@ impl From<ViMotion> for Action {
impl From<SearchAction> 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: \

View File

@ -157,7 +157,7 @@ fn load_from(path: &Path, cli_config: Value) -> Result<Config> {
/// Deserialize configuration file from path.
fn read_config(path: &Path, cli_config: Value) -> Result<Config> {
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);

View File

@ -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(&regex) {
let regex_search = match RegexSearch::new(regex) {
Ok(regex_search) => regex_search,
Err(error) => {
error!("hint regex is invalid: {}", error);

View File

@ -44,7 +44,7 @@ impl<'a> RenderableContent<'a> {
term: &'a Term<T>,
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();

View File

@ -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<renderer::Error> for Error {
impl From<glutin::ContextError> 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);
});
}

View File

@ -177,7 +177,7 @@ impl Window {
wayland_event_queue: Option<&EventQueue>,
) -> Result<Window> {
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.

View File

@ -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<Event> for GlutinEvent<'_, Event> {
impl From<TerminalEvent> 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(&regex).ok();
self.search_state.dfas = RegexSearch::new(regex).ok();
// Update search highlighting.
self.goto_match(MAX_SEARCH_WHILE_TYPING);
@ -1038,7 +1038,7 @@ impl<N: Notify + OnResize> Processor<N> {
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<N: Notify + OnResize> Processor<N> {
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<N: Notify + OnResize> Processor<N> {
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));
}
}

View File

@ -148,19 +148,19 @@ impl<T: EventListener> Execute<T> 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<T: EventListener> Execute<T> 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<T: EventListener> Execute<T> 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<T: EventListener> Execute<T> 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<T: EventListener> Execute<T> 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<T: EventListener> Execute<T> 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<T> {
&self.terminal
self.terminal
}
fn terminal_mut(&mut self) -> &mut Term<T> {

View File

@ -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.

View File

@ -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.

View File

@ -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, &regular_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<crossfont::Metrics, crossfont::Error> {
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, &regular_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);
}

View File

@ -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.

View File

@ -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;

View File

@ -88,14 +88,14 @@ impl<T> Term<T> {
_ => 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(&regex_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<T> Term<T> {
_ => 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(&regex_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