diff --git a/src/clipboard/x11.rs b/src/clipboard/x11.rs index ea2195a44..a9bff973d 100644 --- a/src/clipboard/x11.rs +++ b/src/clipboard/x11.rs @@ -1,5 +1,5 @@ //! Interface with the X11 clipboard/selection -//! Check out https://tronche.com/gui/x/icccm/sec-2.html for some deep and complex +//! Check out for some deep and complex //! background on what's happening in here. use failure::{self, Error}; use glium::glutin::WindowId; @@ -74,7 +74,7 @@ impl Inner { let screen = setup .roots() .nth(screen as usize) - .ok_or(failure::err_msg("no screen?"))?; + .ok_or_else(|| failure::err_msg("no screen?"))?; xcb::create_window_checked( &conn, @@ -212,7 +212,7 @@ impl Inner { // We don't and won't do any conversion from UTF-8 to // whatever STRING represents; let's just assume that // the other end is going to handle it correctly. - if let &Some(ref text) = &self.owned { + if let Some(ref text) = self.owned { debug!("going to respond with clip text because we own it"); xcb::xproto::change_property( &self.conn, @@ -254,12 +254,12 @@ impl Inner { Ok(()) } - fn process_xcb_event(&mut self, event: xcb::GenericEvent) -> Result<(), Error> { + fn process_xcb_event(&mut self, event: &xcb::GenericEvent) -> Result<(), Error> { match event.response_type() & 0x7f { xcb::SELECTION_CLEAR => self.selection_clear(), - xcb::SELECTION_NOTIFY => self.selection_notify(unsafe { xcb::cast_event(&event) }), + xcb::SELECTION_NOTIFY => self.selection_notify(unsafe { xcb::cast_event(event) }), - xcb::SELECTION_REQUEST => self.selection_request(unsafe { xcb::cast_event(&event) }), + xcb::SELECTION_REQUEST => self.selection_request(unsafe { xcb::cast_event(event) }), xcb::MAPPING_NOTIFY => { // Nothing to do here; just don't want to print an error // in the case below. @@ -284,7 +284,7 @@ impl Inner { bail!("clipboard window connection is broken: {:?}", err); } }, - Some(event) => match self.process_xcb_event(event) { + Some(event) => match self.process_xcb_event(&event) { Ok(_) => (), Err(err) => return Err(err), }, @@ -294,7 +294,7 @@ impl Inner { loop { match self.conn.poll_for_queued_event() { None => return Ok(()), - Some(event) => self.process_xcb_event(event)?, + Some(event) => self.process_xcb_event(&event)?, } self.conn.flush(); } @@ -359,25 +359,21 @@ impl Inner { match poll.poll(&mut events, None) { Ok(_) => for event in &events { if event.token() == Token(0) { - match self.process_queued_xcb() { - Err(err) => { - eprintln!("clipboard: {:?}", err); - return; - } - _ => (), + if let Err(err) = self.process_queued_xcb() { + eprintln!("clipboard: {:?}", err); + return; } } if event.token() == Token(1) { - match self.process_receiver() { + if let Err(err) = self.process_receiver() { // No need to print the error trace if we were shutdown gracefully - Err(err) => match err.downcast_ref::() { + match err.downcast_ref::() { Some(_) => return, _ => { eprintln!("clipboard: {:?}", err); return; } - }, - _ => (), + } } self.conn.flush(); } @@ -414,7 +410,7 @@ impl ClipboardImpl for Clipboard { // Make sure that it started up ok match receiver_paste.recv_timeout(Duration::from_secs(10)) { Ok(Paste::Running) => {} - other @ _ => bail!("failed to init clipboard window: {:?}", other), + other => bail!("failed to init clipboard window: {:?}", other), }; Ok(Self { @@ -434,9 +430,9 @@ impl ClipboardImpl for Clipboard { fn get_clipboard(&self) -> Result { self.sender.send(ClipRequest::RequestClipboard)?; match self.receiver.recv_timeout(Duration::from_secs(10)) { - Ok(Paste::All(result)) => return Ok(result), - Ok(Paste::Cleared) => return Ok("".into()), - other @ _ => bail!("unexpected result while waiting for paste: {:?}", other), + Ok(Paste::All(result)) => Ok(result), + Ok(Paste::Cleared) => Ok("".into()), + other => bail!("unexpected result while waiting for paste: {:?}", other), } } @@ -452,11 +448,8 @@ impl ClipboardImpl for Clipboard { impl Drop for Clipboard { fn drop(&mut self) { self.sender.send(ClipRequest::Terminate).ok(); - match self.clip_thread.take() { - Some(thread) => { - thread.join().ok(); - } - None => {} + if let Some(thread) = self.clip_thread.take() { + thread.join().ok(); } } } diff --git a/src/config.rs b/src/config.rs index 67438346e..5bfeadbb3 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,6 +1,6 @@ //! Configuration for the gui portion of the terminal -use failure::Error; +use failure::{err_msg, Error}; use std; use std::fs; use std::io::prelude::*; @@ -120,8 +120,8 @@ impl TextStyle { } } -/// Defines a rule that can be used to select a TextStyle given -/// an input CellAttributes value. The logic that applies the +/// Defines a rule that can be used to select a `TextStyle` given +/// an input `CellAttributes` value. The logic that applies the /// matching can be found in src/font/mod.rs. The concept is that /// the user can specify something like this: /// @@ -131,7 +131,7 @@ impl TextStyle { /// font = { fontconfig_pattern = "Operator Mono SSm Lig:style=Italic" } /// ``` /// -/// The above is translated as: "if the CellAttributes have the italic bit +/// The above is translated as: "if the `CellAttributes` have the italic bit /// set, then use the italic style of font rather than the default", and /// stop processing further font rules. #[derive(Debug, Default, Deserialize, Clone)] @@ -166,14 +166,14 @@ pub struct StyleRule { impl Config { pub fn load() -> Result { - let home = std::env::home_dir().ok_or_else(|| format_err!("can't find home dir"))?; + let home = std::env::home_dir().ok_or_else(|| err_msg("can't find home dir"))?; let paths = [ home.join(".config").join("wezterm").join("wezterm.toml"), home.join(".wezterm.toml"), ]; - for p in paths.iter() { + for p in &paths { let mut file = match fs::File::open(p) { Ok(file) => file, Err(err) => match err.kind() { @@ -198,7 +198,7 @@ impl Config { fn compute_extra_defaults(&self) -> Self { let mut cfg = self.clone(); - if cfg.font_rules.len() == 0 { + if cfg.font_rules.is_empty() { // Expand out some reasonable default font rules let bold = self.font.make_bold(); let italic = self.font.make_italic(); diff --git a/src/font/fcwrap.rs b/src/font/fcwrap.rs index f20fd2d2c..464b13a6d 100644 --- a/src/font/fcwrap.rs +++ b/src/font/fcwrap.rs @@ -49,7 +49,7 @@ impl<'a> Iterator for FontSetIter<'a> { impl FontSet { pub fn iter(&self) -> FontSetIter { FontSetIter { - set: &self, + set: self, position: 0, } } diff --git a/src/font/fontconfigandfreetype.rs b/src/font/fontconfigandfreetype.rs index 4570560d0..86d42d6ef 100644 --- a/src/font/fontconfigandfreetype.rs +++ b/src/font/fontconfigandfreetype.rs @@ -51,7 +51,7 @@ impl Font for FontImpl { } fn has_color(&self) -> bool { let face = self.face.borrow(); - unsafe { ((*face.face).face_flags & ftwrap::FT_FACE_FLAG_COLOR as i64) != 0 } + unsafe { ((*face.face).face_flags & i64::from(ftwrap::FT_FACE_FLAG_COLOR)) != 0 } } fn metrics(&self) -> FontMetrics { @@ -88,7 +88,7 @@ impl Font for FontImpl { let ft_glyph = face.load_and_render_glyph(glyph_pos, load_flags, render_mode)?; let mode: ftwrap::FT_Pixel_Mode = - unsafe { mem::transmute(ft_glyph.bitmap.pixel_mode as u32) }; + unsafe { mem::transmute(u32::from(ft_glyph.bitmap.pixel_mode)) }; // pitch is the number of bytes per source row let pitch = ft_glyph.bitmap.pitch.abs() as usize; @@ -110,11 +110,11 @@ impl Font for FontImpl { let src_offset = y * pitch as usize; let dest_offset = y * width * 4; for x in 0..width { - let blue = data[src_offset + (x * 3) + 0]; + let blue = data[src_offset + (x * 3)]; let green = data[src_offset + (x * 3) + 1]; let red = data[src_offset + (x * 3) + 2]; let alpha = red | green | blue; - rgba[dest_offset + (x * 4) + 0] = red; + rgba[dest_offset + (x * 4)] = red; rgba[dest_offset + (x * 4) + 1] = green; rgba[dest_offset + (x * 4) + 2] = blue; rgba[dest_offset + (x * 4) + 3] = alpha; @@ -139,12 +139,12 @@ impl Font for FontImpl { let src_offset = y * pitch as usize; let dest_offset = y * width * 4; for x in 0..width { - let blue = data[src_offset + (x * 4) + 0]; + let blue = data[src_offset + (x * 4)]; let green = data[src_offset + (x * 4) + 1]; let red = data[src_offset + (x * 4) + 2]; let alpha = data[src_offset + (x * 4) + 3]; - rgba[dest_offset + (x * 4) + 0] = red; + rgba[dest_offset + (x * 4)] = red; rgba[dest_offset + (x * 4) + 1] = green; rgba[dest_offset + (x * 4) + 2] = blue; rgba[dest_offset + (x * 4) + 3] = alpha; @@ -170,7 +170,7 @@ impl Font for FontImpl { for x in 0..width { let gray = data[src_offset + x]; - rgba[dest_offset + (x * 4) + 0] = gray; + rgba[dest_offset + (x * 4)] = gray; rgba[dest_offset + (x * 4) + 1] = gray; rgba[dest_offset + (x * 4) + 2] = gray; rgba[dest_offset + (x * 4) + 3] = gray; @@ -208,7 +208,7 @@ impl Font for FontImpl { rgba[dest_offset + (x * 4) + j] = 0xff; } } - b = b << 1; + b <<= 1; x += 1; } } @@ -221,7 +221,7 @@ impl Font for FontImpl { bearing_y: ft_glyph.bitmap_top, } } - mode @ _ => bail!("unhandled pixel mode: {:?}", mode), + mode => bail!("unhandled pixel mode: {:?}", mode), }; Ok(glyph) } @@ -288,7 +288,7 @@ impl NamedFontImpl { let pat = self.font_list .iter() .nth(idx) - .ok_or(failure::err_msg("no more fallbacks"))?; + .ok_or_else(|| failure::err_msg("no more fallbacks"))?; let pat = self.pattern.render_prepare(&pat)?; let file = pat.get_file()?; @@ -304,26 +304,23 @@ impl NamedFontImpl { let mut face = self.lib.new_face(file, 0)?; - match face.set_char_size(size, size, dpi, dpi) { - Err(err) => { - let sizes = unsafe { - let rec = &(*face.face); - slice::from_raw_parts(rec.available_sizes, rec.num_fixed_sizes as usize) - }; - if sizes.len() == 0 { - return Err(err); - } else { - // Find the best matching size. - // We just take the biggest. - let mut size = 0i16; - for info in sizes.iter() { - size = size.max(info.height); - } - face.set_pixel_sizes(size as u32, size as u32)?; - debug!("fall back to set_pixel_sizes {}", size); + if let Err(err) = face.set_char_size(size, size, dpi, dpi) { + let sizes = unsafe { + let rec = &(*face.face); + slice::from_raw_parts(rec.available_sizes, rec.num_fixed_sizes as usize) + }; + if sizes.is_empty() { + return Err(err); + } else { + // Find the best matching size. + // We just take the biggest. + let mut size = 0i16; + for info in sizes.iter() { + size = size.max(info.height); } + face.set_pixel_sizes(size as u32, size as u32)?; + debug!("fall back to set_pixel_sizes {}", size); } - Ok(_) => {} } let font = harfbuzz::Font::new(face.face); diff --git a/src/font/ftwrap.rs b/src/font/ftwrap.rs index 7ccdcf014..f9909b5d0 100644 --- a/src/font/ftwrap.rs +++ b/src/font/ftwrap.rs @@ -76,8 +76,8 @@ impl Face { pub fn cell_metrics(&mut self) -> (f64, f64) { unsafe { let metrics = &(*(*self.face).size).metrics; - let height = - (metrics.y_scale as f64 * (*self.face).height as f64) / (0x10000 as f64 * 64.0); + let height = (metrics.y_scale as f64 * f64::from((*self.face).height)) + / (f64::from(0x1_0000) * 64.0); let mut width = 0.0; for i in 32..128 { diff --git a/src/font/mod.rs b/src/font/mod.rs index f475dc835..039478ec7 100644 --- a/src/font/mod.rs +++ b/src/font/mod.rs @@ -27,10 +27,12 @@ use self::coretext::FontSystemImpl; use super::config::{Config, TextStyle}; use term::CellAttributes; +type FontPtr = Rc>>; + /// Matches and loads fonts for a given input style pub struct FontConfiguration { config: Config, - fonts: RefCell>>>>, + fonts: RefCell>, system: FontSystemImpl, } @@ -83,7 +85,7 @@ impl FontConfiguration { } }; - for rule in self.config.font_rules.iter() { + for rule in &self.config.font_rules { attr_match!(intensity, &rule); attr_match!(underline, &rule); attr_match!(italic, &rule); @@ -179,16 +181,16 @@ pub fn shape_with_harfbuzz( // Start of a run that needs fallback first_fallback_pos = Some(pos); } - } else if let Some(start) = first_fallback_pos { + } else if let Some(start_pos) = first_fallback_pos { // End of a fallback run //debug!("range: {:?}-{:?} needs fallback", start, pos); - let substr = &s[start..pos]; + let substr = &s[start_pos..pos]; let mut shape = shape_with_harfbuzz(font, font_idx + 1, substr)?; // Fixup the cluster member to match our current offset - for info in shape.iter_mut() { - info.cluster += start as u32; + for mut info in &mut shape { + info.cluster += start_pos as u32; } cluster.append(&mut shape); @@ -203,20 +205,20 @@ pub fn shape_with_harfbuzz( // Check to see if we started and didn't finish a // fallback run. - if let Some(start) = first_fallback_pos { - let substr = &s[start..]; + if let Some(start_pos) = first_fallback_pos { + let substr = &s[start_pos..]; if false { debug!( "at end {:?}-{:?} needs fallback {}", - start, + start_pos, s.len() - 1, substr, ); } let mut shape = shape_with_harfbuzz(font, font_idx + 1, substr)?; // Fixup the cluster member to match our current offset - for info in shape.iter_mut() { - info.cluster += start as u32; + for mut info in &mut shape { + info.cluster += start_pos as u32; } cluster.append(&mut shape); } diff --git a/src/font/system.rs b/src/font/system.rs index fb69c1e38..e5d4b16bf 100644 --- a/src/font/system.rs +++ b/src/font/system.rs @@ -54,21 +54,21 @@ impl GlyphInfo { font_idx, glyph_pos: info.codepoint, cluster: info.cluster, - x_advance: pos.x_advance as f64 / 64.0, - y_advance: pos.y_advance as f64 / 64.0, - x_offset: pos.x_offset as f64 / 64.0, - y_offset: pos.y_offset as f64 / 64.0, + x_advance: f64::from(pos.x_advance) / 64.0, + y_advance: f64::from(pos.y_advance) / 64.0, + x_offset: f64::from(pos.x_offset) / 64.0, + y_offset: f64::from(pos.y_offset) / 64.0, } } } -/// Represents a numbered index in the fallback sequence for a NamedFont. +/// Represents a numbered index in the fallback sequence for a `NamedFont`. /// 0 is the first, best match. If a glyph isn't present then we will /// want to search for a fallback in later indices. pub type FallbackIdx = usize; /// Represents a named, user-selected font. -/// This is really a set of fallback fonts indexed by FallbackIdx with +/// This is really a set of fallback fonts indexed by `FallbackIdx` with /// zero as the best/most preferred font. pub trait NamedFont { /// Get a reference to a numbered fallback Font instance @@ -78,7 +78,7 @@ pub trait NamedFont { fn shape(&mut self, text: &str) -> Result, Error>; } -/// FontSystem is a handle to the system font selection system +/// `FontSystem` is a handle to the system font selection system pub trait FontSystem { /// Given a text style, load (without caching) the font that /// best matches according to the fontconfig pattern. diff --git a/src/futurecore.rs b/src/futurecore.rs index 93b2d86da..1c183aa17 100644 --- a/src/futurecore.rs +++ b/src/futurecore.rs @@ -90,8 +90,7 @@ impl Core { // spawn-in-run. let mut future = match self.tasks.borrow_mut().get_mut(task_id) { Some(&mut Slot::RunningFuture(ref mut future)) => future.take().unwrap(), - Some(&mut Slot::Vacant { .. }) => return false, - None => return false, + Some(&mut Slot::Vacant { .. }) | None => return false, }; // Drive this future forward. If it's done we remove it and if it's not @@ -110,7 +109,7 @@ impl Core { tasks[task_id] = Slot::RunningFuture(Some(future)); } - return true; + true } } @@ -134,6 +133,6 @@ struct Notifier { impl Notify for Notifier { fn notify(&self, id: usize) { - drop(self.tx.lock().unwrap().send(id)); + self.tx.lock().unwrap().send(id).ok(); } } diff --git a/src/gliumwindows.rs b/src/gliumwindows.rs index cbd98989f..af4c39dd1 100644 --- a/src/gliumwindows.rs +++ b/src/gliumwindows.rs @@ -81,6 +81,7 @@ pub struct TerminalWindow { } impl TerminalWindow { + #[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))] pub fn new( event_loop: &glutin::EventsLoop, paster: GuiSender, @@ -108,7 +109,7 @@ impl TerminalWindow { .with_pixel_format(24, 8) .with_srgb(true); let display = - glium::Display::new(window, context, &event_loop).map_err(|e| format_err!("{:?}", e))?; + glium::Display::new(window, context, event_loop).map_err(|e| format_err!("{:?}", e))?; let window_id = display.gl_window().id(); let host = Host { @@ -160,16 +161,13 @@ impl TerminalWindow { // allocate a newer bigger texture. match res { Err(err) => { - match err.downcast_ref::() { - Some(&OutOfTextureSpace { size }) => { - eprintln!("out of texture space, allocating {}", size); - self.renderer.recreate_atlas(&self.host.display, size)?; - self.terminal.make_all_lines_dirty(); - // Recursively initiate a new paint - return self.paint(); - } - _ => (), - }; + if let Some(&OutOfTextureSpace { size }) = err.downcast_ref::() { + eprintln!("out of texture space, allocating {}", size); + self.renderer.recreate_atlas(&self.host.display, size)?; + self.terminal.make_all_lines_dirty(); + // Recursively initiate a new paint + return self.paint(); + } Err(err) } Ok(_) => Ok(()), @@ -197,8 +195,8 @@ impl TerminalWindow { // simply divide by the scaling factor to have them take up // twice as much space. OpenGL is going to scale things automatically. let scale = self.host.display.gl_window().hidpi_factor(); - let width = (width as f32 / scale) as u16; - let height = (height as f32 / scale) as u16; + let width = (f32::from(width) / scale) as u16; + let height = (f32::from(height) / scale) as u16; if width != self.width || height != self.height { debug!("resize {},{}", width, height); @@ -447,8 +445,7 @@ impl TerminalWindow { V::Down => KeyCode::Down, V::LAlt | V::RAlt => KeyCode::Alt, V::LControl | V::RControl => KeyCode::Control, - V::LMenu | V::RMenu => KeyCode::Super, - V::LShift | V::RShift => KeyCode::Shift, + V::LMenu | V::RMenu | V::LShift | V::RShift => KeyCode::Shift, V::LWin | V::RWin => KeyCode::Super, _ => { eprintln!("unhandled key: {:?}", event); @@ -472,9 +469,9 @@ impl TerminalWindow { Ok(()) } - pub fn dispatch_event(&mut self, event: glutin::Event) -> Result<(), Error> { + pub fn dispatch_event(&mut self, event: &glutin::Event) -> Result<(), Error> { use glium::glutin::{Event, WindowEvent}; - match event { + match *event { Event::WindowEvent { event: WindowEvent::Closed, .. diff --git a/src/main.rs b/src/main.rs index 3c134cc17..fa4e935e2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -137,19 +137,19 @@ impl GuiEventLoop { fn process_gui_event( &self, - event: glium::glutin::Event, + event: &glium::glutin::Event, dead_windows: &mut HashSet, ) -> Result { use glium::glutin::ControlFlow::{Break, Continue}; use glium::glutin::Event; - let result = match event { + let result = match *event { Event::WindowEvent { window_id, .. } => { match self.windows_by_id.borrow_mut().get_mut(&window_id) { Some(window) => match window.dispatch_event(event) { Ok(_) => Continue, Err(err) => match err.downcast_ref::() { Some(_) => { - dead_windows.insert(window_id.clone()); + dead_windows.insert(window_id); Continue } _ => { @@ -182,7 +182,7 @@ impl GuiEventLoop { })?; let mut by_id = self.windows_by_id.borrow_mut(); - let window = by_id.get_mut(&window_id).ok_or_else(|| { + let window = by_id.get_mut(window_id).ok_or_else(|| { format_err!( "fd {} -> window_id {:?} but no associated window is in the windows_by_id map", fd, @@ -268,7 +268,7 @@ impl GuiEventLoop { event_loop.run_forever(|event| { use glium::glutin::ControlFlow::{Break, Continue}; - let result = self.process_gui_event(event, &mut dead_windows); + let result = self.process_gui_event(&event, &mut dead_windows); match result { Ok(Continue) => Continue, diff --git a/src/opengl/render.rs b/src/opengl/render.rs index 76259c505..0ed8b519a 100644 --- a/src/opengl/render.rs +++ b/src/opengl/render.rs @@ -3,7 +3,7 @@ use super::textureatlas::{Atlas, Sprite, SpriteSlice, TEX_SIZE}; use config::TextStyle; use euclid; -use failure::Error; +use failure::{err_msg, Error}; use font::{FontConfiguration, GlyphInfo}; use glium::{self, IndexBuffer, Surface, VertexBuffer}; use glium::backend::Facade; @@ -277,9 +277,9 @@ impl Renderer { (metrics.cell_height, metrics.cell_width, metrics.descender) }; let descender = if descender.is_positive() { - ((descender as f64) / 64.0).ceil() as isize + ((f64::from(descender)) / 64.0).ceil() as isize } else { - ((descender as f64) / 64.0).floor() as isize + ((f64::from(descender)) / 64.0).floor() as isize }; debug!( "METRICS: h={} w={} d={}", @@ -366,8 +366,8 @@ impl Renderer { facade, cell_width as f32, cell_height as f32, - width as f32, - height as f32, + f32::from(width), + f32::from(height), )?; let program = glium::Program::from_source(facade, VERTEX_SHADER, FRAGMENT_SHADER, None)?; @@ -387,7 +387,7 @@ impl Renderer { cell_width, descender, glyph_cache: RefCell::new(HashMap::new()), - projection: Self::compute_projection(width as f32, height as f32), + projection: Self::compute_projection(f32::from(width), f32::from(height)), underline_tex, }) } @@ -404,14 +404,14 @@ impl Renderer { self.width = width; self.height = height; - self.projection = Self::compute_projection(width as f32, height as f32); + self.projection = Self::compute_projection(f32::from(width), f32::from(height)); let (glyph_vertex_buffer, glyph_index_buffer) = Self::compute_vertices( facade, self.cell_width as f32, self.cell_height as f32, - width as f32, - height as f32, + f32::from(width), + f32::from(height), )?; self.glyph_vertex_buffer = RefCell::new(glyph_vertex_buffer); self.glyph_index_buffer = glyph_index_buffer; @@ -451,13 +451,14 @@ impl Renderer { (has_color, glyph, metrics.cell_width, metrics.cell_height) }; - let scale = if (info.x_advance / info.num_cells as f64).floor() > cell_width { - info.num_cells as f64 * (cell_width / info.x_advance) + let scale = if (info.x_advance / f64::from(info.num_cells)).floor() > cell_width { + f64::from(info.num_cells) * (cell_width / info.x_advance) } else if glyph.height as f64 > cell_height { cell_height / glyph.height as f64 } else { 1.0f64 }; + #[cfg_attr(feature = "cargo-clippy", allow(float_cmp))] let (x_offset, y_offset) = if scale != 1.0 { (info.x_offset * scale, info.y_offset * scale) } else { @@ -485,8 +486,8 @@ impl Renderer { .borrow_mut() .allocate(raw_im.width, raw_im.height, raw_im)?; - let bearing_x = (glyph.bearing_x as f64 * scale) as isize; - let bearing_y = (glyph.bearing_y as f64 * scale) as isize; + let bearing_x = (f64::from(glyph.bearing_x) * scale) as isize; + let bearing_y = (f64::from(glyph.bearing_y) * scale) as isize; CachedGlyph { texture: Some(tex), @@ -596,9 +597,9 @@ impl Renderer { let mut vb = self.glyph_vertex_buffer.borrow_mut(); let mut vertices = { let per_line = num_cols * VERTICES_PER_CELL; - let start = line_idx * per_line; - vb.slice_mut(start..start + per_line) - .ok_or_else(|| format_err!("we're confused about the screen size"))? + let start_pos = line_idx * per_line; + vb.slice_mut(start_pos..start_pos + per_line) + .ok_or_else(|| err_msg("we're confused about the screen size"))? .map() }; @@ -632,24 +633,24 @@ impl Renderer { // Shape the printable text from this cluster let glyph_info = { - let font = self.fonts.cached_font(&style)?; + let font = self.fonts.cached_font(style)?; let mut font = font.borrow_mut(); font.shape(&cluster.text)? }; - for info in glyph_info.iter() { + for info in &glyph_info { let cell_idx = cluster.byte_to_cell_idx[info.cluster as usize]; - let glyph = self.cached_glyph(info, &style)?; + let glyph = self.cached_glyph(info, style)?; - let glyph_color = match fg_color { - &term::color::ColorAttribute::Foreground => { + let glyph_color = match *fg_color { + term::color::ColorAttribute::Foreground => { if let Some(fg) = style.foreground { fg } else { self.palette.resolve(fg_color) } } - &term::color::ColorAttribute::PaletteIndex(idx) if idx < 8 => { + term::color::ColorAttribute::PaletteIndex(idx) if idx < 8 => { // For compatibility purposes, switch to a brighter version // of one of the standard ANSI colors when Bold is enabled. // This lifts black to dark grey. @@ -672,6 +673,7 @@ impl Renderer { // Figure out what we're going to draw for the underline. // If the current cell is part of the current URL highlight // then we want to show the underline. + #[cfg_attr(feature = "cargo-clippy", allow(match_same_arms))] let underline: f32 = match ( is_highlited_hyperlink, attrs.strikethrough(), @@ -708,7 +710,7 @@ impl Renderer { let (glyph_color, bg_color) = self.compute_cell_fg_bg( line_idx, cell_idx, - &cursor, + cursor, &selection, glyph_color, bg_color, @@ -732,8 +734,8 @@ impl Renderer { vert[V_BOT_LEFT].underline = underline; vert[V_BOT_RIGHT].underline = underline; - match &glyph.texture { - &Some(ref texture) => { + match glyph.texture { + Some(ref texture) => { let slice = SpriteSlice { cell_idx: glyph_idx, num_cells: info.num_cells as usize, @@ -769,7 +771,7 @@ impl Renderer { vert[V_BOT_LEFT].has_color = has_color; vert[V_BOT_RIGHT].has_color = has_color; } - &None => { + None => { // Whitespace; no texture to render let zero = (0.0, 0.0f32); @@ -812,7 +814,7 @@ impl Renderer { let (glyph_color, bg_color) = self.compute_cell_fg_bg( line_idx, cell_idx, - &cursor, + cursor, &selection, self.palette.foreground.to_linear_tuple_rgba(), self.palette.background.to_linear_tuple_rgba(), @@ -842,7 +844,7 @@ impl Renderer { fg_color: RgbaTuple, bg_color: RgbaTuple, ) -> (RgbaTuple, RgbaTuple) { - let selected = term::in_range(cell_idx, &selection); + let selected = term::in_range(cell_idx, selection); let is_cursor = line_idx as i64 == cursor.y && cursor.x == cell_idx; let (fg_color, bg_color) = match (selected, is_cursor) { diff --git a/src/opengl/textureatlas.rs b/src/opengl/textureatlas.rs index 5be640e8e..d47d9f98f 100644 --- a/src/opengl/textureatlas.rs +++ b/src/opengl/textureatlas.rs @@ -124,7 +124,7 @@ pub struct Sprite { /// Represents a vertical slice through a sprite. /// These are used to handle multi-cell wide glyphs. -/// Each cell is nominally cell_width wide but font metrics +/// Each cell is nominally `cell_width` wide but font metrics /// may result in the glyphs being wider than this. #[derive(Debug)] pub struct SpriteSlice { diff --git a/src/pty.rs b/src/pty.rs index cb4589719..e5ff35640 100644 --- a/src/pty.rs +++ b/src/pty.rs @@ -116,6 +116,8 @@ pub fn openpty( }; let result = unsafe { + // BSDish systems may require mut pointers to some args + #[cfg_attr(feature = "cargo-clippy", allow(unnecessary_mut_passed))] libc::openpty( &mut master, &mut slave, diff --git a/src/remotemio.rs b/src/remotemio.rs index 138cc8438..78da090ae 100644 --- a/src/remotemio.rs +++ b/src/remotemio.rs @@ -149,8 +149,8 @@ impl Inner { self.interval - diff }; - match poll.poll(&mut events, Some(period)) { - Ok(_) => for event in &events { + if poll.poll(&mut events, Some(period)).is_ok() { + for event in &events { if event.token() == Token(0) { match self.rx.try_recv() { Err(TryRecvError::Empty) => {} @@ -180,8 +180,7 @@ impl Inner { } else { self.wakeup.send(Notification::EventReady(event))?; } - }, - _ => {} + } } } } diff --git a/src/sigchld.rs b/src/sigchld.rs index a6eed1983..ab4c9f600 100644 --- a/src/sigchld.rs +++ b/src/sigchld.rs @@ -11,11 +11,8 @@ static mut EVENT_LOOP: Option> = None; extern "C" fn chld_handler(_signo: libc::c_int, _si: *const libc::siginfo_t, _: *const u8) { unsafe { - match EVENT_LOOP.as_mut() { - Some(wakeup) => { - wakeup.send(()).ok(); - } - None => (), + if let Some(wakeup) = EVENT_LOOP.as_mut() { + wakeup.send(()).ok(); } } }