From bbc438d9b271ef3f71a5e101622797ff74963c9f Mon Sep 17 00:00:00 2001 From: Paul Lietar Date: Sun, 29 Jan 2017 16:25:09 +0000 Subject: [PATCH] Clippy run --- src/audio_backend/portaudio.rs | 2 +- src/audio_key.rs | 4 ++-- src/component.rs | 1 + src/lib.rs | 2 ++ src/main.rs | 2 +- src/mercury/types.rs | 2 +- src/metadata.rs | 8 +++----- src/player.rs | 16 +++++++--------- src/session.rs | 3 ++- src/spirc.rs | 22 ++++++++++++++++------ src/util/int128.rs | 6 +++--- src/util/mod.rs | 2 +- 12 files changed, 40 insertions(+), 30 deletions(-) diff --git a/src/audio_backend/portaudio.rs b/src/audio_backend/portaudio.rs index 2460c22e..791f102d 100644 --- a/src/audio_backend/portaudio.rs +++ b/src/audio_backend/portaudio.rs @@ -92,7 +92,7 @@ impl <'a> Sink for PortAudioSink<'a> { Ok(()) } fn write(&mut self, data: &[i16]) -> io::Result<()> { - match self.0.as_mut().unwrap().write(&data) { + match self.0.as_mut().unwrap().write(data) { Ok(_) => (), Err(portaudio::PaError::OutputUnderflowed) => error!("PortAudio write underflow"), diff --git a/src/audio_key.rs b/src/audio_key.rs index eab364f3..7875a259 100644 --- a/src/audio_key.rs +++ b/src/audio_key.rs @@ -42,7 +42,7 @@ impl AudioKeyManager { } } - pub fn request<'a>(&self, track: SpotifyId, file: FileId) -> AudioKeyFuture { + pub fn request(&self, track: SpotifyId, file: FileId) -> AudioKeyFuture { let (tx, rx) = oneshot::channel(); let seq = self.lock(move |inner| { @@ -55,7 +55,7 @@ impl AudioKeyManager { AudioKeyFuture(rx) } - fn send_key_request<'a>(&self, seq: u32, track: SpotifyId, file: FileId) { + fn send_key_request(&self, seq: u32, track: SpotifyId, file: FileId) { let mut data: Vec = Vec::new(); data.write(&file.0).unwrap(); data.write(&track.to_raw()).unwrap(); diff --git a/src/component.rs b/src/component.rs index 59753fa5..51f9898d 100644 --- a/src/component.rs +++ b/src/component.rs @@ -35,6 +35,7 @@ pub struct Lazy(Mutex, UnsafeCell>); unsafe impl Sync for Lazy {} unsafe impl Send for Lazy {} +#[cfg_attr(feature = "cargo-clippy", allow(mutex_atomic))] impl Lazy { pub fn new() -> Lazy { Lazy(Mutex::new(false), UnsafeCell::new(None)) diff --git a/src/lib.rs b/src/lib.rs index e1fe4dc9..67ea0371 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,8 @@ #![cfg_attr(not(feature = "with-syntex"), feature(plugin, custom_derive))] #![cfg_attr(not(feature = "with-syntex"), plugin(protobuf_macros))] +#![cfg_attr(feature = "cargo-clippy", allow(unused_io_amount))] + #[macro_use] extern crate error_chain; #[macro_use] extern crate futures; #[macro_use] extern crate lazy_static; diff --git a/src/main.rs b/src/main.rs index 09b6f90e..40074d61 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,7 @@ use librespot::version; fn usage(program: &str, opts: &getopts::Options) -> String { let brief = format!("Usage: {} [options]", program); - format!("{}", opts.usage(&brief)) + opts.usage(&brief) } fn setup_logging(verbose: bool) { diff --git a/src/mercury/types.rs b/src/mercury/types.rs index 60acb7a1..aa33af2c 100644 --- a/src/mercury/types.rs +++ b/src/mercury/types.rs @@ -72,7 +72,7 @@ impl MercuryRequest { for p in &self.payload { packet.write_u16::(p.len() as u16).unwrap(); - packet.write(&p).unwrap(); + packet.write(p).unwrap(); } packet diff --git a/src/metadata.rs b/src/metadata.rs index 43094e5c..938631f0 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -80,7 +80,7 @@ impl MetadataTrait for Track { .filter(|file| file.has_file_id()) .map(|file| { let mut dst = [0u8; 20]; - dst.clone_from_slice(&file.get_file_id()); + dst.clone_from_slice(file.get_file_id()); (file.get_format(), FileId(dst)) }) .collect(); @@ -129,7 +129,7 @@ impl MetadataTrait for Album { .filter(|image| image.has_file_id()) .map(|image| { let mut dst = [0u8; 20]; - dst.clone_from_slice(&image.get_file_id()); + dst.clone_from_slice(image.get_file_id()); FileId(dst) }) .collect::>(); @@ -157,9 +157,7 @@ impl MetadataTrait for Artist { let top_tracks = msg.get_top_track() .iter() - .filter(|tt| !tt.has_country() || - countrylist_contains(tt.get_country(), &country)) - .next() + .find(|tt| !tt.has_country() || countrylist_contains(tt.get_country(), &country)) .unwrap() .get_track() .iter() diff --git a/src/player.rs b/src/player.rs index 3725f85f..ec9bb669 100644 --- a/src/player.rs +++ b/src/player.rs @@ -197,7 +197,7 @@ impl PlayerInternal { match packet { Some(Ok(mut packet)) => { if self.volume < 0xFFFF { - for x in packet.data.iter_mut() { + for x in &mut packet.data { *x = (*x as i32 * self.volume as i32 / 0xFFFF) as i16; } } @@ -314,17 +314,15 @@ impl PlayerInternal { } fn run_onstart(&self) { - match self.session.config().onstart { - Some(ref program) => util::run_program(program), - None => {}, - }; + if let Some(ref program) = self.session.config().onstart { + util::run_program(program) + } } fn run_onstop(&self) { - match self.session.config().onstop { - Some(ref program) => util::run_program(program), - None => {}, - }; + if let Some(ref program) = self.session.config().onstop { + util::run_program(program) + } } fn find_available_alternative<'a>(&self, track: &'a Track) -> Option> { diff --git a/src/session.rs b/src/session.rs index dcefddd0..8994217c 100644 --- a/src/session.rs +++ b/src/session.rs @@ -77,7 +77,7 @@ pub struct SessionWeak(pub Weak); pub fn device_id(name: &str) -> String { let mut h = Sha1::new(); - h.input_str(&name); + h.input_str(name); h.result_str() } @@ -192,6 +192,7 @@ impl Session { self.0.handle.spawn(f) } + #[cfg_attr(feature = "cargo-clippy", allow(match_same_arms))] fn dispatch(&self, cmd: u8, data: Vec) { match cmd { 0x4 => self.send_packet(0x49, data), diff --git a/src/spirc.rs b/src/spirc.rs index 218c7aad..170b5f45 100644 --- a/src/spirc.rs +++ b/src/spirc.rs @@ -159,8 +159,8 @@ impl Spirc { (spirc, task) } - pub fn shutdown(&mut self) { - mpsc::UnboundedSender::send(&mut self.commands, SpircCommand::Shutdown).unwrap(); + pub fn shutdown(&self) { + mpsc::UnboundedSender::send(&self.commands, SpircCommand::Shutdown).unwrap(); } } @@ -312,7 +312,12 @@ impl SpircTask { // Over 3s it seeks to zero if self.position() < 3000 { let current_index = self.state.get_playing_track_index(); - let new_index = (current_index - 1) % (self.state.get_track().len() as u32); + + let new_index = if current_index == 0 { + self.state.get_track().len() as u32 - 1 + } else { + current_index - 1 + }; self.state.set_playing_track_index(new_index); self.state.set_position_ms(0); @@ -379,12 +384,12 @@ impl SpircTask { self.state.get_position_ms() + diff as u32 } - fn update_tracks(&mut self, ref frame: &protocol::spirc::Frame) { + fn update_tracks(&mut self, frame: &protocol::spirc::Frame) { let index = frame.get_state().get_playing_track_index(); let tracks = frame.get_state().get_track(); self.state.set_playing_track_index(index); - self.state.set_track(tracks.into_iter().map(Clone::clone).collect()); + self.state.set_track(tracks.into_iter().cloned().collect()); } fn load_track(&mut self, play: bool) { @@ -398,7 +403,12 @@ impl SpircTask { let end_of_track = self.player.load(track, play, position); - self.state.set_status(PlayStatus::kPlayStatusPlay); + if play { + self.state.set_status(PlayStatus::kPlayStatusPlay); + } else { + self.state.set_status(PlayStatus::kPlayStatusPause); + } + self.end_of_track = end_of_track.boxed(); } diff --git a/src/util/int128.rs b/src/util/int128.rs index d25385a7..9cfbaf3b 100644 --- a/src/util/int128.rs +++ b/src/util/int128.rs @@ -86,10 +86,10 @@ impl std::ops::Mul for u128 { 2 => (product, 0), 3 => (product << 32, 0), _ => { - if product != 0 { - panic!("Overflow on mul {:?} {:?} ({} {})", self, rhs, i, j) - } else { + if product == 0 { (0, 0) + } else { + panic!("Overflow on mul {:?} {:?} ({} {})", self, rhs, i, j) } } }; diff --git a/src/util/mod.rs b/src/util/mod.rs index d7a79bf9..4bf45e8c 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -42,7 +42,7 @@ pub fn mkdir_existing(path: &Path) -> io::Result<()> { }) } -pub fn run_program(program: &String) { +pub fn run_program(program: &str) { info!("Running {}", program); let mut v: Vec<&str> = program.split_whitespace().collect(); let status = Command::new(&v.remove(0))