Clippy run

This commit is contained in:
Paul Lietar 2017-01-29 16:25:09 +00:00
parent 17482c236a
commit bbc438d9b2
12 changed files with 40 additions and 30 deletions

View file

@ -92,7 +92,7 @@ impl <'a> Sink for PortAudioSink<'a> {
Ok(()) Ok(())
} }
fn write(&mut self, data: &[i16]) -> io::Result<()> { 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(_) => (), Ok(_) => (),
Err(portaudio::PaError::OutputUnderflowed) => Err(portaudio::PaError::OutputUnderflowed) =>
error!("PortAudio write underflow"), error!("PortAudio write underflow"),

View file

@ -42,7 +42,7 @@ impl AudioKeyManager {
} }
} }
pub fn request<'a>(&self, track: SpotifyId, file: FileId) -> AudioKeyFuture<AudioKey> { pub fn request(&self, track: SpotifyId, file: FileId) -> AudioKeyFuture<AudioKey> {
let (tx, rx) = oneshot::channel(); let (tx, rx) = oneshot::channel();
let seq = self.lock(move |inner| { let seq = self.lock(move |inner| {
@ -55,7 +55,7 @@ impl AudioKeyManager {
AudioKeyFuture(rx) 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<u8> = Vec::new(); let mut data: Vec<u8> = Vec::new();
data.write(&file.0).unwrap(); data.write(&file.0).unwrap();
data.write(&track.to_raw()).unwrap(); data.write(&track.to_raw()).unwrap();

View file

@ -35,6 +35,7 @@ pub struct Lazy<T>(Mutex<bool>, UnsafeCell<Option<T>>);
unsafe impl <T: Sync> Sync for Lazy<T> {} unsafe impl <T: Sync> Sync for Lazy<T> {}
unsafe impl <T: Send> Send for Lazy<T> {} unsafe impl <T: Send> Send for Lazy<T> {}
#[cfg_attr(feature = "cargo-clippy", allow(mutex_atomic))]
impl <T> Lazy<T> { impl <T> Lazy<T> {
pub fn new() -> Lazy<T> { pub fn new() -> Lazy<T> {
Lazy(Mutex::new(false), UnsafeCell::new(None)) Lazy(Mutex::new(false), UnsafeCell::new(None))

View file

@ -3,6 +3,8 @@
#![cfg_attr(not(feature = "with-syntex"), feature(plugin, custom_derive))] #![cfg_attr(not(feature = "with-syntex"), feature(plugin, custom_derive))]
#![cfg_attr(not(feature = "with-syntex"), plugin(protobuf_macros))] #![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 error_chain;
#[macro_use] extern crate futures; #[macro_use] extern crate futures;
#[macro_use] extern crate lazy_static; #[macro_use] extern crate lazy_static;

View file

@ -25,7 +25,7 @@ use librespot::version;
fn usage(program: &str, opts: &getopts::Options) -> String { fn usage(program: &str, opts: &getopts::Options) -> String {
let brief = format!("Usage: {} [options]", program); let brief = format!("Usage: {} [options]", program);
format!("{}", opts.usage(&brief)) opts.usage(&brief)
} }
fn setup_logging(verbose: bool) { fn setup_logging(verbose: bool) {

View file

@ -72,7 +72,7 @@ impl MercuryRequest {
for p in &self.payload { for p in &self.payload {
packet.write_u16::<BigEndian>(p.len() as u16).unwrap(); packet.write_u16::<BigEndian>(p.len() as u16).unwrap();
packet.write(&p).unwrap(); packet.write(p).unwrap();
} }
packet packet

View file

@ -80,7 +80,7 @@ impl MetadataTrait for Track {
.filter(|file| file.has_file_id()) .filter(|file| file.has_file_id())
.map(|file| { .map(|file| {
let mut dst = [0u8; 20]; 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)) (file.get_format(), FileId(dst))
}) })
.collect(); .collect();
@ -129,7 +129,7 @@ impl MetadataTrait for Album {
.filter(|image| image.has_file_id()) .filter(|image| image.has_file_id())
.map(|image| { .map(|image| {
let mut dst = [0u8; 20]; let mut dst = [0u8; 20];
dst.clone_from_slice(&image.get_file_id()); dst.clone_from_slice(image.get_file_id());
FileId(dst) FileId(dst)
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
@ -157,9 +157,7 @@ impl MetadataTrait for Artist {
let top_tracks = msg.get_top_track() let top_tracks = msg.get_top_track()
.iter() .iter()
.filter(|tt| !tt.has_country() || .find(|tt| !tt.has_country() || countrylist_contains(tt.get_country(), &country))
countrylist_contains(tt.get_country(), &country))
.next()
.unwrap() .unwrap()
.get_track() .get_track()
.iter() .iter()

View file

@ -197,7 +197,7 @@ impl PlayerInternal {
match packet { match packet {
Some(Ok(mut packet)) => { Some(Ok(mut packet)) => {
if self.volume < 0xFFFF { 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; *x = (*x as i32 * self.volume as i32 / 0xFFFF) as i16;
} }
} }
@ -314,17 +314,15 @@ impl PlayerInternal {
} }
fn run_onstart(&self) { fn run_onstart(&self) {
match self.session.config().onstart { if let Some(ref program) = self.session.config().onstart {
Some(ref program) => util::run_program(program), util::run_program(program)
None => {}, }
};
} }
fn run_onstop(&self) { fn run_onstop(&self) {
match self.session.config().onstop { if let Some(ref program) = self.session.config().onstop {
Some(ref program) => util::run_program(program), util::run_program(program)
None => {}, }
};
} }
fn find_available_alternative<'a>(&self, track: &'a Track) -> Option<Cow<'a, Track>> { fn find_available_alternative<'a>(&self, track: &'a Track) -> Option<Cow<'a, Track>> {

View file

@ -77,7 +77,7 @@ pub struct SessionWeak(pub Weak<SessionInternal>);
pub fn device_id(name: &str) -> String { pub fn device_id(name: &str) -> String {
let mut h = Sha1::new(); let mut h = Sha1::new();
h.input_str(&name); h.input_str(name);
h.result_str() h.result_str()
} }
@ -192,6 +192,7 @@ impl Session {
self.0.handle.spawn(f) self.0.handle.spawn(f)
} }
#[cfg_attr(feature = "cargo-clippy", allow(match_same_arms))]
fn dispatch(&self, cmd: u8, data: Vec<u8>) { fn dispatch(&self, cmd: u8, data: Vec<u8>) {
match cmd { match cmd {
0x4 => self.send_packet(0x49, data), 0x4 => self.send_packet(0x49, data),

View file

@ -159,8 +159,8 @@ impl Spirc {
(spirc, task) (spirc, task)
} }
pub fn shutdown(&mut self) { pub fn shutdown(&self) {
mpsc::UnboundedSender::send(&mut self.commands, SpircCommand::Shutdown).unwrap(); mpsc::UnboundedSender::send(&self.commands, SpircCommand::Shutdown).unwrap();
} }
} }
@ -312,7 +312,12 @@ impl SpircTask {
// Over 3s it seeks to zero // Over 3s it seeks to zero
if self.position() < 3000 { if self.position() < 3000 {
let current_index = self.state.get_playing_track_index(); 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_playing_track_index(new_index);
self.state.set_position_ms(0); self.state.set_position_ms(0);
@ -379,12 +384,12 @@ impl SpircTask {
self.state.get_position_ms() + diff as u32 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 index = frame.get_state().get_playing_track_index();
let tracks = frame.get_state().get_track(); let tracks = frame.get_state().get_track();
self.state.set_playing_track_index(index); 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) { fn load_track(&mut self, play: bool) {
@ -398,7 +403,12 @@ impl SpircTask {
let end_of_track = self.player.load(track, play, position); let end_of_track = self.player.load(track, play, position);
if play {
self.state.set_status(PlayStatus::kPlayStatusPlay); self.state.set_status(PlayStatus::kPlayStatusPlay);
} else {
self.state.set_status(PlayStatus::kPlayStatusPause);
}
self.end_of_track = end_of_track.boxed(); self.end_of_track = end_of_track.boxed();
} }

View file

@ -86,10 +86,10 @@ impl std::ops::Mul<u128> for u128 {
2 => (product, 0), 2 => (product, 0),
3 => (product << 32, 0), 3 => (product << 32, 0),
_ => { _ => {
if product != 0 { if product == 0 {
panic!("Overflow on mul {:?} {:?} ({} {})", self, rhs, i, j)
} else {
(0, 0) (0, 0)
} else {
panic!("Overflow on mul {:?} {:?} ({} {})", self, rhs, i, j)
} }
} }
}; };

View file

@ -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); info!("Running {}", program);
let mut v: Vec<&str> = program.split_whitespace().collect(); let mut v: Vec<&str> = program.split_whitespace().collect();
let status = Command::new(&v.remove(0)) let status = Command::new(&v.remove(0))