Fix clippy issues

This commit is contained in:
Christian Duerr 2018-07-01 16:31:46 +00:00 committed by GitHub
parent d5690f6cc7
commit 12afbd007d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 64 additions and 64 deletions

View File

@ -162,7 +162,7 @@ impl ::Rasterize for Rasterizer {
} }
/// Get rasterized glyph for given glyph key /// Get rasterized glyph for given glyph key
fn get_glyph(&mut self, glyph: &GlyphKey) -> Result<RasterizedGlyph, Error> { fn get_glyph(&mut self, glyph: GlyphKey) -> Result<RasterizedGlyph, Error> {
// get loaded font // get loaded font
let font = self.fonts 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. // Helper to try and get a glyph for a given font. Used for font fallback.
fn maybe_get_glyph( fn maybe_get_glyph(
&self, &self,
glyph: &GlyphKey, glyph: GlyphKey,
font: &Font, font: &Font,
) -> Option<Result<RasterizedGlyph, Error>> { ) -> Option<Result<RasterizedGlyph, Error>> {
let scaled_size = self.device_pixel_ratio * glyph.size.as_f32_pts(); 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); let menlo = ct_new_from_descriptor(&descriptor.ct_descriptor, size);
// TODO fixme, hardcoded en for english // 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() .into_iter()
.filter(|desc| desc.font_path != "") .filter(|desc| desc.font_path != "")
.map(|desc| desc.to_font(size, false)) .map(|desc| desc.to_font(size, false))

View File

@ -180,9 +180,9 @@ pub enum Width {
} }
impl Width { impl Width {
fn to_isize(&self) -> isize { fn to_isize(self) -> isize {
use self::Width::*; use self::Width::*;
match *self { match self {
Ultracondensed => 50, Ultracondensed => 50,
Extracondensed => 63, Extracondensed => 63,
Condensed => 75, Condensed => 75,

View File

@ -102,7 +102,7 @@ impl ::Rasterize for FreeTypeRasterizer {
self.get_face(desc, size) self.get_face(desc, size)
} }
fn get_glyph(&mut self, glyph_key: &GlyphKey) -> Result<RasterizedGlyph, Error> { fn get_glyph(&mut self, glyph_key: GlyphKey) -> Result<RasterizedGlyph, Error> {
self.get_rendered_glyph(glyph_key) 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<FontKey, Error> { fn face_for_glyph(&mut self, glyph_key: GlyphKey, have_recursed: bool) -> Result<FontKey, Error> {
let c = glyph_key.c; let c = glyph_key.c;
let use_initial_face = if self.faces.contains_key(&glyph_key.font_key) { 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<RasterizedGlyph, Error> { -> Result<RasterizedGlyph, Error> {
// Render a custom symbol for the underline and beam cursor // Render a custom symbol for the underline and beam cursor
match glyph_key.c { match glyph_key.c {

View File

@ -344,5 +344,5 @@ pub trait Rasterize {
fn load_font(&mut self, &FontDesc, Size) -> Result<FontKey, Self::Err>; fn load_font(&mut self, &FontDesc, Size) -> Result<FontKey, Self::Err>;
/// Rasterize the glyph described by `GlyphKey`. /// Rasterize the glyph described by `GlyphKey`.
fn get_glyph(&mut self, &GlyphKey) -> Result<RasterizedGlyph, Self::Err>; fn get_glyph(&mut self, GlyphKey) -> Result<RasterizedGlyph, Self::Err>;
} }

View File

@ -561,8 +561,8 @@ pub enum NamedColor {
} }
impl NamedColor { impl NamedColor {
pub fn to_bright(&self) -> Self { pub fn to_bright(self) -> Self {
match *self { match self {
NamedColor::Black => NamedColor::BrightBlack, NamedColor::Black => NamedColor::BrightBlack,
NamedColor::Red => NamedColor::BrightRed, NamedColor::Red => NamedColor::BrightRed,
NamedColor::Green => NamedColor::BrightGreen, NamedColor::Green => NamedColor::BrightGreen,
@ -583,8 +583,8 @@ impl NamedColor {
} }
} }
pub fn to_dim(&self) -> Self { pub fn to_dim(self) -> Self {
match *self { match self {
NamedColor::Black => NamedColor::DimBlack, NamedColor::Black => NamedColor::DimBlack,
NamedColor::Red => NamedColor::DimRed, NamedColor::Red => NamedColor::DimRed,
NamedColor::Green => NamedColor::DimGreen, NamedColor::Green => NamedColor::DimGreen,

View File

@ -242,7 +242,7 @@ impl Alpha {
} }
#[inline] #[inline]
pub fn get(&self) -> f32 { pub fn get(self) -> f32 {
self.0 self.0
} }
@ -1925,10 +1925,10 @@ enum Key {
} }
impl Key { impl Key {
fn to_glutin_key(&self) -> ::glutin::VirtualKeyCode { fn to_glutin_key(self) -> ::glutin::VirtualKeyCode {
use ::glutin::VirtualKeyCode::*; use ::glutin::VirtualKeyCode::*;
// Thank you, vim macros! // Thank you, vim macros!
match *self { match self {
Key::Key1 => Key1, Key::Key1 => Key1,
Key::Key2 => Key2, Key::Key2 => Key2,
Key::Key3 => Key3, Key::Key3 => Key3,

View File

@ -291,7 +291,7 @@ impl<N: Notify> Processor<N> {
}, },
KeyboardInput { input, .. } => { KeyboardInput { input, .. } => {
let glutin::KeyboardInput { state, virtual_keycode, modifiers, .. } = 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 { if state == ElementState::Pressed {
// Hide cursor while typing // Hide cursor while typing
*hide_cursor = true; *hide_cursor = true;

View File

@ -270,7 +270,7 @@ macro_rules! inclusive {
match *self { match *self {
Empty { .. } => (0, Some(0)), Empty { .. } => (0, Some(0)),
NonEmpty { ref start, ref end } => { NonEmpty { start, end } => {
let added = $steps_add_one(start, end); let added = $steps_add_one(start, end);
match added { match added {
Some(hint) => (hint.saturating_add(1), hint.checked_add(1)), 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<usize> { fn steps_add_one_u8(start: u8, end: u8) -> Option<usize> {
if *start < *end { if start < end {
Some((*end - *start) as usize) Some((end - start) as usize)
} else { } else {
None None
} }
@ -330,11 +330,11 @@ macro_rules! ops {
impl $ty { impl $ty {
#[inline] #[inline]
#[allow(trivial_numeric_casts)] #[allow(trivial_numeric_casts)]
fn steps_between(start: &$ty, end: &$ty, by: &$ty) -> Option<usize> { fn steps_between(start: $ty, end: $ty, by: $ty) -> Option<usize> {
if *by == $construct(0) { return None; } if by == $construct(0) { return None; }
if *start < *end { if start < end {
// Note: We assume $t <= usize here // Note: We assume $t <= usize here
let diff = (*end - *start).0; let diff = (end - start).0;
let by = by.0; let by = by.0;
if diff % by > 0 { if diff % by > 0 {
Some(diff / by + 1) Some(diff / by + 1)
@ -347,8 +347,8 @@ macro_rules! ops {
} }
#[inline] #[inline]
fn steps_between_by_one(start: &$ty, end: &$ty) -> Option<usize> { fn steps_between_by_one(start: $ty, end: $ty) -> Option<usize> {
Self::steps_between(start, end, &$construct(1)) Self::steps_between(start, end, $construct(1))
} }
} }
@ -366,7 +366,7 @@ macro_rules! ops {
} }
#[inline] #[inline]
fn size_hint(&self) -> (usize, Option<usize>) { fn size_hint(&self) -> (usize, Option<usize>) {
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)), Some(hint) => (hint, Some(hint)),
None => (0, None) None => (0, None)
} }

View File

@ -102,15 +102,15 @@ impl<T: Eq> Binding<T> {
fn is_triggered_by( fn is_triggered_by(
&self, &self,
mode: TermMode, mode: TermMode,
mods: &ModifiersState, mods: ModifiersState,
input: &T input: &T
) -> bool { ) -> bool {
// Check input first since bindings are stored in one big list. This is // 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 // the most likely item to fail so prioritizing it here allows more
// checks to be short circuited. // checks to be short circuited.
self.trigger == *input && self.trigger == *input &&
self.mode_matches(&mode) && self.mode_matches(mode) &&
self.not_mode_matches(&mode) && self.not_mode_matches(mode) &&
self.mods_match(mods) self.mods_match(mods)
} }
} }
@ -123,12 +123,12 @@ impl<T> Binding<T> {
} }
#[inline] #[inline]
fn mode_matches(&self, mode: &TermMode) -> bool { fn mode_matches(&self, mode: TermMode) -> bool {
self.mode.is_empty() || mode.intersects(self.mode) self.mode.is_empty() || mode.intersects(self.mode)
} }
#[inline] #[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) self.notmode.is_empty() || !mode.intersects(self.notmode)
} }
@ -136,10 +136,10 @@ impl<T> Binding<T> {
/// ///
/// Optimized to use single check instead of four (one per modifier) /// Optimized to use single check instead of four (one per modifier)
#[inline] #[inline]
fn mods_match(&self, mods: &ModifiersState) -> bool { fn mods_match(&self, mods: ModifiersState) -> bool {
debug_assert!(4 == mem::size_of::<ModifiersState>()); debug_assert!(4 == mem::size_of::<ModifiersState>());
unsafe { 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; return;
} }
self.process_mouse_bindings(&ModifiersState::default(), button); self.process_mouse_bindings(ModifiersState::default(), button);
} }
/// Process key input /// Process key input
@ -542,11 +542,11 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
&mut self, &mut self,
state: ElementState, state: ElementState,
key: Option<VirtualKeyCode>, key: Option<VirtualKeyCode>,
mods: &ModifiersState, mods: ModifiersState,
) { ) {
match (key, state) { match (key, state) {
(Some(key), ElementState::Pressed) => { (Some(key), ElementState::Pressed) => {
*self.ctx.last_modifiers() = *mods; *self.ctx.last_modifiers() = mods;
*self.ctx.received_count() = 0; *self.ctx.received_count() = 0;
*self.ctx.suppress_chars() = false; *self.ctx.suppress_chars() = false;
@ -587,7 +587,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
/// for its action to be executed. /// for its action to be executed.
/// ///
/// Returns true if an action is 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 { for binding in self.key_bindings {
if binding.is_triggered_by(self.ctx.terminal_mode(), mods, &key) { if binding.is_triggered_by(self.ctx.terminal_mode(), mods, &key) {
// binding was triggered; run the action // binding was triggered; run the action
@ -605,7 +605,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
/// for its action to be executed. /// for its action to be executed.
/// ///
/// Returns true if an action is 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 { for binding in self.mouse_bindings {
if binding.is_triggered_by(self.ctx.terminal_mode(), mods, &button) { if binding.is_triggered_by(self.ctx.terminal_mode(), mods, &button) {
// binding was triggered; run the action // binding was triggered; run the action
@ -782,9 +782,9 @@ mod tests {
#[test] #[test]
fn $name() { fn $name() {
if $triggers { if $triggers {
assert!($binding.is_triggered_by($mode, &$mods, &KEY)); assert!($binding.is_triggered_by($mode, $mods, &KEY));
} else { } else {
assert!(!$binding.is_triggered_by($mode, &$mods, &KEY)); assert!(!$binding.is_triggered_by($mode, $mods, &KEY));
} }
} }
} }

View File

@ -183,7 +183,7 @@ impl GlyphCache {
// Need to load at least one glyph for the face before calling metrics. // 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 // The glyph requested here ('m' at the time of writing) has no special
// meaning. // 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 metrics = rasterizer.metrics(regular)?;
let mut cache = GlyphCache { let mut cache = GlyphCache {
@ -211,7 +211,7 @@ impl GlyphCache {
) { ) {
let size = self.font_size; let size = self.font_size;
for i in RangeInclusive::new(32u8, 128u8) { for i in RangeInclusive::new(32u8, 128u8) {
self.get(&GlyphKey { self.get(GlyphKey {
font_key: font, font_key: font,
c: i as char, c: i as char,
size, size,
@ -273,14 +273,14 @@ impl GlyphCache {
.expect("metrics load since font is loaded at glyph cache creation") .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 where L: LoadGlyph
{ {
let glyph_offset = self.glyph_offset; let glyph_offset = self.glyph_offset;
let rasterizer = &mut self.rasterizer; let rasterizer = &mut self.rasterizer;
let metrics = &self.metrics; let metrics = &self.metrics;
self.cache self.cache
.entry(*glyph_key) .entry(glyph_key)
.or_insert_with(|| { .or_insert_with(|| {
let mut rasterized = rasterizer.get_glyph(glyph_key) let mut rasterized = rasterizer.get_glyph(glyph_key)
.unwrap_or_else(|_| Default::default()); .unwrap_or_else(|_| Default::default());
@ -306,7 +306,7 @@ impl GlyphCache {
let font = font.to_owned().with_size(size); let font = font.to_owned().with_size(size);
info!("Font size changed: {:?}", font.size); info!("Font size changed: {:?}", font.size);
let (regular, bold, italic) = Self::compute_font_keys(&font, &mut self.rasterizer)?; 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)?; let metrics = self.rasterizer.metrics(regular)?;
self.font_size = font.size; self.font_size = font.size;
@ -842,7 +842,7 @@ impl<'a> RenderApi<'a> {
// Add cell to batch // 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); self.add_render_item(&cell, glyph);
} }
@ -856,7 +856,7 @@ impl<'a> RenderApi<'a> {
c: '_' c: '_'
}; };
let underscore = glyph_cache.get(&glyph_key, self); let underscore = glyph_cache.get(glyph_key, self);
self.add_render_item(&cell, underscore); self.add_render_item(&cell, underscore);
} }
} }

View File

@ -152,7 +152,7 @@ impl Selection {
Selection::Semantic { ref region, ref initial_expansion } => { Selection::Semantic { ref region, ref initial_expansion } => {
Selection::span_semantic(grid, region, 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) Selection::span_lines(grid, region, initial_line)
} }
} }
@ -192,18 +192,18 @@ impl Selection {
}) })
} }
fn span_lines<G>(grid: &G, region: &Region<Point>, initial_line: &Line) -> Option<Span> fn span_lines<G>(grid: &G, region: &Region<Point>, initial_line: Line) -> Option<Span>
where G: Dimensions where G: Dimensions
{ {
// First, create start and end points based on initial line and the grid // First, create start and end points based on initial line and the grid
// dimensions. // dimensions.
let mut start = Point { let mut start = Point {
col: Column(0), col: Column(0),
line: *initial_line line: initial_line
}; };
let mut end = Point { let mut end = Point {
col: grid.dimensions().col - 1, col: grid.dimensions().col - 1,
line: *initial_line line: initial_line
}; };
// Now, expand lines based on where cursor started and ended. // Now, expand lines based on where cursor started and ended.

View File

@ -269,9 +269,9 @@ impl<'a> RenderableCellsIter<'a> {
self.mode.contains(mode::TermMode::SHOW_CURSOR) && self.grid.contains(self.cursor) 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; use self::cell::Flags;
match *fg { match fg {
Color::Spec(rgb) => rgb, Color::Spec(rgb) => rgb,
Color::Named(ansi) => { Color::Named(ansi) => {
match (self.config.draw_bold_text_with_bright_colors(), cell.flags & Flags::DIM_BOLD) { match (self.config.draw_bold_text_with_bright_colors(), cell.flags & Flags::DIM_BOLD) {
@ -302,15 +302,15 @@ impl<'a> RenderableCellsIter<'a> {
} }
#[inline] #[inline]
fn compute_bg_alpha(&self, bg: &Color) -> f32 { fn compute_bg_alpha(&self, bg: Color) -> f32 {
match *bg { match bg {
Color::Named(NamedColor::Background) => 0.0, Color::Named(NamedColor::Background) => 0.0,
_ => 1.0 _ => 1.0
} }
} }
fn compute_bg_rgb(&self, bg: &Color) -> Rgb { fn compute_bg_rgb(&self, bg: Color) -> Rgb {
match *bg { match bg {
Color::Spec(rgb) => rgb, Color::Spec(rgb) => rgb,
Color::Named(ansi) => self.colors[ansi], Color::Named(ansi) => self.colors[ansi],
Color::Indexed(idx) => self.colors[idx], Color::Indexed(idx) => self.colors[idx],
@ -387,13 +387,13 @@ impl<'a> Iterator for RenderableCellsIter<'a> {
fg_rgb = self.colors[NamedColor::Background]; fg_rgb = self.colors[NamedColor::Background];
bg_alpha = 1.0 bg_alpha = 1.0
} else { } else {
bg_rgb = self.compute_fg_rgb(&cell.fg, &cell); bg_rgb = self.compute_fg_rgb(cell.fg, &cell);
fg_rgb = self.compute_bg_rgb(&cell.bg); fg_rgb = self.compute_bg_rgb(cell.bg);
} }
} else { } else {
fg_rgb = self.compute_fg_rgb(&cell.fg, &cell); fg_rgb = self.compute_fg_rgb(cell.fg, &cell);
bg_rgb = self.compute_bg_rgb(&cell.bg); bg_rgb = self.compute_bg_rgb(cell.bg);
bg_alpha = self.compute_bg_alpha(&cell.bg); bg_alpha = self.compute_bg_alpha(cell.bg);
} }
return Some(RenderableCell { return Some(RenderableCell {