Skip to content

Commit 5dbf6e5

Browse files
authored
fix clippy warnings (#1510)
* fix clippy warnings * update changelog
1 parent 28d12e9 commit 5dbf6e5

File tree

17 files changed

+99
-104
lines changed

17 files changed

+99
-104
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
### v0.39.0
55

6+
[PR #1510](https://github.com/Rust-SDL2/rust-sdl2/pull/1510) Fix clippy warnings.
7+
68
[PR #1509](https://github.com/Rust-SDL2/rust-sdl2/pull/1509) **BREAKING CHANGE** Add Send + 'static bounds for EventWatchCallback and 'static bound to AudioCallback to avoid soundness hole.
79

810
[PR #1506](https://github.com/Rust-SDL2/rust-sdl2/pull/1506) **BREAKING CHANGE** Update crates.io dependencies, update bundled SDL2 to 2.32.10, add whitelist to bindgen to only emit SDL related items, and specifically no platform (or compiler, etc) specific items. Implement the same set of useful derived traits on bitflags types.

examples/resource-manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ where
127127
// TextureCreator knows how to load Textures
128128
impl<'l, T> ResourceLoader<'l, Texture<'l>> for TextureCreator<T> {
129129
type Args = str;
130-
fn load(&'l self, path: &str) -> Result<Texture, String> {
130+
fn load(&'l self, path: &str) -> Result<Texture<'l>, String> {
131131
println!("LOADED A TEXTURE");
132132
self.load_texture(path)
133133
}

src/sdl2/audio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ impl<CB: AudioCallback> AudioDevice<CB> {
10251025
/// called.
10261026
/// Use this method to read and mutate callback data.
10271027
#[doc(alias = "SDL_LockAudioDevice")]
1028-
pub fn lock(&mut self) -> AudioDeviceLockGuard<CB> {
1028+
pub fn lock(&mut self) -> AudioDeviceLockGuard<'_, CB> {
10291029
unsafe { sys::SDL_LockAudioDevice(self.device_id.id()) };
10301030
AudioDeviceLockGuard {
10311031
device: self,

src/sdl2/event.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2770,7 +2770,7 @@ impl crate::EventPump {
27702770
/// }
27712771
/// }
27722772
/// ```
2773-
pub fn poll_iter(&mut self) -> EventPollIterator {
2773+
pub fn poll_iter(&mut self) -> EventPollIterator<'_> {
27742774
EventPollIterator {
27752775
_marker: PhantomData,
27762776
}
@@ -2797,7 +2797,7 @@ impl crate::EventPump {
27972797
/// Returns a waiting iterator that calls `wait_event()`.
27982798
///
27992799
/// Note: The iterator will never terminate.
2800-
pub fn wait_iter(&mut self) -> EventWaitIterator {
2800+
pub fn wait_iter(&mut self) -> EventWaitIterator<'_> {
28012801
EventWaitIterator {
28022802
_marker: PhantomData,
28032803
}
@@ -2807,15 +2807,15 @@ impl crate::EventPump {
28072807
///
28082808
/// Note: The iterator will never terminate, unless waiting for an event
28092809
/// exceeds the specified timeout.
2810-
pub fn wait_timeout_iter(&mut self, timeout: u32) -> EventWaitTimeoutIterator {
2810+
pub fn wait_timeout_iter(&mut self, timeout: u32) -> EventWaitTimeoutIterator<'_> {
28112811
EventWaitTimeoutIterator {
28122812
_marker: PhantomData,
28132813
timeout,
28142814
}
28152815
}
28162816

28172817
#[inline]
2818-
pub fn keyboard_state(&self) -> crate::keyboard::KeyboardState {
2818+
pub fn keyboard_state(&self) -> crate::keyboard::KeyboardState<'_> {
28192819
crate::keyboard::KeyboardState::new(self)
28202820
}
28212821

src/sdl2/gfx/rotozoom.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,25 @@ use sys::gfx::rotozoom;
99
/// `RotozoomSurface` for work with rust-sdl2 Surface type
1010
pub trait RotozoomSurface {
1111
/// Rotates and zooms a surface and optional anti-aliasing.
12-
fn rotozoom(&self, angle: f64, zoom: f64, smooth: bool) -> Result<Surface, String>;
12+
fn rotozoom(&self, angle: f64, zoom: f64, smooth: bool) -> Result<Surface<'_>, String>;
1313
/// Rotates and zooms a surface with different horizontal and vertical scaling factors and optional anti-aliasing.
1414
fn rotozoom_xy(
1515
&self,
1616
angle: f64,
1717
zoomx: f64,
1818
zoomy: f64,
1919
smooth: bool,
20-
) -> Result<Surface, String>;
20+
) -> Result<Surface<'_>, String>;
2121
/// Zoom a surface by independent horizontal and vertical factors with optional smoothing.
22-
fn zoom(&self, zoomx: f64, zoomy: f64, smooth: bool) -> Result<Surface, String>;
22+
fn zoom(&self, zoomx: f64, zoomy: f64, smooth: bool) -> Result<Surface<'_>, String>;
2323
/// Shrink a surface by an integer ratio using averaging.
24-
fn shrink(&self, factorx: i32, factory: i32) -> Result<Surface, String>;
24+
fn shrink(&self, factorx: i32, factory: i32) -> Result<Surface<'_>, String>;
2525
/// Rotates a 8/16/24/32 bit surface in increments of 90 degrees.
26-
fn rotate_90deg(&self, turns: i32) -> Result<Surface, String>;
26+
fn rotate_90deg(&self, turns: i32) -> Result<Surface<'_>, String>;
2727
}
2828

2929
impl<'a> RotozoomSurface for Surface<'a> {
30-
fn rotozoom(&self, angle: f64, zoom: f64, smooth: bool) -> Result<Surface, String> {
30+
fn rotozoom(&self, angle: f64, zoom: f64, smooth: bool) -> Result<Surface<'_>, String> {
3131
let raw = unsafe { rotozoom::rotozoomSurface(self.raw(), angle, zoom, smooth as c_int) };
3232
if (raw as *mut ()).is_null() {
3333
Err(get_error())
@@ -41,7 +41,7 @@ impl<'a> RotozoomSurface for Surface<'a> {
4141
zoomx: f64,
4242
zoomy: f64,
4343
smooth: bool,
44-
) -> Result<Surface, String> {
44+
) -> Result<Surface<'_>, String> {
4545
let raw = unsafe {
4646
rotozoom::rotozoomSurfaceXY(self.raw(), angle, zoomx, zoomy, smooth as c_int)
4747
};
@@ -51,15 +51,15 @@ impl<'a> RotozoomSurface for Surface<'a> {
5151
unsafe { Ok(Surface::from_ll(raw)) }
5252
}
5353
}
54-
fn zoom(&self, zoomx: f64, zoomy: f64, smooth: bool) -> Result<Surface, String> {
54+
fn zoom(&self, zoomx: f64, zoomy: f64, smooth: bool) -> Result<Surface<'_>, String> {
5555
let raw = unsafe { rotozoom::zoomSurface(self.raw(), zoomx, zoomy, smooth as c_int) };
5656
if (raw as *mut ()).is_null() {
5757
Err(get_error())
5858
} else {
5959
unsafe { Ok(Surface::from_ll(raw)) }
6060
}
6161
}
62-
fn shrink(&self, factorx: i32, factory: i32) -> Result<Surface, String> {
62+
fn shrink(&self, factorx: i32, factory: i32) -> Result<Surface<'_>, String> {
6363
let raw =
6464
unsafe { rotozoom::shrinkSurface(self.raw(), factorx as c_int, factory as c_int) };
6565
if (raw as *mut ()).is_null() {
@@ -68,7 +68,7 @@ impl<'a> RotozoomSurface for Surface<'a> {
6868
unsafe { Ok(Surface::from_ll(raw)) }
6969
}
7070
}
71-
fn rotate_90deg(&self, turns: i32) -> Result<Surface, String> {
71+
fn rotate_90deg(&self, turns: i32) -> Result<Surface<'_>, String> {
7272
let raw = unsafe { rotozoom::rotateSurface90Degrees(self.raw(), turns as c_int) };
7373
if (raw as *mut ()).is_null() {
7474
Err(get_error())

src/sdl2/hint.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub enum Hint {
2525
/// ```
2626
///
2727
/// * `value`: `true` to enable minimizing of the Window if it loses key focus when in fullscreen mode,
28-
/// `false` to disable this feature.
28+
/// `false` to disable this feature.
2929
pub fn set_video_minimize_on_focus_loss(value: bool) -> bool {
3030
set(VIDEO_MINIMIZE_ON_FOCUS_LOSS, if value { "1" } else { "0" })
3131
}
@@ -41,10 +41,10 @@ pub fn set_video_minimize_on_focus_loss(value: bool) -> bool {
4141
/// ```
4242
///
4343
/// * `value`: `true` to enable minimizing of the Window if it loses key focus when in fullscreen mode,
44-
/// `false` to disable this feature.
44+
/// `false` to disable this feature.
4545
/// * `priority`: The priority controls the behavior when setting a hint that already has a value.
46-
/// Hints will replace existing hints of their priority and lower.
47-
/// Environment variables are considered to have override priority.
46+
/// Hints will replace existing hints of their priority and lower.
47+
/// Environment variables are considered to have override priority.
4848
pub fn set_video_minimize_on_focus_loss_with_priority(value: bool, priority: &Hint) -> bool {
4949
set_with_priority(
5050
VIDEO_MINIMIZE_ON_FOCUS_LOSS,

src/sdl2/image/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,12 @@ impl<'a> SaveSurface for Surface<'a> {
134134

135135
/// Method extensions for creating Textures from a `TextureCreator`
136136
pub trait LoadTexture {
137-
fn load_texture<P: AsRef<Path>>(&self, filename: P) -> Result<Texture, String>;
138-
fn load_texture_bytes(&self, buf: &[u8]) -> Result<Texture, String>;
137+
fn load_texture<P: AsRef<Path>>(&self, filename: P) -> Result<Texture<'_>, String>;
138+
fn load_texture_bytes(&self, buf: &[u8]) -> Result<Texture<'_>, String>;
139139
}
140140

141141
impl<T> LoadTexture for TextureCreator<T> {
142-
fn load_texture<P: AsRef<Path>>(&self, filename: P) -> Result<Texture, String> {
142+
fn load_texture<P: AsRef<Path>>(&self, filename: P) -> Result<Texture<'_>, String> {
143143
//! Loads an SDL Texture from a file
144144
unsafe {
145145
let c_filename = CString::new(filename.as_ref().to_str().unwrap()).unwrap();
@@ -153,7 +153,7 @@ impl<T> LoadTexture for TextureCreator<T> {
153153
}
154154

155155
#[doc(alias = "IMG_LoadTexture")]
156-
fn load_texture_bytes(&self, buf: &[u8]) -> Result<Texture, String> {
156+
fn load_texture_bytes(&self, buf: &[u8]) -> Result<Texture<'_>, String> {
157157
//! Loads an SDL Texture from a buffer that the format must be something supported by SDL2_image (png, jpeg, ect, but NOT RGBA8888 bytes for instance)
158158
unsafe {
159159
let buf = sdl2_sys::SDL_RWFromMem(buf.as_ptr() as *mut libc::c_void, buf.len() as i32);

src/sdl2/keyboard/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl<'a> KeyboardState<'a> {
7272
}
7373

7474
/// Returns an iterator all scancodes with a boolean indicating if the scancode is pressed.
75-
pub fn scancodes(&self) -> ScancodeIterator {
75+
pub fn scancodes(&self) -> ScancodeIterator<'_> {
7676
ScancodeIterator {
7777
index: 0,
7878
keyboard_state: self.keyboard_state,
@@ -102,7 +102,7 @@ impl<'a> KeyboardState<'a> {
102102
/// // sugar for: new.difference(old).collect()
103103
/// }
104104
/// ```
105-
pub fn pressed_scancodes(&self) -> PressedScancodeIterator {
105+
pub fn pressed_scancodes(&self) -> PressedScancodeIterator<'_> {
106106
self.scancodes().into_pressed_scancode_iter()
107107
}
108108
}

src/sdl2/log.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl Category {
4545
}
4646

4747
fn into_ll(value: Category) -> u32 {
48-
return match value {
48+
match value {
4949
Category::Application => sys::SDL_LogCategory::SDL_LOG_CATEGORY_APPLICATION as u32,
5050
Category::Error => sys::SDL_LogCategory::SDL_LOG_CATEGORY_ERROR as u32,
5151
Category::Assert => sys::SDL_LogCategory::SDL_LOG_CATEGORY_ASSERT as u32,
@@ -57,7 +57,7 @@ impl Category {
5757
Category::Test => sys::SDL_LogCategory::SDL_LOG_CATEGORY_TEST as u32,
5858
Category::Custom => sys::SDL_LogCategory::SDL_LOG_CATEGORY_CUSTOM as u32,
5959
Category::Unknown => sys::SDL_LogCategory::SDL_LOG_CATEGORY_APPLICATION as u32,
60-
};
60+
}
6161
}
6262
}
6363

@@ -80,7 +80,7 @@ impl Priority {
8080
SDL_LOG_PRIORITY_INFO => Priority::Info,
8181
SDL_LOG_PRIORITY_WARN => Priority::Warn,
8282
SDL_LOG_PRIORITY_ERROR => Priority::Error,
83-
SDL_LOG_PRIORITY_CRITICAL | _ => Priority::Critical,
83+
_ /* | SDL_LOG_PRIORITY_CRITICAL */ => Priority::Critical,
8484
}
8585
}
8686
}

src/sdl2/mixer/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ pub fn init(flags: InitFlag) -> Result<Sdl2MixerContext, String> {
163163
/// or require more fine-grained control over the device configuration, use [`open_audio_device`].
164164
///
165165
/// * `chunksize`: It is recommended to choose values between 256 and 1024, depending on whether
166-
/// you prefer latency or compatibility. Small values reduce latency but may not
167-
/// work very well on older systems. For instance, a chunk size of 256 will give
168-
/// you a latency of 6ms, while a chunk size of 1024 will give you a latency of 23ms
169-
/// for a frequency of 44100kHz.
166+
/// you prefer latency or compatibility. Small values reduce latency but may not
167+
/// work very well on older systems. For instance, a chunk size of 256 will give
168+
/// you a latency of 6ms, while a chunk size of 1024 will give you a latency of 23ms
169+
/// for a frequency of 44100kHz.
170170
pub fn open_audio(
171171
frequency: i32,
172172
format: AudioFormat,
@@ -207,8 +207,8 @@ pub fn open_audio(
207207
/// * `format`: Audio format ([`AudioFormat`]).
208208
/// * `channels`: Number of channels (1 is mono, 2 is stereo, etc).
209209
/// * `chunksize`: Audio buffer size in sample FRAMES (total samples divided by channel count).
210-
/// The lower the number, the lower the latency, but you risk dropouts if it gets
211-
/// too low.
210+
/// The lower the number, the lower the latency, but you risk dropouts if it gets
211+
/// too low.
212212
/// * `device`: The device name to open, or [`None`] to choose a reasonable default.
213213
/// * `allowed_changes`: Allow change flags ([`AllowChangeFlag`]).
214214
///
@@ -545,7 +545,7 @@ impl Channel {
545545
match ret {
546546
mixer::Mix_Fading_MIX_FADING_OUT => Fading::FadingOut,
547547
mixer::Mix_Fading_MIX_FADING_IN => Fading::FadingIn,
548-
mixer::Mix_Fading_MIX_NO_FADING | _ => Fading::NoFading,
548+
_ /* | mixer::Mix_Fading_MIX_NO_FADING */ => Fading::NoFading,
549549
}
550550
}
551551

@@ -872,7 +872,7 @@ impl<'a> Music<'a> {
872872
mixer::Mix_MusicType_MUS_MP3_MAD_UNUSED => MusicType::MusicMp3Mad,
873873
mixer::Mix_MusicType_MUS_FLAC => MusicType::MusicFlac,
874874
mixer::Mix_MusicType_MUS_MODPLUG_UNUSED => MusicType::MusicModPlug,
875-
mixer::Mix_MusicType_MUS_NONE | _ => MusicType::MusicNone,
875+
_ /* | mixer::Mix_MusicType_MUS_NONE */ => MusicType::MusicNone,
876876
}
877877
}
878878

@@ -1029,7 +1029,7 @@ impl<'a> Music<'a> {
10291029
match ret {
10301030
mixer::Mix_Fading_MIX_FADING_OUT => Fading::FadingOut,
10311031
mixer::Mix_Fading_MIX_FADING_IN => Fading::FadingIn,
1032-
mixer::Mix_Fading_MIX_NO_FADING | _ => Fading::NoFading,
1032+
_ /* | mixer::Mix_Fading_MIX_NO_FADING */ => Fading::NoFading,
10331033
}
10341034
}
10351035
}

0 commit comments

Comments
 (0)