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
7 changes: 3 additions & 4 deletions examples/sine_synth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();

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
2 changes: 1 addition & 1 deletion src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
43 changes: 19 additions & 24 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
crsaracco marked this conversation as resolved.
Show resolved Hide resolved
acc + 1
});
}
}

Expand All @@ -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!();
}
Expand All @@ -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!();
}
Expand All @@ -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);
crsaracco marked this conversation as resolved.
Show resolved Hide resolved
acc + 1
});
}
}
}
2 changes: 1 addition & 1 deletion src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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
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
1 change: 1 addition & 0 deletions src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
6 changes: 3 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 @@ -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));
crsaracco marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
13 changes: 13 additions & 0 deletions src/util/test_util.rs
Original file line number Diff line number Diff line change
@@ -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);
}
crsaracco marked this conversation as resolved.
Show resolved Hide resolved

#[inline(always)]
/// Assert that an `f32` is zero.
pub fn assert_f32_zero(a: f32) {
assert!(a.abs() < std::f32::EPSILON);
}
crsaracco marked this conversation as resolved.
Show resolved Hide resolved