From ba22ab3e17f190e4ac32f108a7cd4465b9de9cc2 Mon Sep 17 00:00:00 2001 From: Charles Saracco Date: Sun, 14 Jul 2019 10:34:08 -0400 Subject: [PATCH 01/10] Fail CI if clippy shows any warnings --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 93b5cd92..e6f5dd07 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,21 +8,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 + - 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 # deploy crates and documentation conditionally # deploy on cargo if tagged master release From ba4f671612a4efbf228e9b0685a19994f844dd3d Mon Sep 17 00:00:00 2001 From: Charles Saracco Date: Sun, 14 Jul 2019 11:42:56 -0400 Subject: [PATCH 02/10] Fix all current Clippy warnings --- examples/dimension_expander.rs | 8 +++--- examples/fwd_midi.rs | 3 ++- examples/gain_effect.rs | 5 ++-- examples/ladder_filter.rs | 6 ++--- examples/sine_synth.rs | 7 +++--- examples/transfer_and_smooth.rs | 2 +- src/api.rs | 2 +- src/buffer.rs | 43 +++++++++++++++------------------ src/host.rs | 2 +- src/interfaces.rs | 2 +- src/plugin.rs | 8 +++--- src/util/mod.rs | 1 + src/util/parameter_transfer.rs | 6 ++--- src/util/test_util.rs | 13 ++++++++++ 14 files changed, 60 insertions(+), 48 deletions(-) create mode 100644 src/util/test_util.rs diff --git a/examples/dimension_expander.rs b/examples/dimension_expander.rs index 3e5247e5..1c42938e 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), @@ -111,8 +111,8 @@ impl Plugin for DimensionExpander { Info { name: "Dimension Expander".to_string(), vendor: "overdrivenpotato".to_string(), - unique_id: 243723071, - version: 0001, + unique_id: 243_723_071, + version: 1, inputs: 2, outputs: 2, parameters: 2, @@ -132,7 +132,7 @@ impl Plugin for DimensionExpander { // Resize if size changed let size = self.params.size.get(); - if size != self.old_size { + if (size - self.old_size).abs() < std::f32::EPSILON { self.resize(size); } diff --git a/examples/fwd_midi.rs b/examples/fwd_midi.rs index c7f92d18..4b9e6a21 100644 --- a/examples/fwd_midi.rs +++ b/examples/fwd_midi.rs @@ -32,13 +32,14 @@ impl Plugin for MyPlugin { fn get_info(&self) -> Info { Info { name: "fwd_midi".to_string(), - unique_id: 7357001, // Used by hosts to differentiate between plugins. + unique_id: 7_357_001, // Used by hosts to differentiate between plugins. ..Default::default() } } 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..bcb51daf 100644 --- a/examples/gain_effect.rs +++ b/examples/gain_effect.rs @@ -60,8 +60,8 @@ impl Plugin for GainEffect { Info { name: "Gain Effect in Rust".to_string(), vendor: "Rust DSP".to_string(), - unique_id: 243723072, - version: 0001, + unique_id: 243_723_072, + 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..20b6e325 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.071_358_68), } } } @@ -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.170_129_75 * (0.00005 * self.cutoff.get()).ln() } pub fn set_poles(&self, value: f32) { self.pole_value.set(value); @@ -190,7 +190,7 @@ impl PluginParameters for LadderParameters { 1 => format!("{:.3}", self.res.get()), 2 => format!("{}", self.poles.load(Ordering::Relaxed) + 1), 3 => format!("{:.3}", self.drive.get()), - _ => format!(""), + _ => "".to_string(), } } } diff --git a/examples/sine_synth.rs b/examples/sine_synth.rs index 09eb3572..55967480 100644 --- a/examples/sine_synth.rs +++ b/examples/sine_synth.rs @@ -91,10 +91,9 @@ 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 +115,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/examples/transfer_and_smooth.rs b/examples/transfer_and_smooth.rs index 87ee7482..5ee5885f 100644 --- a/examples/transfer_and_smooth.rs +++ b/examples/transfer_and_smooth.rs @@ -75,7 +75,7 @@ impl Plugin for MyPlugin { name: "transfer_and_smooth".to_string(), vendor: "Loonies".to_string(), - unique_id: 0x500007, + unique_id: 0x0050_0007, version: 100, ..Info::default() diff --git a/src/api.rs b/src/api.rs index 8f9b233f..381ba9f7 100644 --- a/src/api.rs +++ b/src/api.rs @@ -479,7 +479,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..03c8bf6c 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -481,6 +481,7 @@ impl SendEventBuffer { #[cfg(test)] mod tests { use buffer::AudioBuffer; + use util::test_util; /// Size of buffers used in tests. const SIZE: usize = 1024; @@ -506,14 +507,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)| { + test_util::assert_f32_equal(*input, acc as f32); + test_util::assert_f32_zero(*output); + acc + 1 + }); } } @@ -534,15 +532,15 @@ mod tests { let mut iter = buffer.zip(); if let Some((observed_in1, observed_out1)) = iter.next() { - assert_eq!(1.0, observed_in1[0]); - assert_eq!(3.0, observed_out1[0]); + test_util::assert_f32_equal(observed_in1[0], 1.0); + test_util::assert_f32_equal(observed_out1[0], 3.0); } else { unreachable!(); } if let Some((observed_in2, observed_out2)) = iter.next() { - assert_eq!(2.0, observed_in2[0]); - assert_eq!(4.0, observed_out2[0]); + test_util::assert_f32_equal(observed_in2[0], 2.0); + test_util::assert_f32_equal(observed_out2[0], 4.0); } else { unreachable!(); } @@ -568,15 +566,15 @@ mod tests { let mut iter = buffer.zip(); if let Some((observed_in1, observed_out1)) = iter.next() { - assert_eq!(1.0, observed_in1[0]); - assert_eq!(4.0, observed_out1[0]); + test_util::assert_f32_equal(observed_in1[0], 1.0); + test_util::assert_f32_equal(observed_out1[0], 4.0); } else { unreachable!(); } if let Some((observed_in2, observed_out2)) = iter.next() { - assert_eq!(2.0, observed_in2[0]); - assert_eq!(5.0, observed_out2[0]); + test_util::assert_f32_equal(observed_in2[0], 2.0); + test_util::assert_f32_equal(observed_out2[0], 5.0); } else { unreachable!(); } @@ -598,14 +596,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)| { + test_util::assert_f32_equal(*input, acc as f32); + test_util::assert_f32_zero(*output); + acc + 1 + }); } } } diff --git a/src/host.rs b/src/host.rs index 4343847c..30302168 100644 --- a/src/host.rs +++ b/src/host.rs @@ -840,7 +840,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/plugin.rs b/src/plugin.rs index 493f3adf..5356af88 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -406,6 +406,8 @@ pub enum CanDo { } impl CanDo { + // TODO: either rename this function or 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 +598,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 +639,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; } } @@ -1024,7 +1026,7 @@ mod tests { match opcode { OpCode::Automate => { assert_eq!(index, 123); - assert_eq!(opt, 12.3); + assert!((opt-12.3).abs() < std::f32::EPSILON); 0 } OpCode::Version => 2400, diff --git a/src/util/mod.rs b/src/util/mod.rs index fbe7a87e..cb4d9309 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -2,6 +2,7 @@ mod atomic_float; mod parameter_transfer; +pub mod test_util; pub use self::atomic_float::AtomicFloat; pub use self::parameter_transfer::{ParameterTransfer, ParameterTransferIterator}; diff --git a/src/util/parameter_transfer.rs b/src/util/parameter_transfer.rs index ad8a2579..6420766c 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() { @@ -182,7 +182,7 @@ mod tests { // Verify final values for p in 0..PARAMETERS { - assert!((0..THREADS).any(|t| results[t][p] == values[p])); + assert!((0..THREADS).any(|t| (results[t][p] - values[p]).abs() < std::f32::EPSILON)); } } } diff --git a/src/util/test_util.rs b/src/util/test_util.rs new file mode 100644 index 00000000..28503058 --- /dev/null +++ b/src/util/test_util.rs @@ -0,0 +1,13 @@ +//! Utility functions that are useful for tests. + +#[inline(always)] +/// Compare two `f32`s, and assert equality. +pub fn assert_f32_equal(a: f32, b: f32) { + assert!((a - b).abs() < std::f32::EPSILON); +} + +#[inline(always)] +/// Assert that an `f32` is zero. +pub fn assert_f32_zero(a: f32) { + assert!(a.abs() < std::f32::EPSILON); +} From 72a6b1f6f280f148879a6700988af168595d715b Mon Sep 17 00:00:00 2001 From: Charles Saracco Date: Sat, 2 Nov 2019 23:19:12 -0400 Subject: [PATCH 03/10] Update code for some new clippy lints --- examples/sine_synth.rs | 1 - src/api.rs | 1 - src/host.rs | 6 ++---- src/lib.rs | 4 +++- src/util/parameter_transfer.rs | 1 + 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/examples/sine_synth.rs b/examples/sine_synth.rs index 55967480..b459b396 100644 --- a/examples/sine_synth.rs +++ b/examples/sine_synth.rs @@ -91,7 +91,6 @@ impl Plugin for SineSynth { } } - #[allow(unknown_lints)] #[allow(unused_variables)] #[allow(clippy::single_match)] fn process_events(&mut self, events: &Events) { diff --git a/src/api.rs b/src/api.rs index 2219163c..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 diff --git a/src/host.rs b/src/host.rs index 30302168..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() { diff --git a/src/lib.rs b/src/lib.rs index cca3c207..0e7065b0 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -187,7 +187,9 @@ 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/util/parameter_transfer.rs b/src/util/parameter_transfer.rs index 6420766c..fc3b52df 100644 --- a/src/util/parameter_transfer.rs +++ b/src/util/parameter_transfer.rs @@ -181,6 +181,7 @@ mod tests { assert!(transfer.iterate(true).next().is_none()); // Verify final values + #[allow(clippy::needless_range_loop)] for p in 0..PARAMETERS { assert!((0..THREADS).any(|t| (results[t][p] - values[p]).abs() < std::f32::EPSILON)); } From 788741f4eca5a8ad7f84e34c088ffc5ee36c4346 Mon Sep 17 00:00:00 2001 From: Charles Saracco Date: Sat, 2 Nov 2019 23:22:27 -0400 Subject: [PATCH 04/10] cargo fmt --- src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0e7065b0..d7df8772 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -187,9 +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::MaybeUninit::zeroed().assume_init())) - }; + let effect = unsafe { Box::into_raw(Box::new(mem::MaybeUninit::zeroed().assume_init())) }; let host = HostCallback::wrap(callback, effect); if host.vst_version() == 0 { From 0c29aed65fb7c30442dea27078c72b31352d41b8 Mon Sep 17 00:00:00 2001 From: Charles Saracco Date: Sat, 2 Nov 2019 23:44:48 -0400 Subject: [PATCH 05/10] Remove fuzzy float checks, remove test_util module --- src/buffer.rs | 29 ++++++++++++++++------------- src/util/mod.rs | 1 - src/util/test_util.rs | 13 ------------- 3 files changed, 16 insertions(+), 27 deletions(-) delete mode 100644 src/util/test_util.rs diff --git a/src/buffer.rs b/src/buffer.rs index 03c8bf6c..f4e4016e 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -481,7 +481,6 @@ impl SendEventBuffer { #[cfg(test)] mod tests { use buffer::AudioBuffer; - use util::test_util; /// Size of buffers used in tests. const SIZE: usize = 1024; @@ -494,6 +493,7 @@ mod tests { /// and the output channels are just 0. /// This test assures that when the buffers are zipped together, /// the input values do not change. + #[allow(clippy::float_cmp)] #[test] fn buffer_zip() { let in1: Vec = (0..SIZE).map(|x| x as f32).collect(); @@ -508,8 +508,8 @@ mod tests { for (input, output) in buffer.zip() { input.iter().zip(output.iter_mut()).fold(0, |acc, (input, output)| { - test_util::assert_f32_equal(*input, acc as f32); - test_util::assert_f32_zero(*output); + assert_eq!(*input, acc as f32); + assert_eq!(*output, 0.0); acc + 1 }); } @@ -517,6 +517,7 @@ mod tests { // Test that the `zip()` method returns an iterator that gives `n` elements // where n is the number of inputs when this is lower than the number of outputs. + #[allow(clippy::float_cmp)] #[test] fn buffer_zip_fewer_inputs_than_outputs() { let in1 = vec![1.0; SIZE]; @@ -532,15 +533,15 @@ mod tests { let mut iter = buffer.zip(); if let Some((observed_in1, observed_out1)) = iter.next() { - test_util::assert_f32_equal(observed_in1[0], 1.0); - test_util::assert_f32_equal(observed_out1[0], 3.0); + assert_eq!(1.0, observed_in1[0]); + assert_eq!(3.0, observed_out1[0]); } else { unreachable!(); } if let Some((observed_in2, observed_out2)) = iter.next() { - test_util::assert_f32_equal(observed_in2[0], 2.0); - test_util::assert_f32_equal(observed_out2[0], 4.0); + assert_eq!(2.0, observed_in2[0]); + assert_eq!(4.0, observed_out2[0]); } else { unreachable!(); } @@ -550,6 +551,7 @@ mod tests { // Test that the `zip()` method returns an iterator that gives `n` elements // where n is the number of outputs when this is lower than the number of inputs. + #[allow(clippy::float_cmp)] #[test] fn buffer_zip_more_inputs_than_outputs() { let in1 = vec![1.0; SIZE]; @@ -566,15 +568,15 @@ mod tests { let mut iter = buffer.zip(); if let Some((observed_in1, observed_out1)) = iter.next() { - test_util::assert_f32_equal(observed_in1[0], 1.0); - test_util::assert_f32_equal(observed_out1[0], 4.0); + assert_eq!(1.0, observed_in1[0]); + assert_eq!(4.0, observed_out1[0]); } else { unreachable!(); } if let Some((observed_in2, observed_out2)) = iter.next() { - test_util::assert_f32_equal(observed_in2[0], 2.0); - test_util::assert_f32_equal(observed_out2[0], 5.0); + assert_eq!(2.0, observed_in2[0]); + assert_eq!(5.0, observed_out2[0]); } else { unreachable!(); } @@ -583,6 +585,7 @@ mod tests { } /// Test that creating buffers from raw pointers works. + #[allow(clippy::float_cmp)] #[test] fn from_raw() { let in1: Vec = (0..SIZE).map(|x| x as f32).collect(); @@ -597,8 +600,8 @@ mod tests { for (input, output) in buffer.zip() { input.iter().zip(output.iter_mut()).fold(0, |acc, (input, output)| { - test_util::assert_f32_equal(*input, acc as f32); - test_util::assert_f32_zero(*output); + assert_eq!(*input, acc as f32); + assert_eq!(*output, 0.0); acc + 1 }); } diff --git a/src/util/mod.rs b/src/util/mod.rs index cb4d9309..fbe7a87e 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -2,7 +2,6 @@ mod atomic_float; mod parameter_transfer; -pub mod test_util; pub use self::atomic_float::AtomicFloat; pub use self::parameter_transfer::{ParameterTransfer, ParameterTransferIterator}; diff --git a/src/util/test_util.rs b/src/util/test_util.rs deleted file mode 100644 index 28503058..00000000 --- a/src/util/test_util.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! Utility functions that are useful for tests. - -#[inline(always)] -/// Compare two `f32`s, and assert equality. -pub fn assert_f32_equal(a: f32, b: f32) { - assert!((a - b).abs() < std::f32::EPSILON); -} - -#[inline(always)] -/// Assert that an `f32` is zero. -pub fn assert_f32_zero(a: f32) { - assert!(a.abs() < std::f32::EPSILON); -} From 46ff65ad153284a29a965d243e7b28d67050f72f Mon Sep 17 00:00:00 2001 From: Charles Saracco Date: Sun, 3 Nov 2019 11:20:05 -0500 Subject: [PATCH 06/10] crate-wide allow for the clippy 'unreadable_literal' lint --- .travis.yml | 4 ++-- examples/dimension_expander.rs | 2 +- examples/fwd_midi.rs | 2 +- examples/gain_effect.rs | 2 +- examples/ladder_filter.rs | 4 ++-- examples/transfer_and_smooth.rs | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index e6f5dd07..e48df815 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ jobs: - cargo build --verbose - cargo test --verbose - cargo fmt --all -- --check - - cargo +stable clippy --all-targets --all-features -- -D warnings + - cargo +stable clippy --all-targets --all-features -- -A clippy::unreadable_literal -D warnings - stage: test os: osx before_script: @@ -22,7 +22,7 @@ jobs: - cargo build --verbose - cargo test --verbose - cargo fmt --all -- --check - - cargo +stable clippy --all-targets --all-features -- -D warnings + - cargo +stable clippy --all-targets --all-features -- -A clippy::unreadable_literal -D warnings # 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 1c42938e..7b25e9d8 100644 --- a/examples/dimension_expander.rs +++ b/examples/dimension_expander.rs @@ -111,7 +111,7 @@ impl Plugin for DimensionExpander { Info { name: "Dimension Expander".to_string(), vendor: "overdrivenpotato".to_string(), - unique_id: 243_723_071, + unique_id: 243723071, version: 1, inputs: 2, outputs: 2, diff --git a/examples/fwd_midi.rs b/examples/fwd_midi.rs index 4b9e6a21..a79b82c0 100644 --- a/examples/fwd_midi.rs +++ b/examples/fwd_midi.rs @@ -32,7 +32,7 @@ impl Plugin for MyPlugin { fn get_info(&self) -> Info { Info { name: "fwd_midi".to_string(), - unique_id: 7_357_001, // Used by hosts to differentiate between plugins. + unique_id: 7357001, // Used by hosts to differentiate between plugins. ..Default::default() } } diff --git a/examples/gain_effect.rs b/examples/gain_effect.rs index bcb51daf..30e8e9cc 100644 --- a/examples/gain_effect.rs +++ b/examples/gain_effect.rs @@ -60,7 +60,7 @@ impl Plugin for GainEffect { Info { name: "Gain Effect in Rust".to_string(), vendor: "Rust DSP".to_string(), - unique_id: 243_723_072, + unique_id: 243723072, version: 1, inputs: 2, outputs: 2, diff --git a/examples/ladder_filter.rs b/examples/ladder_filter.rs index 20b6e325..142cf536 100644 --- a/examples/ladder_filter.rs +++ b/examples/ladder_filter.rs @@ -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.170_129_75 * (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); @@ -190,7 +190,7 @@ impl PluginParameters for LadderParameters { 1 => format!("{:.3}", self.res.get()), 2 => format!("{}", self.poles.load(Ordering::Relaxed) + 1), 3 => format!("{:.3}", self.drive.get()), - _ => "".to_string(), + _ => format!(""), } } } diff --git a/examples/transfer_and_smooth.rs b/examples/transfer_and_smooth.rs index 5ee5885f..34b30400 100644 --- a/examples/transfer_and_smooth.rs +++ b/examples/transfer_and_smooth.rs @@ -75,7 +75,7 @@ impl Plugin for MyPlugin { name: "transfer_and_smooth".to_string(), vendor: "Loonies".to_string(), - unique_id: 0x0050_0007, + unique_id: 0x00500007, version: 100, ..Info::default() From 00a5e88ca4f328733cc50e7e7d86c91d2ff81848 Mon Sep 17 00:00:00 2001 From: Charles Saracco Date: Sun, 3 Nov 2019 11:30:55 -0500 Subject: [PATCH 07/10] Revert some fuzzy float compare changes --- examples/dimension_expander.rs | 3 ++- src/plugin.rs | 3 ++- src/util/parameter_transfer.rs | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/dimension_expander.rs b/examples/dimension_expander.rs index 7b25e9d8..08df6aa5 100644 --- a/examples/dimension_expander.rs +++ b/examples/dimension_expander.rs @@ -122,6 +122,7 @@ impl Plugin for DimensionExpander { } } + #[allow(clippy::float_cmp)] fn process(&mut self, buffer: &mut AudioBuffer) { let (inputs, outputs) = buffer.split(); @@ -132,7 +133,7 @@ impl Plugin for DimensionExpander { // Resize if size changed let size = self.params.size.get(); - if (size - self.old_size).abs() < std::f32::EPSILON { + if size != self.old_size { self.resize(size); } diff --git a/src/plugin.rs b/src/plugin.rs index 5356af88..5749a97c 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -1014,6 +1014,7 @@ mod tests { } #[allow(dead_code)] + #[allow(clippy::float_cmp)] fn instance() -> *mut AEffect { fn host_callback(_effect: *mut AEffect, opcode: i32, @@ -1026,7 +1027,7 @@ mod tests { match opcode { OpCode::Automate => { assert_eq!(index, 123); - assert!((opt-12.3).abs() < std::f32::EPSILON); + assert_eq!(opt, 12.3); 0 } OpCode::Version => 2400, diff --git a/src/util/parameter_transfer.rs b/src/util/parameter_transfer.rs index fc3b52df..477bcaa0 100644 --- a/src/util/parameter_transfer.rs +++ b/src/util/parameter_transfer.rs @@ -181,9 +181,10 @@ mod tests { assert!(transfer.iterate(true).next().is_none()); // Verify final values + #[allow(clippy::float_cmp)] #[allow(clippy::needless_range_loop)] for p in 0..PARAMETERS { - assert!((0..THREADS).any(|t| (results[t][p] - values[p]).abs() < std::f32::EPSILON)); + assert!((0..THREADS).any(|t| results[t][p] == values[p])); } } } From 575274e1d0e081f7246c02f6e3cc487ef9604a19 Mon Sep 17 00:00:00 2001 From: Charles Saracco Date: Sun, 3 Nov 2019 12:10:32 -0500 Subject: [PATCH 08/10] Crate-wide allow clippy::needless_range_loop until bugs are fixed --- .travis.yml | 7 +++++-- src/util/parameter_transfer.rs | 1 - 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index e48df815..b35332d7 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: @@ -11,7 +14,7 @@ jobs: - cargo build --verbose - cargo test --verbose - cargo fmt --all -- --check - - cargo +stable clippy --all-targets --all-features -- -A clippy::unreadable_literal -D warnings + - cargo +stable clippy --all-targets --all-features -- -D warnings -A clippy::unreadable_literal -A clippy::needless_range_loop - stage: test os: osx before_script: @@ -22,7 +25,7 @@ jobs: - cargo build --verbose - cargo test --verbose - cargo fmt --all -- --check - - cargo +stable clippy --all-targets --all-features -- -A clippy::unreadable_literal -D warnings + - cargo +stable clippy --all-targets --all-features -- -D warnings -A clippy::unreadable_literal -A clippy::needless_range_loop # deploy crates and documentation conditionally # deploy on cargo if tagged master release diff --git a/src/util/parameter_transfer.rs b/src/util/parameter_transfer.rs index 477bcaa0..ee2d38c1 100644 --- a/src/util/parameter_transfer.rs +++ b/src/util/parameter_transfer.rs @@ -182,7 +182,6 @@ mod tests { // Verify final values #[allow(clippy::float_cmp)] - #[allow(clippy::needless_range_loop)] for p in 0..PARAMETERS { assert!((0..THREADS).any(|t| results[t][p] == values[p])); } From 7c0086b2eff4d522ff9813ce4b4f62fc1f111691 Mon Sep 17 00:00:00 2001 From: Charles Saracco Date: Sun, 3 Nov 2019 12:26:17 -0500 Subject: [PATCH 09/10] Crate-wide allow for clippy::float_cmp (pretty much only false positives for now) --- .travis.yml | 4 ++-- examples/dimension_expander.rs | 1 - examples/transfer_and_smooth.rs | 2 +- src/buffer.rs | 4 ---- src/plugin.rs | 1 - src/util/parameter_transfer.rs | 1 - 6 files changed, 3 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index b35332d7..e2135cef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ jobs: - 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 + - 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: @@ -25,7 +25,7 @@ jobs: - 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 + - 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 08df6aa5..639bab4f 100644 --- a/examples/dimension_expander.rs +++ b/examples/dimension_expander.rs @@ -122,7 +122,6 @@ impl Plugin for DimensionExpander { } } - #[allow(clippy::float_cmp)] fn process(&mut self, buffer: &mut AudioBuffer) { let (inputs, outputs) = buffer.split(); diff --git a/examples/transfer_and_smooth.rs b/examples/transfer_and_smooth.rs index 34b30400..87ee7482 100644 --- a/examples/transfer_and_smooth.rs +++ b/examples/transfer_and_smooth.rs @@ -75,7 +75,7 @@ impl Plugin for MyPlugin { name: "transfer_and_smooth".to_string(), vendor: "Loonies".to_string(), - unique_id: 0x00500007, + unique_id: 0x500007, version: 100, ..Info::default() diff --git a/src/buffer.rs b/src/buffer.rs index f4e4016e..f507ccfe 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -493,7 +493,6 @@ mod tests { /// and the output channels are just 0. /// This test assures that when the buffers are zipped together, /// the input values do not change. - #[allow(clippy::float_cmp)] #[test] fn buffer_zip() { let in1: Vec = (0..SIZE).map(|x| x as f32).collect(); @@ -517,7 +516,6 @@ mod tests { // Test that the `zip()` method returns an iterator that gives `n` elements // where n is the number of inputs when this is lower than the number of outputs. - #[allow(clippy::float_cmp)] #[test] fn buffer_zip_fewer_inputs_than_outputs() { let in1 = vec![1.0; SIZE]; @@ -551,7 +549,6 @@ mod tests { // Test that the `zip()` method returns an iterator that gives `n` elements // where n is the number of outputs when this is lower than the number of inputs. - #[allow(clippy::float_cmp)] #[test] fn buffer_zip_more_inputs_than_outputs() { let in1 = vec![1.0; SIZE]; @@ -585,7 +582,6 @@ mod tests { } /// Test that creating buffers from raw pointers works. - #[allow(clippy::float_cmp)] #[test] fn from_raw() { let in1: Vec = (0..SIZE).map(|x| x as f32).collect(); diff --git a/src/plugin.rs b/src/plugin.rs index 5749a97c..04312d33 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -1014,7 +1014,6 @@ mod tests { } #[allow(dead_code)] - #[allow(clippy::float_cmp)] fn instance() -> *mut AEffect { fn host_callback(_effect: *mut AEffect, opcode: i32, diff --git a/src/util/parameter_transfer.rs b/src/util/parameter_transfer.rs index ee2d38c1..986fe421 100644 --- a/src/util/parameter_transfer.rs +++ b/src/util/parameter_transfer.rs @@ -181,7 +181,6 @@ mod tests { assert!(transfer.iterate(true).next().is_none()); // Verify final values - #[allow(clippy::float_cmp)] for p in 0..PARAMETERS { assert!((0..THREADS).any(|t| results[t][p] == values[p])); } From 055604ea46bcb0992b829110ffe34d0a29daac91 Mon Sep 17 00:00:00 2001 From: Charles Saracco Date: Sun, 3 Nov 2019 12:42:11 -0500 Subject: [PATCH 10/10] Final formatting and comment changes --- examples/ladder_filter.rs | 2 +- src/plugin.rs | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/ladder_filter.rs b/examples/ladder_filter.rs index 142cf536..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.071_358_68), + g: AtomicFloat::new(0.07135868), } } } diff --git a/src/plugin.rs b/src/plugin.rs index 04312d33..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,7 +405,7 @@ pub enum CanDo { } impl CanDo { - // TODO: either rename this function or implement FromStr + // 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.