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

Commit 37ced4b

Browse files
authored
Merge pull request #104 from RustAudio/clippy-ci
Make CI fail if Clippy finds any warnings.
2 parents aa7cc43 + 055604e commit 37ced4b

13 files changed

+39
-44
lines changed

.travis.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# TODO: `clippy::needless_range_loop` is currently buggy (https://github.com/rust-lang/rust-clippy/issues/3032)
2+
# Remove it from this file when that bug is resolved.
3+
14
language: rust
25
jobs:
36
include:
@@ -8,21 +11,21 @@ jobs:
811
- rustup component add --toolchain stable clippy-preview || cargo install --git https://github.com/rust-lang/rust-clippy/ --force clippy
912
- rustup component add rustfmt
1013
script:
11-
- cargo +stable clippy
1214
- cargo build --verbose
1315
- cargo test --verbose
1416
- cargo fmt --all -- --check
15-
-
17+
- cargo +stable clippy --all-targets --all-features -- -D warnings -A clippy::unreadable_literal -A clippy::needless_range_loop -A clippy::float_cmp
18+
- stage: test
1619
os: osx
1720
before_script:
1821
- rustup toolchain install stable
1922
- rustup component add --toolchain stable clippy-preview || cargo install --git https://github.com/rust-lang/rust-clippy/ --force clippy
2023
- rustup component add rustfmt
2124
script:
22-
- cargo +stable clippy
2325
- cargo build --verbose
2426
- cargo test --verbose
2527
- cargo fmt --all -- --check
28+
- cargo +stable clippy --all-targets --all-features -- -D warnings -A clippy::unreadable_literal -A clippy::needless_range_loop -A clippy::float_cmp
2629

2730
# deploy crates and documentation conditionally
2831
# deploy on cargo if tagged master release

examples/dimension_expander.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl DimensionExpander {
7070
}
7171

7272
DimensionExpander {
73-
buffers: buffers,
73+
buffers,
7474
params: Arc::new(DimensionExpanderParameters {
7575
dry_wet: AtomicFloat::new(dry_wet),
7676
size: AtomicFloat::new(size),
@@ -112,7 +112,7 @@ impl Plugin for DimensionExpander {
112112
name: "Dimension Expander".to_string(),
113113
vendor: "overdrivenpotato".to_string(),
114114
unique_id: 243723071,
115-
version: 0001,
115+
version: 1,
116116
inputs: 2,
117117
outputs: 2,
118118
parameters: 2,

examples/fwd_midi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ impl Plugin for MyPlugin {
3939

4040
fn process_events(&mut self, events: &api::Events) {
4141
for e in events.events() {
42+
#[allow(clippy::single_match)]
4243
match e {
4344
Event::Midi(e) => self.events.push(e),
4445
_ => (),

examples/gain_effect.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl Plugin for GainEffect {
6161
name: "Gain Effect in Rust".to_string(),
6262
vendor: "Rust DSP".to_string(),
6363
unique_id: 243723072,
64-
version: 0001,
64+
version: 1,
6565
inputs: 2,
6666
outputs: 2,
6767
// This `parameters` bit is important; without it, none of our
@@ -106,6 +106,7 @@ impl PluginParameters for GainEffectParameters {
106106

107107
// the `set_parameter` function sets the value of a parameter.
108108
fn set_parameter(&self, index: i32, val: f32) {
109+
#[allow(clippy::single_match)]
109110
match index {
110111
0 => self.amplitude.set(val),
111112
_ => (),

examples/ladder_filter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl Default for LadderParameters {
5555
pole_value: AtomicFloat::new(1.),
5656
drive: AtomicFloat::new(0.),
5757
sample_rate: AtomicFloat::new(44100.),
58-
g: AtomicFloat::new(0.07135868087),
58+
g: AtomicFloat::new(0.07135868),
5959
}
6060
}
6161
}
@@ -136,7 +136,7 @@ impl LadderParameters {
136136
}
137137
// returns the value used to set cutoff. for get_parameter function
138138
pub fn get_cutoff(&self) -> f32 {
139-
1. + 0.1701297528 * (0.00005 * self.cutoff.get()).ln()
139+
1. + 0.17012975 * (0.00005 * self.cutoff.get()).ln()
140140
}
141141
pub fn set_poles(&self, value: f32) {
142142
self.pole_value.set(value);

examples/sine_synth.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,8 @@ impl Plugin for SineSynth {
9191
}
9292
}
9393

94-
// Supresses warning about match statment only having one arm
95-
#[allow(unknown_lints)]
9694
#[allow(unused_variables)]
97-
#[allow(single_match)]
95+
#[allow(clippy::single_match)]
9896
fn process_events(&mut self, events: &Events) {
9997
for event in events.events() {
10098
match event {
@@ -116,8 +114,8 @@ impl Plugin for SineSynth {
116114
let per_sample = self.time_per_sample();
117115
let mut output_sample;
118116
for sample_idx in 0..samples {
119-
let mut time = self.time;
120-
let mut note_duration = self.note_duration;
117+
let time = self.time;
118+
let note_duration = self.note_duration;
121119
if let Some(current_note) = self.note {
122120
let signal = (time * midi_pitch_to_freq(current_note) * TAU).sin();
123121

src/api.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ pub struct AEffect {
132132
impl AEffect {
133133
/// Return handle to Plugin object. Only works for plugins created using this library.
134134
// Supresses warning about returning a reference to a box
135-
#[allow(unknown_lints)]
136135
#[allow(clippy::borrowed_box)]
137136
pub unsafe fn get_plugin(&mut self) -> &mut Box<dyn Plugin> {
138137
//FIXME: find a way to do this without resorting to transmuting via a box
@@ -479,7 +478,7 @@ impl<'a> Iterator for EventIterator<'a> {
479478
None
480479
} else {
481480
let event = unsafe {
482-
let e = (**self.current).clone();
481+
let e = **self.current;
483482
self.current = self.current.offset(1);
484483
e
485484
};

src/buffer.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -506,14 +506,11 @@ mod tests {
506506
let mut buffer = unsafe { AudioBuffer::from_raw(2, 2, inputs.as_ptr(), outputs.as_mut_ptr(), SIZE) };
507507

508508
for (input, output) in buffer.zip() {
509-
input
510-
.into_iter()
511-
.zip(output.into_iter())
512-
.fold(0, |acc, (input, output)| {
513-
assert_eq!(*input - acc as f32, 0.0);
514-
assert_eq!(*output, 0.0);
515-
acc + 1
516-
});
509+
input.iter().zip(output.iter_mut()).fold(0, |acc, (input, output)| {
510+
assert_eq!(*input, acc as f32);
511+
assert_eq!(*output, 0.0);
512+
acc + 1
513+
});
517514
}
518515
}
519516

@@ -598,14 +595,11 @@ mod tests {
598595
let mut buffer = unsafe { AudioBuffer::from_raw(2, 2, inputs.as_ptr(), outputs.as_mut_ptr(), SIZE) };
599596

600597
for (input, output) in buffer.zip() {
601-
input
602-
.into_iter()
603-
.zip(output.into_iter())
604-
.fold(0, |acc, (input, output)| {
605-
assert_eq!(*input - acc as f32, 0.0);
606-
assert_eq!(*output, 0.0);
607-
acc + 1
608-
});
598+
input.iter().zip(output.iter_mut()).fold(0, |acc, (input, output)| {
599+
assert_eq!(*input, acc as f32);
600+
assert_eq!(*output, 0.0);
601+
acc + 1
602+
});
609603
}
610604
}
611605
}

src/host.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -725,10 +725,8 @@ impl<T: Float> HostBuffer<T> {
725725
/// was created for, or if the sample arrays do not all have the same length.
726726
pub fn bind<'a, I, O>(&'a mut self, input_arrays: &[I], output_arrays: &mut [O]) -> AudioBuffer<'a, T>
727727
where
728-
I: AsRef<[T]>,
729-
O: AsMut<[T]>,
730-
I: 'a,
731-
O: 'a,
728+
I: AsRef<[T]> + 'a,
729+
O: AsMut<[T]> + 'a,
732730
{
733731
// Check that number of desired inputs and outputs fit in allocation
734732
if input_arrays.len() > self.inputs.len() {
@@ -840,7 +838,7 @@ mod tests {
840838

841839
#[test]
842840
fn host_buffer() {
843-
const LENGTH: usize = 1000000;
841+
const LENGTH: usize = 1_000_000;
844842
let mut host_buffer: HostBuffer<f32> = HostBuffer::new(2, 2);
845843
let input_left = vec![1.0; LENGTH];
846844
let input_right = vec![1.0; LENGTH];

src/interfaces.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub fn get_parameter(effect: *mut AEffect, index: i32) -> f32 {
6969
/// String will be cut at `max` characters.
7070
fn copy_string(dst: *mut c_void, src: &str, max: usize) -> isize {
7171
unsafe {
72-
use libc::{c_void, memcpy, memset};
72+
use libc::{memcpy, memset};
7373
use std::cmp::min;
7474

7575
let dst = dst as *mut c_void;

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ pub fn main<T: Plugin + Default>(callback: HostCallbackProc) -> *mut AEffect {
187187
// Create a Box containing a zeroed AEffect. This is transmuted into a *mut pointer so that it
188188
// can be passed into the HostCallback `wrap` method. The AEffect is then updated after the vst
189189
// object is created so that the host still contains a raw pointer to the AEffect struct.
190-
let effect = unsafe { Box::into_raw(Box::new(mem::zeroed::<AEffect>())) };
190+
let effect = unsafe { Box::into_raw(Box::new(mem::MaybeUninit::zeroed().assume_init())) };
191191

192192
let host = HostCallback::wrap(callback, effect);
193193
if host.vst_version() == 0 {

src/plugin.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
//! Plugin specific structures.
22
3+
use std::os::raw::c_void;
34
use std::ptr;
45
use std::sync::Arc;
56

6-
use std::os::raw::c_void;
7-
87
use api;
98
use api::consts::VST_MAGIC;
109
use api::{AEffect, HostCallbackProc, Supported, TimeInfo};
@@ -406,6 +405,8 @@ pub enum CanDo {
406405
}
407406

408407
impl CanDo {
408+
// TODO: implement FromStr
409+
#![allow(clippy::should_implement_trait)]
409410
/// Converts a string to a `CanDo` instance. Any given string that does not match the predefined
410411
/// values will return a `CanDo::Other` value.
411412
pub fn from_str(s: &str) -> CanDo {
@@ -596,7 +597,7 @@ pub trait Plugin {
596597
// For each input and output
597598
for (input, output) in buffer.zip() {
598599
// For each input sample and output sample in buffer
599-
for (in_frame, out_frame) in input.into_iter().zip(output.into_iter()) {
600+
for (in_frame, out_frame) in input.iter().zip(output.iter_mut()) {
600601
*out_frame = *in_frame;
601602
}
602603
}
@@ -637,7 +638,7 @@ pub trait Plugin {
637638
// For each input and output
638639
for (input, output) in buffer.zip() {
639640
// For each input sample and output sample in buffer
640-
for (in_frame, out_frame) in input.into_iter().zip(output.into_iter()) {
641+
for (in_frame, out_frame) in input.iter().zip(output.iter_mut()) {
641642
*out_frame = *in_frame;
642643
}
643644
}

src/util/parameter_transfer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl ParameterTransfer {
5757
///
5858
/// The changed parameters are reported in increasing index order, and the same
5959
/// parameter is never reported more than once in the same iteration.
60-
pub fn iterate<'pt>(&'pt self, acquire: bool) -> ParameterTransferIterator<'pt> {
60+
pub fn iterate(&self, acquire: bool) -> ParameterTransferIterator {
6161
ParameterTransferIterator {
6262
pt: self,
6363
word: 0,
@@ -128,7 +128,7 @@ mod tests {
128128

129129
const THREADS: usize = 3;
130130
const PARAMETERS: usize = 1000;
131-
const UPDATES: usize = 1000000;
131+
const UPDATES: usize = 1_000_000;
132132

133133
#[test]
134134
fn parameter_transfer() {

0 commit comments

Comments
 (0)