Skip to content

Commit 315c9e2

Browse files
authored
Merge pull request #1416 from antonilol/clippy-fixes
fix clippy warnings and other improvements to code quality
2 parents a57f9ad + 1dabf0e commit 315c9e2

18 files changed

+101
-126
lines changed

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ when upgrading from a version of rust-sdl2 to another.
33

44
### Next
55

6+
[PR #1416](https://github.com/Rust-SDL2/rust-sdl2/pull/1416) Apply clippy fixes, fix deprecations and other code quality improvements.
7+
68
[PR #1408](https://github.com/Rust-SDL2/rust-sdl2/pull/1408) Allow comparing `Version`s, add constant with the version the bindings were compiled with.
79

810
[PR #1407](https://github.com/Rust-SDL2/rust-sdl2/pull/1407) Add new use_ios_framework for linking to SDL2.framework on iOS

examples/animation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ fn main() -> Result<(), String> {
7474

7575
// set the current frame for time
7676
source_rect_0.set_x(32 * ((ticks / 100) % frames_per_anim));
77-
dest_rect_0.set_x(1 * ((ticks / 14) % 768) - 128);
77+
dest_rect_0.set_x(((ticks / 14) % 768) - 128);
7878

7979
source_rect_1.set_x(32 * ((ticks / 100) % frames_per_anim));
80-
dest_rect_1.set_x((1 * ((ticks / 12) % 768) - 672) * -1);
80+
dest_rect_1.set_x(-(((ticks / 12) % 768) - 672));
8181

8282
source_rect_2.set_x(32 * ((ticks / 100) % frames_per_anim));
83-
dest_rect_2.set_x(1 * ((ticks / 10) % 768) - 128);
83+
dest_rect_2.set_x(((ticks / 10) % 768) - 128);
8484

8585
canvas.clear();
8686
// copy the frame to the canvas

examples/audio-capture-and-replay.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ extern crate sdl2;
22

33
use sdl2::audio::{AudioCallback, AudioSpecDesired};
44
use sdl2::AudioSubsystem;
5-
use std::i16;
65
use std::sync::mpsc;
76
use std::time::Duration;
87

examples/audio-wav.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn main() -> Result<(), String> {
6969

7070
// initialize the audio callback
7171
Sound {
72-
data: data,
72+
data,
7373
volume: 0.25,
7474
pos: 0,
7575
}

examples/audio-whitenoise.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn main() -> Result<(), String> {
4848
{
4949
// Acquire a lock. This lets us read and modify callback data.
5050
let mut lock = device.lock();
51-
(*lock).volume = 0.25;
51+
lock.volume = 0.25;
5252
// Lock guard is dropped here
5353
}
5454

examples/game-of-life.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ mod game_of_life {
4040
}
4141

4242
GameOfLife {
43-
playground: playground,
43+
playground,
4444
state: State::Paused,
4545
}
4646
}
@@ -90,13 +90,18 @@ mod game_of_life {
9090
}
9191
}
9292
}
93-
if count > 3 || count < 2 {
94-
*square = false;
95-
} else if count == 3 {
96-
*square = true;
97-
} else if count == 2 {
98-
*square = *square;
99-
}
93+
match count {
94+
..=1 => {
95+
*square = false;
96+
}
97+
2 => {}
98+
3 => {
99+
*square = true;
100+
}
101+
4.. => {
102+
*square = false;
103+
}
104+
};
100105
}
101106
self.playground = new_playground;
102107
}
@@ -127,7 +132,7 @@ fn dummy_texture<'a>(
127132
.map_err(|e| e.to_string())?;
128133
// let's change the textures we just created
129134
{
130-
let textures = vec![
135+
let textures = [
131136
(&mut square_texture1, TextureColor::Yellow),
132137
(&mut square_texture2, TextureColor::White),
133138
];

examples/haptic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ fn main() -> Result<(), String> {
1313

1414
// Iterate over all available joysticks and stop once we manage to open one.
1515
let joystick_index = (0..available)
16-
.find_map(|id| match joystick_subsystem.open(id) {
16+
.find(|&id| match joystick_subsystem.open(id) {
1717
Ok(c) => {
1818
println!("Success: opened \"{}\"", c.name());
19-
Some(id)
19+
true
2020
}
2121
Err(e) => {
2222
println!("failed: {:?}", e);
23-
None
23+
false
2424
}
2525
})
2626
.expect("Couldn't open any joystick");

examples/mixer-demo.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn main() -> Result<(), String> {
1111
if args.len() < 2 {
1212
println!("Usage: ./demo music.[mp3|wav|ogg] [sound-effect.[mp3|wav|ogg]]")
1313
} else {
14-
let sound_file = args.get(2).map(|sound_file| Path::new(sound_file));
14+
let sound_file = args.get(2).map(Path::new);
1515
demo(Path::new(&args[1]), sound_file)?;
1616
}
1717

@@ -23,7 +23,7 @@ fn demo(music_file: &Path, sound_file: Option<&Path>) -> Result<(), String> {
2323

2424
let sdl = sdl2::init()?;
2525
let _audio = sdl.audio()?;
26-
let mut timer = sdl.timer()?;
26+
let timer = sdl.timer()?;
2727

2828
let frequency = 44_100;
2929
let format = AUDIO_S16LSB; // signed 16 bit samples, in little-endian byte order
@@ -77,9 +77,9 @@ fn demo(music_file: &Path, sound_file: Option<&Path>) -> Result<(), String> {
7777
// (played at half the volume to save people's ears).
7878
let buffer = (0..frequency)
7979
.map(|i| {
80-
(0.1 * i16::max_value() as f32
81-
* (2.0 * 3.14 * 500.0 * (i as f32 / frequency as f32)).sin())
82-
as i16
80+
(0.1 * i16::MAX as f32
81+
* (2.0 * std::f32::consts::PI * 500.0 * (i as f32 / frequency as f32))
82+
.sin()) as i16
8383
})
8484
.collect();
8585
sdl2::mixer::Chunk::from_raw_buffer(buffer)

examples/resource-manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ where
101101
pub fn new(loader: &'l L) -> Self {
102102
ResourceManager {
103103
cache: HashMap::new(),
104-
loader: loader,
104+
loader,
105105
}
106106
}
107107

src/sdl2/event.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/*!
2-
Event Handling
3-
*/
1+
//! Event Handling
42
53
use std::borrow::ToOwned;
64
use std::collections::HashMap;
@@ -2359,25 +2357,22 @@ impl Event {
23592357
// FIXME: Use a constant from sdl2-sys when bindgen will be fixed (see https://github.com/Rust-SDL2/rust-sdl2/issues/1265)
23602358
const SDL_TOUCH_MOUSEID: u32 = 0xFFFFFFFF;
23612359

2362-
match self {
2360+
matches!(
2361+
self,
23632362
Self::MouseMotion {
23642363
which: SDL_TOUCH_MOUSEID,
23652364
..
2366-
}
2367-
| Self::MouseButtonDown {
2365+
} | Self::MouseButtonDown {
23682366
which: SDL_TOUCH_MOUSEID,
23692367
..
2370-
}
2371-
| Self::MouseButtonUp {
2368+
} | Self::MouseButtonUp {
23722369
which: SDL_TOUCH_MOUSEID,
23732370
..
2374-
}
2375-
| Self::MouseWheel {
2371+
} | Self::MouseWheel {
23762372
which: SDL_TOUCH_MOUSEID,
23772373
..
2378-
} => true,
2379-
_ => false,
2380-
}
2374+
}
2375+
)
23812376
}
23822377

23832378
/// Returns `true` if this is a controller event.

0 commit comments

Comments
 (0)