From 12afbd007db8a8995617b3e7ebda3840860bbadc Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sun, 1 Jul 2018 16:31:46 +0000 Subject: [PATCH] Fix clippy issues --- font/src/darwin/mod.rs | 6 +++--- font/src/ft/fc/mod.rs | 4 ++-- font/src/ft/mod.rs | 6 +++--- font/src/lib.rs | 2 +- src/ansi.rs | 8 ++++---- src/config.rs | 6 +++--- src/event.rs | 2 +- src/index.rs | 22 +++++++++++----------- src/input.rs | 28 ++++++++++++++-------------- src/renderer/mod.rs | 14 +++++++------- src/selection.rs | 8 ++++---- src/term/mod.rs | 22 +++++++++++----------- 12 files changed, 64 insertions(+), 64 deletions(-) diff --git a/font/src/darwin/mod.rs b/font/src/darwin/mod.rs index 843d75dd..4351af61 100644 --- a/font/src/darwin/mod.rs +++ b/font/src/darwin/mod.rs @@ -162,7 +162,7 @@ impl ::Rasterize for Rasterizer { } /// Get rasterized glyph for given glyph key - fn get_glyph(&mut self, glyph: &GlyphKey) -> Result { + fn get_glyph(&mut self, glyph: GlyphKey) -> Result { // get loaded font let font = self.fonts @@ -246,7 +246,7 @@ impl Rasterizer { // Helper to try and get a glyph for a given font. Used for font fallback. fn maybe_get_glyph( &self, - glyph: &GlyphKey, + glyph: GlyphKey, font: &Font, ) -> Option> { let scaled_size = self.device_pixel_ratio * glyph.size.as_f32_pts(); @@ -356,7 +356,7 @@ impl Descriptor { let menlo = ct_new_from_descriptor(&descriptor.ct_descriptor, size); // TODO fixme, hardcoded en for english - let mut fallbacks = cascade_list_for_languages(&menlo, &vec!["en".to_owned()]) + let mut fallbacks = cascade_list_for_languages(&menlo, &["en".to_owned()]) .into_iter() .filter(|desc| desc.font_path != "") .map(|desc| desc.to_font(size, false)) diff --git a/font/src/ft/fc/mod.rs b/font/src/ft/fc/mod.rs index ac0c9442..865f63c9 100644 --- a/font/src/ft/fc/mod.rs +++ b/font/src/ft/fc/mod.rs @@ -180,9 +180,9 @@ pub enum Width { } impl Width { - fn to_isize(&self) -> isize { + fn to_isize(self) -> isize { use self::Width::*; - match *self { + match self { Ultracondensed => 50, Extracondensed => 63, Condensed => 75, diff --git a/font/src/ft/mod.rs b/font/src/ft/mod.rs index 7c5fb768..cdae88cb 100644 --- a/font/src/ft/mod.rs +++ b/font/src/ft/mod.rs @@ -102,7 +102,7 @@ impl ::Rasterize for FreeTypeRasterizer { self.get_face(desc, size) } - fn get_glyph(&mut self, glyph_key: &GlyphKey) -> Result { + fn get_glyph(&mut self, glyph_key: GlyphKey) -> Result { self.get_rendered_glyph(glyph_key) } @@ -264,7 +264,7 @@ impl FreeTypeRasterizer { } } - fn face_for_glyph(&mut self, glyph_key: &GlyphKey, have_recursed: bool) -> Result { + fn face_for_glyph(&mut self, glyph_key: GlyphKey, have_recursed: bool) -> Result { let c = glyph_key.c; let use_initial_face = if self.faces.contains_key(&glyph_key.font_key) { @@ -285,7 +285,7 @@ impl FreeTypeRasterizer { } } - fn get_rendered_glyph(&mut self, glyph_key: &GlyphKey) + fn get_rendered_glyph(&mut self, glyph_key: GlyphKey) -> Result { // Render a custom symbol for the underline and beam cursor match glyph_key.c { diff --git a/font/src/lib.rs b/font/src/lib.rs index 05680da2..ad94d084 100644 --- a/font/src/lib.rs +++ b/font/src/lib.rs @@ -344,5 +344,5 @@ pub trait Rasterize { fn load_font(&mut self, &FontDesc, Size) -> Result; /// Rasterize the glyph described by `GlyphKey`. - fn get_glyph(&mut self, &GlyphKey) -> Result; + fn get_glyph(&mut self, GlyphKey) -> Result; } diff --git a/src/ansi.rs b/src/ansi.rs index dbc361a8..e37e25f1 100644 --- a/src/ansi.rs +++ b/src/ansi.rs @@ -561,8 +561,8 @@ pub enum NamedColor { } impl NamedColor { - pub fn to_bright(&self) -> Self { - match *self { + pub fn to_bright(self) -> Self { + match self { NamedColor::Black => NamedColor::BrightBlack, NamedColor::Red => NamedColor::BrightRed, NamedColor::Green => NamedColor::BrightGreen, @@ -583,8 +583,8 @@ impl NamedColor { } } - pub fn to_dim(&self) -> Self { - match *self { + pub fn to_dim(self) -> Self { + match self { NamedColor::Black => NamedColor::DimBlack, NamedColor::Red => NamedColor::DimRed, NamedColor::Green => NamedColor::DimGreen, diff --git a/src/config.rs b/src/config.rs index 539edb61..cdf1dc21 100644 --- a/src/config.rs +++ b/src/config.rs @@ -242,7 +242,7 @@ impl Alpha { } #[inline] - pub fn get(&self) -> f32 { + pub fn get(self) -> f32 { self.0 } @@ -1925,10 +1925,10 @@ enum Key { } impl Key { - fn to_glutin_key(&self) -> ::glutin::VirtualKeyCode { + fn to_glutin_key(self) -> ::glutin::VirtualKeyCode { use ::glutin::VirtualKeyCode::*; // Thank you, vim macros! - match *self { + match self { Key::Key1 => Key1, Key::Key2 => Key2, Key::Key3 => Key3, diff --git a/src/event.rs b/src/event.rs index cff013e3..c10f8a72 100644 --- a/src/event.rs +++ b/src/event.rs @@ -291,7 +291,7 @@ impl Processor { }, KeyboardInput { input, .. } => { let glutin::KeyboardInput { state, virtual_keycode, modifiers, .. } = input; - processor.process_key(state, virtual_keycode, &modifiers); + processor.process_key(state, virtual_keycode, modifiers); if state == ElementState::Pressed { // Hide cursor while typing *hide_cursor = true; diff --git a/src/index.rs b/src/index.rs index 418faff2..c5ae0794 100644 --- a/src/index.rs +++ b/src/index.rs @@ -270,7 +270,7 @@ macro_rules! inclusive { match *self { Empty { .. } => (0, Some(0)), - NonEmpty { ref start, ref end } => { + NonEmpty { start, end } => { let added = $steps_add_one(start, end); match added { Some(hint) => (hint.saturating_add(1), hint.checked_add(1)), @@ -283,9 +283,9 @@ macro_rules! inclusive { } } -fn steps_add_one_u8(start: &u8, end: &u8) -> Option { - if *start < *end { - Some((*end - *start) as usize) +fn steps_add_one_u8(start: u8, end: u8) -> Option { + if start < end { + Some((end - start) as usize) } else { None } @@ -330,11 +330,11 @@ macro_rules! ops { impl $ty { #[inline] #[allow(trivial_numeric_casts)] - fn steps_between(start: &$ty, end: &$ty, by: &$ty) -> Option { - if *by == $construct(0) { return None; } - if *start < *end { + fn steps_between(start: $ty, end: $ty, by: $ty) -> Option { + if by == $construct(0) { return None; } + if start < end { // Note: We assume $t <= usize here - let diff = (*end - *start).0; + let diff = (end - start).0; let by = by.0; if diff % by > 0 { Some(diff / by + 1) @@ -347,8 +347,8 @@ macro_rules! ops { } #[inline] - fn steps_between_by_one(start: &$ty, end: &$ty) -> Option { - Self::steps_between(start, end, &$construct(1)) + fn steps_between_by_one(start: $ty, end: $ty) -> Option { + Self::steps_between(start, end, $construct(1)) } } @@ -366,7 +366,7 @@ macro_rules! ops { } #[inline] fn size_hint(&self) -> (usize, Option) { - match Self::Item::steps_between_by_one(&self.0.start, &self.0.end) { + match Self::Item::steps_between_by_one(self.0.start, self.0.end) { Some(hint) => (hint, Some(hint)), None => (0, None) } diff --git a/src/input.rs b/src/input.rs index 7afd359d..aa00ee3d 100644 --- a/src/input.rs +++ b/src/input.rs @@ -102,15 +102,15 @@ impl Binding { fn is_triggered_by( &self, mode: TermMode, - mods: &ModifiersState, + mods: ModifiersState, input: &T ) -> bool { // Check input first since bindings are stored in one big list. This is // the most likely item to fail so prioritizing it here allows more // checks to be short circuited. self.trigger == *input && - self.mode_matches(&mode) && - self.not_mode_matches(&mode) && + self.mode_matches(mode) && + self.not_mode_matches(mode) && self.mods_match(mods) } } @@ -123,12 +123,12 @@ impl Binding { } #[inline] - fn mode_matches(&self, mode: &TermMode) -> bool { + fn mode_matches(&self, mode: TermMode) -> bool { self.mode.is_empty() || mode.intersects(self.mode) } #[inline] - fn not_mode_matches(&self, mode: &TermMode) -> bool { + fn not_mode_matches(&self, mode: TermMode) -> bool { self.notmode.is_empty() || !mode.intersects(self.notmode) } @@ -136,10 +136,10 @@ impl Binding { /// /// Optimized to use single check instead of four (one per modifier) #[inline] - fn mods_match(&self, mods: &ModifiersState) -> bool { + fn mods_match(&self, mods: ModifiersState) -> bool { debug_assert!(4 == mem::size_of::()); unsafe { - mem::transmute_copy::<_, u32>(&self.mods) == mem::transmute_copy::<_, u32>(mods) + mem::transmute_copy::<_, u32>(&self.mods) == mem::transmute_copy::<_, u32>(&mods) } } } @@ -532,7 +532,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { return; } - self.process_mouse_bindings(&ModifiersState::default(), button); + self.process_mouse_bindings(ModifiersState::default(), button); } /// Process key input @@ -542,11 +542,11 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { &mut self, state: ElementState, key: Option, - mods: &ModifiersState, + mods: ModifiersState, ) { match (key, state) { (Some(key), ElementState::Pressed) => { - *self.ctx.last_modifiers() = *mods; + *self.ctx.last_modifiers() = mods; *self.ctx.received_count() = 0; *self.ctx.suppress_chars() = false; @@ -587,7 +587,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { /// for its action to be executed. /// /// Returns true if an action is executed. - fn process_key_bindings(&mut self, mods: &ModifiersState, key: VirtualKeyCode) -> bool { + fn process_key_bindings(&mut self, mods: ModifiersState, key: VirtualKeyCode) -> bool { for binding in self.key_bindings { if binding.is_triggered_by(self.ctx.terminal_mode(), mods, &key) { // binding was triggered; run the action @@ -605,7 +605,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { /// for its action to be executed. /// /// Returns true if an action is executed. - fn process_mouse_bindings(&mut self, mods: &ModifiersState, button: MouseButton) -> bool { + fn process_mouse_bindings(&mut self, mods: ModifiersState, button: MouseButton) -> bool { for binding in self.mouse_bindings { if binding.is_triggered_by(self.ctx.terminal_mode(), mods, &button) { // binding was triggered; run the action @@ -782,9 +782,9 @@ mod tests { #[test] fn $name() { if $triggers { - assert!($binding.is_triggered_by($mode, &$mods, &KEY)); + assert!($binding.is_triggered_by($mode, $mods, &KEY)); } else { - assert!(!$binding.is_triggered_by($mode, &$mods, &KEY)); + assert!(!$binding.is_triggered_by($mode, $mods, &KEY)); } } } diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index 0d474123..b006f566 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -183,7 +183,7 @@ impl GlyphCache { // Need to load at least one glyph for the face before calling metrics. // The glyph requested here ('m' at the time of writing) has no special // meaning. - rasterizer.get_glyph(&GlyphKey { font_key: regular, c: 'm', size: font.size() })?; + rasterizer.get_glyph(GlyphKey { font_key: regular, c: 'm', size: font.size() })?; let metrics = rasterizer.metrics(regular)?; let mut cache = GlyphCache { @@ -211,7 +211,7 @@ impl GlyphCache { ) { let size = self.font_size; for i in RangeInclusive::new(32u8, 128u8) { - self.get(&GlyphKey { + self.get(GlyphKey { font_key: font, c: i as char, size, @@ -273,14 +273,14 @@ impl GlyphCache { .expect("metrics load since font is loaded at glyph cache creation") } - pub fn get<'a, L>(&'a mut self, glyph_key: &GlyphKey, loader: &mut L) -> &'a Glyph + pub fn get<'a, L>(&'a mut self, glyph_key: GlyphKey, loader: &mut L) -> &'a Glyph where L: LoadGlyph { let glyph_offset = self.glyph_offset; let rasterizer = &mut self.rasterizer; let metrics = &self.metrics; self.cache - .entry(*glyph_key) + .entry(glyph_key) .or_insert_with(|| { let mut rasterized = rasterizer.get_glyph(glyph_key) .unwrap_or_else(|_| Default::default()); @@ -306,7 +306,7 @@ impl GlyphCache { let font = font.to_owned().with_size(size); info!("Font size changed: {:?}", font.size); let (regular, bold, italic) = Self::compute_font_keys(&font, &mut self.rasterizer)?; - self.rasterizer.get_glyph(&GlyphKey { font_key: regular, c: 'm', size: font.size() })?; + self.rasterizer.get_glyph(GlyphKey { font_key: regular, c: 'm', size: font.size() })?; let metrics = self.rasterizer.metrics(regular)?; self.font_size = font.size; @@ -842,7 +842,7 @@ impl<'a> RenderApi<'a> { // Add cell to batch { - let glyph = glyph_cache.get(&glyph_key, self); + let glyph = glyph_cache.get(glyph_key, self); self.add_render_item(&cell, glyph); } @@ -856,7 +856,7 @@ impl<'a> RenderApi<'a> { c: '_' }; - let underscore = glyph_cache.get(&glyph_key, self); + let underscore = glyph_cache.get(glyph_key, self); self.add_render_item(&cell, underscore); } } diff --git a/src/selection.rs b/src/selection.rs index cd905164..ae584025 100644 --- a/src/selection.rs +++ b/src/selection.rs @@ -152,7 +152,7 @@ impl Selection { Selection::Semantic { ref region, ref initial_expansion } => { Selection::span_semantic(grid, region, initial_expansion) }, - Selection::Lines { ref region, ref initial_line } => { + Selection::Lines { ref region, initial_line } => { Selection::span_lines(grid, region, initial_line) } } @@ -192,18 +192,18 @@ impl Selection { }) } - fn span_lines(grid: &G, region: &Region, initial_line: &Line) -> Option + fn span_lines(grid: &G, region: &Region, initial_line: Line) -> Option where G: Dimensions { // First, create start and end points based on initial line and the grid // dimensions. let mut start = Point { col: Column(0), - line: *initial_line + line: initial_line }; let mut end = Point { col: grid.dimensions().col - 1, - line: *initial_line + line: initial_line }; // Now, expand lines based on where cursor started and ended. diff --git a/src/term/mod.rs b/src/term/mod.rs index 27cc9312..d1f48c91 100644 --- a/src/term/mod.rs +++ b/src/term/mod.rs @@ -269,9 +269,9 @@ impl<'a> RenderableCellsIter<'a> { self.mode.contains(mode::TermMode::SHOW_CURSOR) && self.grid.contains(self.cursor) } - fn compute_fg_rgb(&self, fg: &Color, cell: &Cell) -> Rgb { + fn compute_fg_rgb(&self, fg: Color, cell: &Cell) -> Rgb { use self::cell::Flags; - match *fg { + match fg { Color::Spec(rgb) => rgb, Color::Named(ansi) => { match (self.config.draw_bold_text_with_bright_colors(), cell.flags & Flags::DIM_BOLD) { @@ -302,15 +302,15 @@ impl<'a> RenderableCellsIter<'a> { } #[inline] - fn compute_bg_alpha(&self, bg: &Color) -> f32 { - match *bg { + fn compute_bg_alpha(&self, bg: Color) -> f32 { + match bg { Color::Named(NamedColor::Background) => 0.0, _ => 1.0 } } - fn compute_bg_rgb(&self, bg: &Color) -> Rgb { - match *bg { + fn compute_bg_rgb(&self, bg: Color) -> Rgb { + match bg { Color::Spec(rgb) => rgb, Color::Named(ansi) => self.colors[ansi], Color::Indexed(idx) => self.colors[idx], @@ -387,13 +387,13 @@ impl<'a> Iterator for RenderableCellsIter<'a> { fg_rgb = self.colors[NamedColor::Background]; bg_alpha = 1.0 } else { - bg_rgb = self.compute_fg_rgb(&cell.fg, &cell); - fg_rgb = self.compute_bg_rgb(&cell.bg); + bg_rgb = self.compute_fg_rgb(cell.fg, &cell); + fg_rgb = self.compute_bg_rgb(cell.bg); } } else { - fg_rgb = self.compute_fg_rgb(&cell.fg, &cell); - bg_rgb = self.compute_bg_rgb(&cell.bg); - bg_alpha = self.compute_bg_alpha(&cell.bg); + fg_rgb = self.compute_fg_rgb(cell.fg, &cell); + bg_rgb = self.compute_bg_rgb(cell.bg); + bg_alpha = self.compute_bg_alpha(cell.bg); } return Some(RenderableCell {