diff --git a/.travis.yml b/.travis.yml index 93b5cd92..e2135cef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,6 @@ +# TODO: `clippy::needless_range_loop` is currently buggy (https://github.com/rust-lang/rust-clippy/issues/3032) +# Remove it from this file when that bug is resolved. + language: rust jobs: include: @@ -8,21 +11,21 @@ jobs: - rustup component add --toolchain stable clippy-preview || cargo install --git https://github.com/rust-lang/rust-clippy/ --force clippy - rustup component add rustfmt script: - - cargo +stable clippy - cargo build --verbose - cargo test --verbose - cargo fmt --all -- --check - - + - cargo +stable clippy --all-targets --all-features -- -D warnings -A clippy::unreadable_literal -A clippy::needless_range_loop -A clippy::float_cmp + - stage: test os: osx before_script: - rustup toolchain install stable - rustup component add --toolchain stable clippy-preview || cargo install --git https://github.com/rust-lang/rust-clippy/ --force clippy - rustup component add rustfmt script: - - cargo +stable clippy - cargo build --verbose - cargo test --verbose - cargo fmt --all -- --check + - cargo +stable clippy --all-targets --all-features -- -D warnings -A clippy::unreadable_literal -A clippy::needless_range_loop -A clippy::float_cmp # deploy crates and documentation conditionally # deploy on cargo if tagged master release diff --git a/examples/dimension_expander.rs b/examples/dimension_expander.rs index 3e5247e5..639bab4f 100644 --- a/examples/dimension_expander.rs +++ b/examples/dimension_expander.rs @@ -70,7 +70,7 @@ impl DimensionExpander { } DimensionExpander { - buffers: buffers, + buffers, params: Arc::new(DimensionExpanderParameters { dry_wet: AtomicFloat::new(dry_wet), size: AtomicFloat::new(size), @@ -112,7 +112,7 @@ impl Plugin for DimensionExpander { name: "Dimension Expander".to_string(), vendor: "overdrivenpotato".to_string(), unique_id: 243723071, - version: 0001, + version: 1, inputs: 2, outputs: 2, parameters: 2, diff --git a/examples/fwd_midi.rs b/examples/fwd_midi.rs index c7f92d18..a79b82c0 100644 --- a/examples/fwd_midi.rs +++ b/examples/fwd_midi.rs @@ -39,6 +39,7 @@ impl Plugin for MyPlugin { fn process_events(&mut self, events: &api::Events) { for e in events.events() { + #[allow(clippy::single_match)] match e { Event::Midi(e) => self.events.push(e), _ => (), diff --git a/examples/gain_effect.rs b/examples/gain_effect.rs index 03e3b183..30e8e9cc 100644 --- a/examples/gain_effect.rs +++ b/examples/gain_effect.rs @@ -61,7 +61,7 @@ impl Plugin for GainEffect { name: "Gain Effect in Rust".to_string(), vendor: "Rust DSP".to_string(), unique_id: 243723072, - version: 0001, + version: 1, inputs: 2, outputs: 2, // This `parameters` bit is important; without it, none of our @@ -106,6 +106,7 @@ impl PluginParameters for GainEffectParameters { // the `set_parameter` function sets the value of a parameter. fn set_parameter(&self, index: i32, val: f32) { + #[allow(clippy::single_match)] match index { 0 => self.amplitude.set(val), _ => (), diff --git a/examples/ladder_filter.rs b/examples/ladder_filter.rs index 14725258..89c1d45b 100644 --- a/examples/ladder_filter.rs +++ b/examples/ladder_filter.rs @@ -55,7 +55,7 @@ impl Default for LadderParameters { pole_value: AtomicFloat::new(1.), drive: AtomicFloat::new(0.), sample_rate: AtomicFloat::new(44100.), - g: AtomicFloat::new(0.07135868087), + g: AtomicFloat::new(0.07135868), } } } @@ -136,7 +136,7 @@ impl LadderParameters { } // returns the value used to set cutoff. for get_parameter function pub fn get_cutoff(&self) -> f32 { - 1. + 0.1701297528 * (0.00005 * self.cutoff.get()).ln() + 1. + 0.17012975 * (0.00005 * self.cutoff.get()).ln() } pub fn set_poles(&self, value: f32) { self.pole_value.set(value); diff --git a/examples/sine_synth.rs b/examples/sine_synth.rs index 09eb3572..b459b396 100644 --- a/examples/sine_synth.rs +++ b/examples/sine_synth.rs @@ -91,10 +91,8 @@ impl Plugin for SineSynth { } } - // Supresses warning about match statment only having one arm - #[allow(unknown_lints)] #[allow(unused_variables)] - #[allow(single_match)] + #[allow(clippy::single_match)] fn process_events(&mut self, events: &Events) { for event in events.events() { match event { @@ -116,8 +114,8 @@ impl Plugin for SineSynth { let per_sample = self.time_per_sample(); let mut output_sample; for sample_idx in 0..samples { - let mut time = self.time; - let mut note_duration = self.note_duration; + let time = self.time; + let note_duration = self.note_duration; if let Some(current_note) = self.note { let signal = (time * midi_pitch_to_freq(current_note) * TAU).sin(); diff --git a/src/api.rs b/src/api.rs index 158b5fd1..a060bc2c 100644 --- a/src/api.rs +++ b/src/api.rs @@ -132,7 +132,6 @@ pub struct AEffect { impl AEffect { /// Return handle to Plugin object. Only works for plugins created using this library. // Supresses warning about returning a reference to a box - #[allow(unknown_lints)] #[allow(clippy::borrowed_box)] pub unsafe fn get_plugin(&mut self) -> &mut Box { //FIXME: find a way to do this without resorting to transmuting via a box @@ -479,7 +478,7 @@ impl<'a> Iterator for EventIterator<'a> { None } else { let event = unsafe { - let e = (**self.current).clone(); + let e = **self.current; self.current = self.current.offset(1); e }; diff --git a/src/buffer.rs b/src/buffer.rs index c233e5e1..f507ccfe 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -506,14 +506,11 @@ mod tests { let mut buffer = unsafe { AudioBuffer::from_raw(2, 2, inputs.as_ptr(), outputs.as_mut_ptr(), SIZE) }; for (input, output) in buffer.zip() { - input - .into_iter() - .zip(output.into_iter()) - .fold(0, |acc, (input, output)| { - assert_eq!(*input - acc as f32, 0.0); - assert_eq!(*output, 0.0); - acc + 1 - }); + input.iter().zip(output.iter_mut()).fold(0, |acc, (input, output)| { + assert_eq!(*input, acc as f32); + assert_eq!(*output, 0.0); + acc + 1 + }); } } @@ -598,14 +595,11 @@ mod tests { let mut buffer = unsafe { AudioBuffer::from_raw(2, 2, inputs.as_ptr(), outputs.as_mut_ptr(), SIZE) }; for (input, output) in buffer.zip() { - input - .into_iter() - .zip(output.into_iter()) - .fold(0, |acc, (input, output)| { - assert_eq!(*input - acc as f32, 0.0); - assert_eq!(*output, 0.0); - acc + 1 - }); + input.iter().zip(output.iter_mut()).fold(0, |acc, (input, output)| { + assert_eq!(*input, acc as f32); + assert_eq!(*output, 0.0); + acc + 1 + }); } } } diff --git a/src/host.rs b/src/host.rs index 4343847c..ad298061 100644 --- a/src/host.rs +++ b/src/host.rs @@ -725,10 +725,8 @@ impl HostBuffer { /// was created for, or if the sample arrays do not all have the same length. pub fn bind<'a, I, O>(&'a mut self, input_arrays: &[I], output_arrays: &mut [O]) -> AudioBuffer<'a, T> where - I: AsRef<[T]>, - O: AsMut<[T]>, - I: 'a, - O: 'a, + I: AsRef<[T]> + 'a, + O: AsMut<[T]> + 'a, { // Check that number of desired inputs and outputs fit in allocation if input_arrays.len() > self.inputs.len() { @@ -840,7 +838,7 @@ mod tests { #[test] fn host_buffer() { - const LENGTH: usize = 1000000; + const LENGTH: usize = 1_000_000; let mut host_buffer: HostBuffer = HostBuffer::new(2, 2); let input_left = vec![1.0; LENGTH]; let input_right = vec![1.0; LENGTH]; diff --git a/src/interfaces.rs b/src/interfaces.rs index d45f6a41..7a1a9463 100644 --- a/src/interfaces.rs +++ b/src/interfaces.rs @@ -69,7 +69,7 @@ pub fn get_parameter(effect: *mut AEffect, index: i32) -> f32 { /// String will be cut at `max` characters. fn copy_string(dst: *mut c_void, src: &str, max: usize) -> isize { unsafe { - use libc::{c_void, memcpy, memset}; + use libc::{memcpy, memset}; use std::cmp::min; let dst = dst as *mut c_void; diff --git a/src/lib.rs b/src/lib.rs index cca3c207..d7df8772 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -187,7 +187,7 @@ pub fn main(callback: HostCallbackProc) -> *mut AEffect { // Create a Box containing a zeroed AEffect. This is transmuted into a *mut pointer so that it // can be passed into the HostCallback `wrap` method. The AEffect is then updated after the vst // object is created so that the host still contains a raw pointer to the AEffect struct. - let effect = unsafe { Box::into_raw(Box::new(mem::zeroed::())) }; + let effect = unsafe { Box::into_raw(Box::new(mem::MaybeUninit::zeroed().assume_init())) }; let host = HostCallback::wrap(callback, effect); if host.vst_version() == 0 { diff --git a/src/plugin.rs b/src/plugin.rs index 493f3adf..41596f2c 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -1,10 +1,9 @@ //! Plugin specific structures. +use std::os::raw::c_void; use std::ptr; use std::sync::Arc; -use std::os::raw::c_void; - use api; use api::consts::VST_MAGIC; use api::{AEffect, HostCallbackProc, Supported, TimeInfo}; @@ -406,6 +405,8 @@ pub enum CanDo { } impl CanDo { + // TODO: implement FromStr + #![allow(clippy::should_implement_trait)] /// Converts a string to a `CanDo` instance. Any given string that does not match the predefined /// values will return a `CanDo::Other` value. pub fn from_str(s: &str) -> CanDo { @@ -596,7 +597,7 @@ pub trait Plugin { // For each input and output for (input, output) in buffer.zip() { // For each input sample and output sample in buffer - for (in_frame, out_frame) in input.into_iter().zip(output.into_iter()) { + for (in_frame, out_frame) in input.iter().zip(output.iter_mut()) { *out_frame = *in_frame; } } @@ -637,7 +638,7 @@ pub trait Plugin { // For each input and output for (input, output) in buffer.zip() { // For each input sample and output sample in buffer - for (in_frame, out_frame) in input.into_iter().zip(output.into_iter()) { + for (in_frame, out_frame) in input.iter().zip(output.iter_mut()) { *out_frame = *in_frame; } } diff --git a/src/util/parameter_transfer.rs b/src/util/parameter_transfer.rs index ad8a2579..986fe421 100644 --- a/src/util/parameter_transfer.rs +++ b/src/util/parameter_transfer.rs @@ -57,7 +57,7 @@ impl ParameterTransfer { /// /// The changed parameters are reported in increasing index order, and the same /// parameter is never reported more than once in the same iteration. - pub fn iterate<'pt>(&'pt self, acquire: bool) -> ParameterTransferIterator<'pt> { + pub fn iterate(&self, acquire: bool) -> ParameterTransferIterator { ParameterTransferIterator { pt: self, word: 0, @@ -128,7 +128,7 @@ mod tests { const THREADS: usize = 3; const PARAMETERS: usize = 1000; - const UPDATES: usize = 1000000; + const UPDATES: usize = 1_000_000; #[test] fn parameter_transfer() {