Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Make CI fail if Clippy finds any warnings. #104

Merged
merged 11 commits into from
Nov 3, 2019
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions examples/dimension_expander.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl DimensionExpander {
}

DimensionExpander {
buffers: buffers,
buffers,
params: Arc::new(DimensionExpanderParameters {
dry_wet: AtomicFloat::new(dry_wet),
size: AtomicFloat::new(size),
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
crsaracco marked this conversation as resolved.
Show resolved Hide resolved
self.resize(size);
}

Expand Down
3 changes: 2 additions & 1 deletion examples/fwd_midi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
_ => (),
Expand Down
5 changes: 3 additions & 2 deletions examples/gain_effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
_ => (),
Expand Down
6 changes: 3 additions & 3 deletions examples/ladder_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(),
crsaracco marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions examples/sine_synth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion examples/transfer_and_smooth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
crsaracco marked this conversation as resolved.
Show resolved Hide resolved
version: 100,

..Info::default()
Expand Down
3 changes: 1 addition & 2 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Plugin> {
//FIXME: find a way to do this without resorting to transmuting via a box
Expand Down Expand Up @@ -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
};
Expand Down
30 changes: 14 additions & 16 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,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)]
crsaracco marked this conversation as resolved.
Show resolved Hide resolved
#[test]
fn buffer_zip() {
let in1: Vec<f32> = (0..SIZE).map(|x| x as f32).collect();
Expand All @@ -506,19 +507,17 @@ 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
});
}
}

// 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];
Expand Down Expand Up @@ -552,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];
Expand Down Expand Up @@ -585,6 +585,7 @@ mod tests {
}

/// Test that creating buffers from raw pointers works.
#[allow(clippy::float_cmp)]
#[test]
fn from_raw() {
let in1: Vec<f32> = (0..SIZE).map(|x| x as f32).collect();
Expand All @@ -598,14 +599,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
});
}
}
}
8 changes: 3 additions & 5 deletions src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,10 +725,8 @@ impl<T: Float> HostBuffer<T> {
/// 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() {
Expand Down Expand Up @@ -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<f32> = HostBuffer::new(2, 2);
let input_left = vec![1.0; LENGTH];
let input_right = vec![1.0; LENGTH];
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub fn main<T: Plugin + Default>(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::<AEffect>())) };
let effect = unsafe { Box::into_raw(Box::new(mem::MaybeUninit::zeroed().assume_init())) };

let host = HostCallback::wrap(callback, effect);
if host.vst_version() == 0 {
Expand Down
8 changes: 5 additions & 3 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ pub enum CanDo {
}

impl CanDo {
// TODO: either rename this function or implement FromStr
#![allow(clippy::should_implement_trait)]
crsaracco marked this conversation as resolved.
Show resolved Hide resolved
/// 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 {
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);
crsaracco marked this conversation as resolved.
Show resolved Hide resolved
0
}
OpCode::Version => 2400,
Expand Down
7 changes: 4 additions & 3 deletions src/util/parameter_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -181,8 +181,9 @@ mod tests {
assert!(transfer.iterate(true).next().is_none());

// Verify final values
#[allow(clippy::needless_range_loop)]
crsaracco marked this conversation as resolved.
Show resolved Hide resolved
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));
crsaracco marked this conversation as resolved.
Show resolved Hide resolved
}
}
}