Skip to content

Commit a9893f0

Browse files
committed
clean up clippy warnings
1 parent e7c2be2 commit a9893f0

File tree

13 files changed

+85
-88
lines changed

13 files changed

+85
-88
lines changed

src/sdl2/controller.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ impl Axis {
224224
})
225225
}
226226

227-
pub fn to_ll(&self) -> sys::SDL_GameControllerAxis {
228-
match *self {
227+
pub fn to_ll(self) -> sys::SDL_GameControllerAxis {
228+
match self {
229229
Axis::LeftX => sys::SDL_GameControllerAxis::SDL_CONTROLLER_AXIS_LEFTX,
230230
Axis::LeftY => sys::SDL_GameControllerAxis::SDL_CONTROLLER_AXIS_LEFTY,
231231
Axis::RightX => sys::SDL_GameControllerAxis::SDL_CONTROLLER_AXIS_RIGHTX,
@@ -302,8 +302,8 @@ impl Button {
302302
})
303303
}
304304

305-
pub fn to_ll(&self) -> sys::SDL_GameControllerButton {
306-
match *self {
305+
pub fn to_ll(self) -> sys::SDL_GameControllerButton {
306+
match self {
307307
Button::A => sys::SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_A,
308308
Button::B => sys::SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_B,
309309
Button::X => sys::SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_X,

src/sdl2/event.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ pub enum WindowEvent {
380380
}
381381

382382
impl WindowEvent {
383-
#[cfg_attr(feature = "cargo-clippy", allow(match_same_arms))]
383+
#[allow(clippy::match_same_arms)]
384384
fn from_ll(id: u8, data1: i32, data2: i32) -> WindowEvent {
385385
match id {
386386
0 => WindowEvent::None,

src/sdl2/hint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::ffi::{CString, CStr};
22
use crate::sys;
33
use libc::c_char;
44

5-
const VIDEO_MINIMIZE_ON_FOCUS_LOSS: &'static str = "SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS";
5+
const VIDEO_MINIMIZE_ON_FOCUS_LOSS: &str = "SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS";
66

77
pub enum Hint {
88
Default,

src/sdl2/joystick.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ impl PowerLevel {
115115
}
116116
}
117117

118-
pub fn to_ll(&self) -> SDL_JoystickPowerLevel {
119-
match *self {
118+
pub fn to_ll(self) -> SDL_JoystickPowerLevel {
119+
match self {
120120
PowerLevel::Unknown => SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_UNKNOWN,
121121
PowerLevel::Empty => SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_EMPTY,
122122
PowerLevel::Low => SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_LOW,
@@ -497,8 +497,8 @@ impl HatState {
497497
}
498498
}
499499

500-
pub fn to_raw(&self) -> u8 {
501-
match *self {
500+
pub fn to_raw(self) -> u8 {
501+
match self {
502502
HatState::Centered => 0,
503503
HatState::Up => 1,
504504
HatState::Right => 2,

src/sdl2/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
#![crate_name = "sdl2"]
4949
#![crate_type = "lib"]
5050

51-
#![cfg_attr(feature = "cargo-clippy", allow(cast_lossless, transmute_ptr_to_ref))]
51+
#![allow(clippy::cast_lossless, clippy::transmute_ptr_to_ref)]
5252

5353
extern crate num;
5454
pub extern crate libc;

src/sdl2/mouse/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ impl MouseWheelDirection {
118118
}
119119
}
120120
#[inline]
121-
pub fn to_ll(&self) -> u32 {
122-
match *self {
121+
pub fn to_ll(self) -> u32 {
122+
match self {
123123
MouseWheelDirection::Normal => 0,
124124
MouseWheelDirection::Flipped => 1,
125125
MouseWheelDirection::Unknown(direction) => direction,

src/sdl2/pixels.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl Color {
116116
Color { r, g, b, a }
117117
}
118118

119-
pub fn to_u32(&self, format: &PixelFormat) -> u32 {
119+
pub fn to_u32(self, format: &PixelFormat) -> u32 {
120120
unsafe { sys::SDL_MapRGBA(format.raw, self.r, self.g, self.b, self.a) }
121121
}
122122

@@ -130,18 +130,18 @@ impl Color {
130130
}
131131

132132
#[inline]
133-
pub fn rgb(&self) -> (u8, u8, u8) {
133+
pub fn rgb(self) -> (u8, u8, u8) {
134134
(self.r, self.g, self.b)
135135
}
136136

137137
#[inline]
138-
pub fn rgba(&self) -> (u8, u8, u8, u8) {
138+
pub fn rgba(self) -> (u8, u8, u8, u8) {
139139
(self.r, self.g, self.b, self.a)
140140
}
141141

142142
// Implemented manually and kept private, because reasons
143143
#[inline]
144-
fn raw(&self) -> sys::SDL_Color {
144+
fn raw(self) -> sys::SDL_Color {
145145
sys::SDL_Color { r: self.r, g: self.g, b: self.b, a: self.a }
146146
}
147147
}
@@ -293,8 +293,8 @@ impl PixelFormatEnum {
293293

294294
/// Calculates the total byte size of an image buffer, given its pitch
295295
/// and height.
296-
pub fn byte_size_from_pitch_and_height(&self, pitch: usize, height: usize) -> usize {
297-
match *self {
296+
pub fn byte_size_from_pitch_and_height(self, pitch: usize, height: usize) -> usize {
297+
match self {
298298
PixelFormatEnum::YV12 | PixelFormatEnum::IYUV => {
299299
// YUV is 4:2:0.
300300
// `pitch` is the width of the Y component, and
@@ -306,9 +306,9 @@ impl PixelFormatEnum {
306306
}
307307
}
308308

309-
#[cfg_attr(feature = "cargo-clippy", allow(match_same_arms))]
310-
pub fn byte_size_of_pixels(&self, num_of_pixels: usize) -> usize {
311-
match *self {
309+
#[allow(clippy::match_same_arms)]
310+
pub fn byte_size_of_pixels(self, num_of_pixels: usize) -> usize {
311+
match self {
312312
PixelFormatEnum::RGB332
313313
=> num_of_pixels,
314314
PixelFormatEnum::RGB444 | PixelFormatEnum::RGB555 |
@@ -340,13 +340,13 @@ impl PixelFormatEnum {
340340
PixelFormatEnum::Unknown | PixelFormatEnum::Index1LSB |
341341
PixelFormatEnum::Index1MSB | PixelFormatEnum::Index4LSB |
342342
PixelFormatEnum::Index4MSB
343-
=> panic!("not supported format: {:?}", *self),
343+
=> panic!("not supported format: {:?}", self),
344344
}
345345
}
346346

347-
#[cfg_attr(feature = "cargo-clippy", allow(match_same_arms))]
348-
pub fn byte_size_per_pixel(&self) -> usize {
349-
match *self {
347+
#[allow(clippy::match_same_arms)]
348+
pub fn byte_size_per_pixel(self) -> usize {
349+
match self {
350350
PixelFormatEnum::RGB332
351351
=> 1,
352352
PixelFormatEnum::RGB444 | PixelFormatEnum::RGB555 |
@@ -377,13 +377,13 @@ impl PixelFormatEnum {
377377
PixelFormatEnum::Unknown | PixelFormatEnum::Index1LSB |
378378
PixelFormatEnum::Index1MSB | PixelFormatEnum::Index4LSB |
379379
PixelFormatEnum::Index4MSB
380-
=> panic!("not supported format: {:?}", *self),
380+
=> panic!("not supported format: {:?}", self),
381381
}
382382
}
383383

384-
pub fn supports_alpha(&self) -> bool {
384+
pub fn supports_alpha(self) -> bool {
385385
use crate::pixels::PixelFormatEnum::*;
386-
match *self {
386+
match self {
387387
ARGB4444 | ARGB1555 | ARGB8888 | ARGB2101010 |
388388
ABGR4444 | ABGR1555 | ABGR8888 |
389389
BGRA4444 | BGRA5551 | BGRA8888 |
@@ -396,7 +396,7 @@ impl PixelFormatEnum {
396396
impl From<PixelFormat> for PixelFormatEnum {
397397
fn from(pf: PixelFormat) -> PixelFormatEnum {
398398
unsafe {
399-
let ref sdl_pf = *pf.raw;
399+
let sdl_pf = *pf.raw;
400400
match PixelFormatEnum::from_u64(sdl_pf.format as u64) {
401401
Some(pfe) => pfe,
402402
None => panic!("Unknown pixel format: {:?}", sdl_pf.format)

src/sdl2/rect.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,7 @@ impl Rect {
430430
}
431431

432432
pub fn raw_slice(slice: &[Rect]) -> *const sys::SDL_Rect {
433-
unsafe {
434-
mem::transmute(slice.as_ptr())
435-
}
433+
slice.as_ptr() as *const sys::SDL_Rect
436434
}
437435

438436
pub fn from_ll(raw: sys::SDL_Rect) -> Rect {
@@ -626,7 +624,7 @@ impl Into<(i32, i32, u32, u32)> for Rect {
626624

627625
impl From<sys::SDL_Rect> for Rect {
628626
fn from(raw: sys::SDL_Rect) -> Rect {
629-
Rect { raw: raw }
627+
Rect { raw }
630628
}
631629
}
632630

@@ -768,18 +766,16 @@ impl Point {
768766
}
769767

770768
pub fn raw_slice(slice: &[Point]) -> *const sys::SDL_Point {
771-
unsafe {
772-
mem::transmute(slice.as_ptr())
773-
}
769+
slice.as_ptr() as *const sys::SDL_Point
774770
}
775771

776-
pub fn raw(&self) -> *const sys::SDL_Point {
772+
pub fn raw(self) -> *const sys::SDL_Point {
777773
&self.raw
778774
}
779775

780776
/// Returns a new point by shifting this point's coordinates by the given
781777
/// x and y values.
782-
pub fn offset(&self, x: i32, y: i32) -> Point {
778+
pub fn offset(self, x: i32, y: i32) -> Point {
783779
let x = match self.raw.x.checked_add(x) {
784780
Some(val) => val,
785781
None => {
@@ -805,18 +801,18 @@ impl Point {
805801

806802
/// Returns a new point by multiplying this point's coordinates by the
807803
/// given scale factor.
808-
pub fn scale(&self, f: i32) -> Point {
804+
pub fn scale(self, f: i32) -> Point {
809805
Point::new(clamped_mul(self.raw.x, f),
810806
clamped_mul(self.raw.y, f))
811807
}
812808

813809
/// Returns the x-coordinate of this point.
814-
pub fn x(&self) -> i32 {
810+
pub fn x(self) -> i32 {
815811
self.raw.x
816812
}
817813

818814
/// Returns the y-coordinate of this point.
819-
pub fn y(&self) -> i32 {
815+
pub fn y(self) -> i32 {
820816
self.raw.y
821817
}
822818
}

src/sdl2/render.rs

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,10 @@ impl<T: RenderTarget> Canvas<T> {
508508
if self.render_target_supported() {
509509
let target = unsafe { self.get_raw_target() };
510510
unsafe { self.set_raw_target(texture.raw) }
511-
.map_err(|e| TargetRenderError::SdlError(e))?;
511+
.map_err(TargetRenderError::SdlError)?;
512512
f(self);
513513
unsafe { self.set_raw_target(target) }
514-
.map_err(|e| TargetRenderError::SdlError(e))?;
514+
.map_err(TargetRenderError::SdlError)?;
515515
Ok(())
516516
} else {
517517
Err(TargetRenderError::NotSupported)
@@ -582,12 +582,12 @@ impl<T: RenderTarget> Canvas<T> {
582582
let target = unsafe { self.get_raw_target() };
583583
for &(ref texture, ref user_context) in textures {
584584
unsafe { self.set_raw_target(texture.raw) }
585-
.map_err(|e| TargetRenderError::SdlError(e))?;
585+
.map_err(TargetRenderError::SdlError)?;
586586
f(self, user_context);
587587
}
588588
// reset the target to its source
589589
unsafe { self.set_raw_target(target) }
590-
.map_err(|e| TargetRenderError::SdlError(e))?;
590+
.map_err(TargetRenderError::SdlError)?;
591591
Ok(())
592592
} else {
593593
Err(TargetRenderError::NotSupported)
@@ -1778,19 +1778,16 @@ impl InternalTexture {
17781778
match format {
17791779
PixelFormatEnum::YV12 |
17801780
PixelFormatEnum::IYUV => {
1781-
match rect {
1782-
Some(r) => {
1783-
if r.x() % 2 != 0 {
1784-
return Err(XMustBeMultipleOfTwoForFormat(r.x(), format));
1785-
} else if r.y() % 2 != 0 {
1786-
return Err(YMustBeMultipleOfTwoForFormat(r.y(), format));
1787-
} else if r.width() % 2 != 0 {
1788-
return Err(WidthMustBeMultipleOfTwoForFormat(r.width(), format));
1789-
} else if r.height() % 2 != 0 {
1790-
return Err(HeightMustBeMultipleOfTwoForFormat(r.height(), format));
1791-
}
1781+
if let Some(r) = rect {
1782+
if r.x() % 2 != 0 {
1783+
return Err(XMustBeMultipleOfTwoForFormat(r.x(), format));
1784+
} else if r.y() % 2 != 0 {
1785+
return Err(YMustBeMultipleOfTwoForFormat(r.y(), format));
1786+
} else if r.width() % 2 != 0 {
1787+
return Err(WidthMustBeMultipleOfTwoForFormat(r.width(), format));
1788+
} else if r.height() % 2 != 0 {
1789+
return Err(HeightMustBeMultipleOfTwoForFormat(r.height(), format));
17921790
}
1793-
_ => {}
17941791
};
17951792
if pitch % 2 != 0 {
17961793
return Err(PitchMustBeMultipleOfTwoForFormat(pitch, format));
@@ -1838,19 +1835,16 @@ impl InternalTexture {
18381835
None => ptr::null(),
18391836
};
18401837

1841-
match rect {
1842-
Some(ref r) => {
1843-
if r.x() % 2 != 0 {
1844-
return Err(XMustBeMultipleOfTwoForFormat(r.x()));
1845-
} else if r.y() % 2 != 0 {
1846-
return Err(YMustBeMultipleOfTwoForFormat(r.y()));
1847-
} else if r.width() % 2 != 0 {
1848-
return Err(WidthMustBeMultipleOfTwoForFormat(r.width()));
1849-
} else if r.height() % 2 != 0 {
1850-
return Err(HeightMustBeMultipleOfTwoForFormat(r.height()));
1851-
}
1838+
if let Some(ref r) = rect {
1839+
if r.x() % 2 != 0 {
1840+
return Err(XMustBeMultipleOfTwoForFormat(r.x()));
1841+
} else if r.y() % 2 != 0 {
1842+
return Err(YMustBeMultipleOfTwoForFormat(r.y()));
1843+
} else if r.width() % 2 != 0 {
1844+
return Err(WidthMustBeMultipleOfTwoForFormat(r.width()));
1845+
} else if r.height() % 2 != 0 {
1846+
return Err(HeightMustBeMultipleOfTwoForFormat(r.height()));
18521847
}
1853-
_ => {}
18541848
};
18551849

18561850
// If the destination rectangle lies outside the texture boundaries,

src/sdl2/sdl.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,16 @@ macro_rules! subsystem {
203203
}
204204
unsafe impl Sync for $name {}
205205

206-
impl $name {
206+
impl std::clone::Clone for $name {
207207
#[inline]
208-
pub fn clone(&self) -> $name {
208+
fn clone(&self) -> $name {
209209
$name {
210210
_subsystem_drop: self._subsystem_drop.clone()
211211
}
212212
}
213+
}
213214

215+
impl $name {
214216
/// Obtain an SDL context.
215217
#[inline]
216218
pub fn sdl(&self) -> Sdl {
@@ -328,9 +330,10 @@ pub fn get_error() -> String {
328330

329331
pub fn set_error(err: &str) -> Result<(), NulError> {
330332
let c_string = CString::new(err)?;
331-
Ok(unsafe {
333+
unsafe {
332334
sys::SDL_SetError(c_string.as_ptr() as *const c_char);
333-
})
335+
}
336+
Ok(())
334337
}
335338

336339
pub fn set_error_from_code(err: Error) {

0 commit comments

Comments
 (0)