From dc918ae71a5e6c78a77994d7ce106a2253918c54 Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Fri, 16 Dec 2016 22:13:51 -0800 Subject: [PATCH] Rustup and clippy All of the changes in this commit are due to clippy lints. --- Cargo.lock | 73 +++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 ++ rustc-version | 2 +- src/ansi.rs | 47 ++++++++++++++++------------- src/config.rs | 23 +++++++------- src/display.rs | 11 +++++-- src/event_loop.rs | 6 ++-- src/grid.rs | 14 ++++----- src/input.rs | 12 +++----- src/lib.rs | 10 +++++-- src/macros.rs | 4 +-- src/main.rs | 3 +- src/meter.rs | 7 ++--- src/renderer/mod.rs | 51 +++++++++++-------------------- src/term/mod.rs | 8 ++--- src/tty.rs | 2 +- src/window.rs | 2 +- 17 files changed, 175 insertions(+), 102 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9bd04cc4..0d81b264 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,6 +4,7 @@ version = "0.1.0" dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "cgmath 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "copypasta 0.0.1", "errno 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "font 0.1.0", @@ -84,6 +85,28 @@ dependencies = [ "rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "clippy" +version = "0.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "clippy_lints 0.0.104 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "clippy_lints" +version = "0.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "quine-mc_cluskey 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", + "semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "cmake" version = "0.1.19" @@ -437,6 +460,11 @@ dependencies = [ "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "matches" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "memmap" version = "0.2.3" @@ -525,6 +553,11 @@ dependencies = [ "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "nom" +version = "1.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "notify" version = "2.6.3" @@ -706,6 +739,11 @@ name = "pkg-config" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "quine-mc_cluskey" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "quote" version = "0.3.10" @@ -719,6 +757,11 @@ dependencies = [ "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "regex-syntax" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "rustc-serialize" version = "0.3.22" @@ -737,6 +780,14 @@ name = "semver" version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "semver" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "serde" version = "0.7.15" @@ -896,6 +947,19 @@ dependencies = [ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "toml" +version = "0.1.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "unicode-normalization" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "unicode-xid" version = "0.0.3" @@ -1046,6 +1110,8 @@ dependencies = [ "checksum cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de1e760d7b6535af4241fca8bd8adf68e2e7edacc6b29f5d399050c5e48cf88c" "checksum cgl 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8bdd78cca65a739cb5475dbf6b6bbb49373e327f4a6f2b499c0f98632df38c10" "checksum cgmath 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75e93b3eb66e74ffb946a69ff54c6026c1399960241c843f249ea0127b96b9f6" +"checksum clippy 0.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "ae3fb361e922a08b698e746d4f199ff2d1e8d4b5f1984eaf8881e720cf5b8e34" +"checksum clippy_lints 0.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "70812027c1a8de9277d125557dce08262bc27508f2eb99592ad2d39a24a0b1c7" "checksum cmake 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)" = "8ebde6558caa6cf9bffe5750c66c517e7f9d470d59fcd48b0acbc0a02d62a82a" "checksum cocoa 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3afe4613f57a171039a98db1773f5840b5743cf85aaf03afb65ddfade4f4a9db" "checksum core-foundation 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "20a6d0448d3a99d977ae4a2aa5a98d886a923e863e81ad9ff814645b6feb3bbd" @@ -1084,6 +1150,7 @@ dependencies = [ "checksum linked-hash-map 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6d262045c5b87c0861b3f004610afd0e2c851e2908d08b6c870cbb9d5f494ecd" "checksum log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ab83497bf8bf4ed2a74259c1c802351fcd67a65baa86394b6ba73c36f4838054" "checksum malloc_buf 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" +"checksum matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "efd7622e3022e1a6eaa602c4cea8912254e5582c9c692e9167714182244801b1" "checksum memmap 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f20f72ed93291a72e22e8b16bb18762183bb4943f0f483da5b8be1a9e8192752" "checksum mio 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a637d1ca14eacae06296a008fa7ad955347e34efcb5891cfd8ba05491a37907e" "checksum mio 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "410a1a0ff76f5a226f1e4e3ff1756128e65cd30166e39c3892283e2ac09d5b67" @@ -1091,6 +1158,7 @@ dependencies = [ "checksum net2 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)" = "5edf9cb6be97212423aed9413dd4729d62b370b5e1c571750e882cebbbc1e3e2" "checksum nix 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bfb3ddedaa14746434a02041940495bf11325c22f6d36125d3bdd56090d50a79" "checksum nix 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a0d95c5fa8b641c10ad0b8887454ebaafa3c92b5cd5350f8fc693adafd178e7b" +"checksum nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b8c256fd9471521bcb84c3cdba98921497f1a331cbc15b8030fc63b82050ce" "checksum notify 2.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4e0e7eec936337952c4228b023007528a33b2fa039d96c2e8f32d764221a9c07" "checksum num 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "bde7c03b09e7c6a301ee81f6ddf66d7a28ec305699e3d3b056d2fc56470e3120" "checksum num-bigint 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "88b14378471f7c2adc5262f05b4701ef53e8da376453a8d8fee48e51db745e49" @@ -1111,11 +1179,14 @@ dependencies = [ "checksum phf_generator 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)" = "50ffbd7970f75afa083c5dd7b6830c97b72b81579c7a92d8134ef2ee6c0c7eb0" "checksum phf_shared 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)" = "286385a0e50d4147bce15b2c19f0cf84c395b0e061aaf840898a7bf664c2cfb7" "checksum pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8cee804ecc7eaf201a4a207241472cc870e825206f6c031e3ee2a72fa425f2fa" +"checksum quine-mc_cluskey 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "07589615d719a60c8dd8a4622e7946465dfef20d1a428f969e3443e7386d5f45" "checksum quote 0.3.10 (registry+https://github.com/rust-lang/crates.io-index)" = "6732e32663c9c271bfc7c1823486b471f18c47a2dbf87c066897b7b51afc83be" "checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d" +"checksum regex-syntax 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "f9ec002c35e86791825ed294b50008eea9ddfc8def4420124fbc6b08db834957" "checksum rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "237546c689f20bb44980270c73c3b9edd0891c1be49cc1274406134a66d3957b" "checksum rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c5f5376ea5e30ce23c03eb77cbe4962b988deead10910c372b226388b594c084" "checksum semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac" +"checksum semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2d5b7638a1f03815d94e88cb3b3c08e87f0db4d683ef499d1836aaf70a45623f" "checksum serde 0.7.15 (registry+https://github.com/rust-lang/crates.io-index)" = "1b0e0732aa8ec4267f61815a396a942ba3525062e3bd5520aa8419927cfc0a92" "checksum serde 0.8.19 (registry+https://github.com/rust-lang/crates.io-index)" = "58a19c0871c298847e6b68318484685cd51fa5478c0c905095647540031356e5" "checksum serde_codegen 0.8.19 (registry+https://github.com/rust-lang/crates.io-index)" = "ce29a6ae259579707650ec292199b5fed2c0b8e2a4bdc994452d24d1bcf2242a" @@ -1135,6 +1206,8 @@ dependencies = [ "checksum target_build_utils 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "54c550e226618cd35334b75e92bfa5437c61474bdb75c38bf330ab5a8037b77c" "checksum tempfile 2.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9270837a93bad1b1dac18fe67e786b3c960513af86231f6f4f57fddd594ff0c8" "checksum time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "3c7ec6d62a20df54e07ab3b78b9a3932972f4b7981de295563686849eb3989af" +"checksum toml 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)" = "0590d72182e50e879c4da3b11c6488dae18fccb1ae0c7a3eda18e16795844796" +"checksum unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "26643a2f83bac55f1976fb716c10234485f9202dcd65cfbdf9da49867b271172" "checksum unicode-xid 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "36dff09cafb4ec7c8cf0023eb0b686cb6ce65499116a12201c9e11840ca01beb" "checksum user32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6717129de5ac253f5642fc78a51d0c7de6f9f53d617fc94e9bae7f6e71cf5504" "checksum utf8parse 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a15ea87f3194a3a454c78d79082b4f5e85f6956ddb6cb86bbfbe4892aa3c0323" diff --git a/Cargo.toml b/Cargo.toml index 4d6f051a..06a1c638 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,8 @@ mio = "0.6" serde_json = "*" copypasta = { path = "./copypasta" } +clippy = { version = "0.0.104", optional = true } + [features] default = ["err-println"] # Enabling this feature makes shaders automatically reload when changed diff --git a/rustc-version b/rustc-version index 397f0ce7..05eb4879 100644 --- a/rustc-version +++ b/rustc-version @@ -1 +1 @@ -nightly-2016-11-21 +nightly-2016-12-15 diff --git a/src/ansi.rs b/src/ansi.rs index f876cb54..28a413b6 100644 --- a/src/ansi.rs +++ b/src/ansi.rs @@ -39,7 +39,7 @@ use index::{Column, Line}; use ::Rgb; -/// The processor wraps a vte::Parser to ultimately call methods on a Handler +/// The processor wraps a `vte::Parser` to ultimately call methods on a Handler pub struct Processor { state: ProcessorState, parser: vte::Parser, @@ -48,10 +48,10 @@ pub struct Processor { /// Internal state for VTE processor struct ProcessorState; -/// Helper type that implements vte::Perform. +/// Helper type that implements `vte::Perform`. /// /// Processor creates a Performer when running advance and passes the Performer -/// to vte::Parser. +/// to `vte::Parser`. struct Performer<'a, H: Handler + TermInfo + 'a, W: io::Write + 'a> { _state: &'a mut ProcessorState, handler: &'a mut H, @@ -74,13 +74,19 @@ impl<'a, H: Handler + TermInfo + 'a, W: io::Write> Performer<'a, H, W> { } } -impl Processor { - pub fn new() -> Processor { +impl Default for Processor { + fn default() -> Processor { Processor { state: ProcessorState, parser: vte::Parser::new(), } } +} + +impl Processor { + pub fn new() -> Processor { + Default::default() + } #[inline] pub fn advance( @@ -527,7 +533,7 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W> handler.move_up(Line(arg_or_default!(idx: 0, default: 1) as usize)); }, 'B' | 'e' => handler.move_down(Line(arg_or_default!(idx: 0, default: 1) as usize)), - 'c' => handler.identify_terminal(writer), + 'c' | 'n' => handler.identify_terminal(writer), 'C' | 'a' => handler.move_forward(Column(arg_or_default!(idx: 0, default: 1) as usize)), 'D' => handler.move_backward(Column(arg_or_default!(idx: 0, default: 1) as usize)), 'E' => handler.move_down_and_cr(Line(arg_or_default!(idx: 0, default: 1) as usize)), @@ -661,14 +667,14 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W> 95 => Attr::Foreground(Color::Named(NamedColor::BrightMagenta)), 96 => Attr::Foreground(Color::Named(NamedColor::BrightCyan)), 97 => Attr::Foreground(Color::Named(NamedColor::BrightWhite)), - 100 => Attr::Foreground(Color::Named(NamedColor::BrightBlack)), - 101 => Attr::Foreground(Color::Named(NamedColor::BrightRed)), - 102 => Attr::Foreground(Color::Named(NamedColor::BrightGreen)), - 103 => Attr::Foreground(Color::Named(NamedColor::BrightYellow)), - 104 => Attr::Foreground(Color::Named(NamedColor::BrightBlue)), - 105 => Attr::Foreground(Color::Named(NamedColor::BrightMagenta)), - 106 => Attr::Foreground(Color::Named(NamedColor::BrightCyan)), - 107 => Attr::Foreground(Color::Named(NamedColor::BrightWhite)), + 100 => Attr::Background(Color::Named(NamedColor::BrightBlack)), + 101 => Attr::Background(Color::Named(NamedColor::BrightRed)), + 102 => Attr::Background(Color::Named(NamedColor::BrightGreen)), + 103 => Attr::Background(Color::Named(NamedColor::BrightYellow)), + 104 => Attr::Background(Color::Named(NamedColor::BrightBlue)), + 105 => Attr::Background(Color::Named(NamedColor::BrightMagenta)), + 106 => Attr::Background(Color::Named(NamedColor::BrightCyan)), + 107 => Attr::Background(Color::Named(NamedColor::BrightWhite)), _ => unhandled!(), }; @@ -677,7 +683,8 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W> i += 1; // C-for expr } } - 'n' => handler.identify_terminal(writer), + // TODO this should be a device status report + // 'n' => handler.identify_terminal(writer), 'r' => { if private { unhandled!(); @@ -737,7 +744,7 @@ fn parse_color(attrs: &[i64], i: &mut usize) -> Option { let g = attrs[*i+3]; let b = attrs[*i+4]; - *i = *i + 4; + *i += 4; let range = 0...255; if !range.contains(r) || !range.contains(g) || !range.contains(b) { @@ -756,7 +763,7 @@ fn parse_color(attrs: &[i64], i: &mut usize) -> Option { err_println!("Expected color index; got {:?}", attrs); None } else { - *i = *i + 2; + *i += 2; let idx = attrs[*i]; match idx { 0 ... 255 => { @@ -833,7 +840,7 @@ pub mod C0 { pub const EM: u8 = 0x19; /// Substitute (VT100 uses this to display parity errors) pub const SUB: u8 = 0x1A; - /// Prefix to an ESCape sequence + /// Prefix to an escape sequence pub const ESC: u8 = 0x1B; /// File Separator pub const FS: u8 = 0x1C; @@ -865,7 +872,7 @@ pub mod C1 { pub const NBH: u8 = 0x83; /// Index, moves down one line same column regardless of NL pub const IND: u8 = 0x84; - /// NEw Line, moves done one line and to first column (CR+LF) + /// New line, moves done one line and to first column (CR+LF) pub const NEL: u8 = 0x85; /// Start of Selected Area to be as charsent to auxiliary output device pub const SSA: u8 = 0x86; @@ -895,7 +902,7 @@ pub mod C1 { pub const PU2: u8 = 0x92; /// Set Transmit State pub const STS: u8 = 0x93; - /// Cancel CHaracter, ignore previous character + /// Cancel character, ignore previous character pub const CCH: u8 = 0x94; /// Message Waiting, turns on an indicator on the terminal pub const MW: u8 = 0x95; diff --git a/src/config.rs b/src/config.rs index 23010350..a6d8150e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -242,10 +242,10 @@ impl de::Deserialize for ModsWrapper { let mut res = Mods::empty(); for modifier in value.split('|') { match modifier { - "Command" | "Super" => res = res | mods::SUPER, - "Shift" => res = res | mods::SHIFT, - "Alt" | "Option" => res = res | mods::ALT, - "Control" => res = res | mods::CONTROL, + "Command" | "Super" => res |= mods::SUPER, + "Shift" => res |= mods::SHIFT, + "Alt" | "Option" => res |= mods::ALT, + "Control" => res |= mods::CONTROL, _ => err_println!("unknown modifier {:?}", modifier), } } @@ -315,10 +315,10 @@ impl de::Deserialize for ModeWrapper { for modifier in value.split('|') { match modifier { - "AppCursor" => res.mode = res.mode | mode::APP_CURSOR, - "~AppCursor" => res.not_mode = res.not_mode | mode::APP_CURSOR, - "AppKeypad" => res.mode = res.mode | mode::APP_KEYPAD, - "~AppKeypad" => res.not_mode = res.not_mode | mode::APP_KEYPAD, + "AppCursor" => res.mode |= mode::APP_CURSOR, + "~AppCursor" => res.not_mode |= mode::APP_CURSOR, + "AppKeypad" => res.mode |= mode::APP_KEYPAD, + "~AppKeypad" => res.not_mode |= mode::APP_KEYPAD, _ => err_println!("unknown omde {:?}", modifier), } } @@ -369,8 +369,8 @@ impl de::Deserialize for MouseButton { } } -/// Bindings are deserialized into a RawBinding before being parsed as a -/// KeyBinding or MouseBinding. +/// Bindings are deserialized into a `RawBinding` before being parsed as a +/// `KeyBinding` or `MouseBinding`. struct RawBinding { key: Option<::glutin::VirtualKeyCode>, mouse: Option<::glutin::MouseButton>, @@ -879,7 +879,7 @@ impl Config { /// Pixels per inch /// -/// This is only used on FreeType systems +/// This is only used on `FreeType` systems #[derive(Debug, Deserialize)] pub struct Dpi { /// Horizontal dpi @@ -1176,6 +1176,7 @@ mod tests { } } +#[cfg_attr(feature = "clippy", allow(enum_variant_names))] #[derive(Deserialize, Copy, Clone)] enum Key { Key1, diff --git a/src/display.rs b/src/display.rs index b16bf95a..b6c5f401 100644 --- a/src/display.rs +++ b/src/display.rs @@ -94,7 +94,7 @@ impl Display { let rasterizer = font::Rasterizer::new(dpi.x(), dpi.y(), dpr); // Create renderer - let mut renderer = QuadRenderer::new(&config, size); + let mut renderer = QuadRenderer::new(config, size); // Initialize glyph cache let glyph_cache = { @@ -102,7 +102,7 @@ impl Display { let init_start = ::std::time::Instant::now(); let cache = renderer.with_loader(|mut api| { - GlyphCache::new(rasterizer, &config, &mut api) + GlyphCache::new(rasterizer, config, &mut api) }); let stop = init_start.elapsed(); @@ -223,7 +223,12 @@ impl Display { { let _sampler = self.meter.sampler(); - let size_info = terminal.size_info().clone(); + // Make a copy of size_info since the closure passed here + // borrows terminal mutably + // + // TODO I wonder if the renderable cells iter could avoid the + // mutable borrow + let size_info = *terminal.size_info(); self.renderer.with_api(config, &size_info, |mut api| { api.clear(); diff --git a/src/event_loop.rs b/src/event_loop.rs index 70aa4acb..e8e323e4 100644 --- a/src/event_loop.rs +++ b/src/event_loop.rs @@ -74,7 +74,7 @@ impl State { fn goto_next(&mut self) { self.writing = self.write_list .pop_front() - .map(|c| Writing::new(c)); + .map(Writing::new); } #[inline] @@ -115,10 +115,10 @@ impl Writing { } } -/// mio::Token for the event loop channel +/// `mio::Token` for the event loop channel const CHANNEL: mio::Token = mio::Token(0); -/// mio::Token for the pty file descriptor +/// `mio::Token` for the pty file descriptor const PTY: mio::Token = mio::Token(1); impl EventLoop diff --git a/src/grid.rs b/src/grid.rs index 1bcc91ce..7192b996 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -192,14 +192,14 @@ impl Index for Grid { type Output = Row; #[inline] - fn index<'a>(&'a self, index: index::Line) -> &'a Row { + fn index(&self, index: index::Line) -> &Row { &self.raw[index.0] } } impl IndexMut for Grid { #[inline] - fn index_mut<'a>(&'a mut self, index: index::Line) -> &'a mut Row { + fn index_mut(&mut self, index: index::Line) -> &mut Row { &mut self.raw[index.0] } } @@ -208,7 +208,7 @@ impl<'cursor, T> Index<&'cursor Cursor> for Grid { type Output = T; #[inline] - fn index<'a, 'b>(&'a self, cursor: &'b Cursor) -> &'a T { + fn index<'a>(&'a self, cursor: &Cursor) -> &'a T { &self.raw[cursor.line.0][cursor.col] } } @@ -294,14 +294,14 @@ impl Index for Row { type Output = T; #[inline] - fn index<'a>(&'a self, index: index::Column) -> &'a T { + fn index(&self, index: index::Column) -> &T { &self.0[index.0] } } impl IndexMut for Row { #[inline] - fn index_mut<'a>(&'a mut self, index: index::Column) -> &'a mut T { + fn index_mut(&mut self, index: index::Column) -> &mut T { &mut self.0[index.0] } } @@ -312,14 +312,14 @@ macro_rules! row_index_range { type Output = [T]; #[inline] - fn index<'a>(&'a self, index: $range) -> &'a [T] { + fn index(&self, index: $range) -> &[T] { &self.0[index] } } impl IndexMut<$range> for Row { #[inline] - fn index_mut<'a>(&'a mut self, index: $range) -> &'a mut [T] { + fn index_mut(&mut self, index: $range) -> &mut [T] { &mut self.0[index] } } diff --git a/src/input.rs b/src/input.rs index 744a462e..3645097e 100644 --- a/src/input.rs +++ b/src/input.rs @@ -73,7 +73,7 @@ impl Default for Mouse { } } -/// Types that are notified of escape sequences from the input::Processor. +/// Types that are notified of escape sequences from the `input::Processor`. pub trait Notify { /// Notify that an escape sequence should be written to the pty /// @@ -97,7 +97,7 @@ impl Notify for LoopNotifier { /// Describes a state and action to take in that state /// -/// This is the shared component of MouseBinding and KeyBinding +/// This is the shared component of `MouseBinding` and `KeyBinding` #[derive(Debug, Clone)] pub struct Binding { /// Modifier keys required to activate binding @@ -183,15 +183,13 @@ impl Action { match *self { Action::Esc(ref s) => notifier.notify(s.clone().into_bytes()), Action::Paste | Action::PasteSelection => { - println!("paste request"); let clip = Clipboard::new().expect("get clipboard"); clip.load_selection() .map(|contents| { - println!("got contents"); if mode.contains(mode::BRACKETED_PASTE) { - notifier.notify("\x1b[200~".as_bytes()); + notifier.notify(&b"\x1b[200~"[..]); notifier.notify(contents.into_bytes()); - notifier.notify("\x1b[201~".as_bytes()); + notifier.notify(&b"\x1b[201~"[..]); } else { notifier.notify(contents.into_bytes()); } @@ -199,8 +197,6 @@ impl Action { .unwrap_or_else(|err| { err_println!("Error getting clipboard contents: {}", err); }); - - println!("ok"); }, } } diff --git a/src/lib.rs b/src/lib.rs index 9903f591..f014d833 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,15 +13,19 @@ // limitations under the License. // //! Alacritty - The GPU Enhanced Terminal -#![feature(question_mark)] #![feature(range_contains)] #![feature(inclusive_range_syntax)] #![feature(drop_types_in_const)] #![feature(unicode)] #![feature(step_trait)] +#![feature(plugin)] +#![cfg_attr(feature = "clippy", plugin(clippy))] +#![cfg_attr(feature = "clippy", deny(clippy))] +#![cfg_attr(feature = "clippy", deny(enum_glob_use))] +#![cfg_attr(feature = "clippy", deny(if_not_else))] +#![cfg_attr(feature = "clippy", deny(wrong_pub_self_convention))] #![cfg_attr(test, feature(test))] #![feature(core_intrinsics)] -#![allow(stable_features)] // lying about question_mark because 1.14.0 isn't released! #![feature(proc_macro)] @@ -75,6 +79,8 @@ pub struct Rgb { pub b: u8, } +#[cfg_attr(feature = "clippy", allow(too_many_arguments))] +#[cfg_attr(feature = "clippy", allow(doc_markdown))] pub mod gl { #![allow(non_upper_case_globals)] include!(concat!(env!("OUT_DIR"), "/gl_bindings.rs")); diff --git a/src/macros.rs b/src/macros.rs index 740e5ed9..a6e30104 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -34,7 +34,7 @@ macro_rules! err_println { macro_rules! debug_println { ($($t:tt)*) => { if cfg!(debug_assertions) { - println!($($t)*); + err_println!($($t)*); } } } @@ -43,7 +43,7 @@ macro_rules! debug_println { macro_rules! debug_print { ($($t:tt)*) => { if cfg!(debug_assertions) { - print!($($t)*); + err_print!($($t)*); } } } diff --git a/src/main.rs b/src/main.rs index c917fe43..409f1c93 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,8 @@ // limitations under the License. // //! Alacritty - The GPU Enhanced Terminal -#![allow(stable_features)] // lying about question_mark because 1.14.0 isn't released! +#![feature(plugin)] +#![cfg_attr(feature = "clippy", plugin(clippy))] #[macro_use] extern crate alacritty; diff --git a/src/meter.rs b/src/meter.rs index b4bab5ff..2dc2ed21 100644 --- a/src/meter.rs +++ b/src/meter.rs @@ -36,6 +36,7 @@ use std::time::{Instant, Duration}; const NUM_SAMPLES: usize = 10; /// The meter +#[derive(Default)] pub struct Meter { /// Track last 60 timestamps times: [f64; NUM_SAMPLES], @@ -83,11 +84,7 @@ impl<'a> Drop for Sampler<'a> { impl Meter { /// Create a meter pub fn new() -> Meter { - Meter { - times: [0.0; NUM_SAMPLES], - avg: 0.0, - index: 0, - } + Default::default() } /// Get a sampler diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index b1fb27ed..d771b6dc 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -47,7 +47,7 @@ static TEXT_SHADER_V: &'static str = include_str!( concat!(env!("CARGO_MANIFEST_DIR"), "/res/text.v.glsl") ); -/// LoadGlyph allows for copying a rasterized glyph into graphics memory +/// `LoadGlyph` allows for copying a rasterized glyph into graphics memory pub trait LoadGlyph { /// Load the rasterized glyph into GPU memory fn load_glyph(&mut self, rasterized: &RasterizedGlyph) -> Glyph; @@ -134,9 +134,9 @@ impl GlyphCache { let bold_desc = FontDesc::new(font.family(), bold_style); let bold = if bold_desc == regular_desc { - regular.clone() + regular } else { - rasterizer.load_font(&bold_desc, size).unwrap_or_else(|| regular.clone()) + rasterizer.load_font(&bold_desc, size).unwrap_or_else(|| regular) }; // Load italic font @@ -144,19 +144,19 @@ impl GlyphCache { let italic_desc = FontDesc::new(font.family(), italic_style); let italic = if italic_desc == regular_desc { - regular.clone() + regular } else { rasterizer.load_font(&italic_desc, size) - .unwrap_or_else(|| regular.clone()) + .unwrap_or_else(|| regular) }; let mut cache = GlyphCache { cache: HashMap::new(), rasterizer: rasterizer, font_size: font.size(), - font_key: regular.clone(), - bold_key: bold.clone(), - italic_key: italic.clone(), + font_key: regular, + bold_key: bold, + italic_key: italic, }; macro_rules! load_glyphs_for_font { @@ -203,7 +203,7 @@ impl GlyphCache { // Rasterize and load the glyph self.load_and_cache_glyph(glyph_key.to_owned(), loader); - self.cache.get(&glyph_key) + self.cache.get(glyph_key) } } @@ -511,7 +511,7 @@ impl QuadRenderer { if op.contains(op::IGNORED) { if let Some(path) = path.as_ref() { if let Err(err) = watcher.watch(path) { - println!("failed to establish watch on {:?}: {:?}", path, err); + err_println!("failed to establish watch on {:?}: {:?}", path, err); } } @@ -580,7 +580,7 @@ impl QuadRenderer { batch: &mut self.batch, atlas: &mut self.atlas, program: &mut self.program, - colors: &config.color_list(), + colors: config.color_list(), }); unsafe { @@ -613,10 +613,10 @@ impl QuadRenderer { Err(err) => { match err { ShaderCreationError::Io(err) => { - println!("Error reading shader file: {}", err); + err_println!("Error reading shader file: {}", err); }, ShaderCreationError::Compile(path, log) => { - println!("Error compiling shader at {:?}", path); + err_println!("Error compiling shader at {:?}", path); io::copy(&mut log.as_bytes(), &mut io::stdout()).unwrap(); } } @@ -715,10 +715,8 @@ impl<'a> RenderApi<'a> { #[inline] fn add_render_item(&mut self, cell: &IndexedCell, glyph: &Glyph) { // Flush batch if tex changing - if !self.batch.is_empty() { - if self.batch.tex != glyph.tex_id { - self.render_batch(); - } + if !self.batch.is_empty() && self.batch.tex != glyph.tex_id { + self.render_batch(); } self.batch.add_item(cell, glyph, self.colors); @@ -872,16 +870,6 @@ impl ShaderProgram { assert_uniform_valid!(projection, term_dim, cell_dim); - let mut color_uniforms: [GLint; 18] = unsafe { ::std::mem::uninitialized() }; - for i in 0..18 { - color_uniforms[i] = unsafe { - let s = format!("colors[{}]\0", i).into_bytes(); - gl::GetUniformLocation(program, cptr!(&s[..])) - }; - - assert_uniform_valid!(color_uniforms[i]); - } - let shader = ShaderProgram { id: program, u_projection: projection, @@ -941,7 +929,7 @@ impl ShaderProgram { gl::GetProgramiv(program, gl::LINK_STATUS, &mut success); if success != (gl::TRUE as GLint) { - println!("{}", get_program_info_log(program)); + err_println!("{}", get_program_info_log(program)); panic!("failed to link shader program"); } program @@ -1248,7 +1236,7 @@ impl Atlas { let uv_height = height as f32 / self.height as f32; let uv_width = width as f32 / self.width as f32; - let g = Glyph { + Glyph { tex_id: self.id, top: glyph.top as f32, width: width as f32, @@ -1258,10 +1246,7 @@ impl Atlas { uv_left: uv_left, uv_width: uv_width, uv_height: uv_height, - }; - - // Return the glyph - g + } } /// Check if there's room in the current row for given glyph diff --git a/src/term/mod.rs b/src/term/mod.rs index 93124732..1bed8134 100644 --- a/src/term/mod.rs +++ b/src/term/mod.rs @@ -95,7 +95,7 @@ pub struct IndexedCell { impl Deref for IndexedCell { type Target = Cell; - #[inline(always)] + #[inline] fn deref(&self) -> &Cell { &self.inner } @@ -108,7 +108,7 @@ impl<'a> Iterator for RenderableCellsIter<'a> { /// /// Skips empty (background) cells and applies any flags to the cell state /// (eg. invert fg and bg colors). - #[inline(always)] + #[inline] fn next(&mut self) -> Option { while self.line < self.grid.num_lines() { while self.column < self.grid.num_cols() { @@ -319,7 +319,7 @@ impl Term { /// A renderable cell is any cell which has content other than the default /// background color. Cells with an alternate background color are /// considered renderable as are cells with any text content. - pub fn renderable_cells<'a>(&'a mut self) -> RenderableCellsIter<'a> { + pub fn renderable_cells(&mut self) -> RenderableCellsIter { RenderableCellsIter::new(&mut self.grid, &self.cursor, self.mode) } @@ -566,7 +566,7 @@ impl ansi::Handler for Term { #[inline] fn identify_terminal(&mut self, writer: &mut W) { - let _ = writer.write_all("\x1b[?6c".as_bytes()); + let _ = writer.write_all(b"\x1b[?6c"); } #[inline] diff --git a/src/tty.rs b/src/tty.rs index 667daf04..b98d2210 100644 --- a/src/tty.rs +++ b/src/tty.rs @@ -162,7 +162,7 @@ struct Passwd<'a> { /// # Unsafety /// /// If `buf` is changed while `Passwd` is alive, bad thing will almost certainly happen. -fn get_pw_entry<'a>(buf: &'a mut [i8; 1024]) -> Passwd<'a> { +fn get_pw_entry(buf: &mut [i8; 1024]) -> Passwd { // Create zeroed passwd struct let mut entry: libc::passwd = unsafe { ::std::mem::uninitialized() }; diff --git a/src/window.rs b/src/window.rs index f9f2050c..62c65c9c 100644 --- a/src/window.rs +++ b/src/window.rs @@ -98,7 +98,7 @@ pub struct Pixels(pub T); #[derive(Debug, Copy, Clone)] pub struct Points(pub T); -/// A wrapper around glutin's WaitEventsIterator that clears the wakeup +/// A wrapper around glutin's `WaitEventsIterator` that clears the wakeup /// optimization flag on drop. pub struct WaitEventsIterator<'a> { inner: glutin::WaitEventsIterator<'a>,