Skip to content

Commit 48509ea

Browse files
committed
Merge pull request #1390
2 parents b3ac580 + 995d239 commit 48509ea

30 files changed

+496
-664
lines changed

changelog.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ when upgrading from a version of rust-sdl2 to another.
88

99
[PR #1378](https://github.com/Rust-SDL2/rust-sdl2/pull/1378) **BREAKING CHANGE** Change `Keycode` to be a struct rather than an enum. Fix `Keycode::from_scancode` for non-QWERTY keyboard layouts.
1010

11+
[PR #1390](https://github.com/Rust-SDL2/rust-sdl2/pull/1390) Apply clippy fixes, fix deprecations and other code quality improvements.
12+
1113
[PR #1368](https://github.com/Rust-SDL2/rust-sdl2/pull/1368) Remove unnecessary unsafe in Window interface. Make Window `Clone`.
1214

1315
[PR #1366](https://github.com/Rust-SDL2/rust-sdl2/pull/1366) Add Primary Selection bindings.
@@ -22,7 +24,7 @@ when upgrading from a version of rust-sdl2 to another.
2224

2325
[PR #1250](https://github.com/Rust-SDL2/rust-sdl2/pull/1250) Add `lib64` to native library search path when using bundled feature
2426

25-
[PR #1240](https://github.com/Rust-SDL2/rust-sdl2/pull/1240) **BREAKING CHANGE** Take `PixelMasks` by refrence
27+
[PR #1240](https://github.com/Rust-SDL2/rust-sdl2/pull/1240) **BREAKING CHANGE** Take `PixelMasks` by reference
2628

2729
[PR #1254](https://github.com/Rust-SDL2/rust-sdl2/pull/1254) **BREAKING CHANGE** Make `SdlDrop` and `SubsystemDrop` safer; forbid external code from constructing `SdlDrop`
2830

@@ -34,8 +36,6 @@ when upgrading from a version of rust-sdl2 to another.
3436

3537
[PR #1337](https://github.com/Rust-SDL2/rust-sdl2/pull/1337) Fix "Cannot initialize Sdl from more than one thread" for tests / CI
3638

37-
[PR #1337](https://github.com/Rust-SDL2/rust-sdl2/pull/1337) Fix "Cannot initialize Sdl from more than one thread" for tests / CI
38-
3939
[PR #1346](https://github.com/Rust-SDL2/rust-sdl2/pull/1346) Add basic Shaped Window support
4040

4141
[PR #1314](https://github.com/Rust-SDL2/rust-sdl2/pull/1314) Add "ALWAYS ON TOP" support for X11

sdl2-sys/build.rs

+19-17
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ macro_rules! add_msvc_includes_to_bindings {
3636
fn init_submodule(sdl_path: &Path) {
3737
if !sdl_path.join("CMakeLists.txt").exists() {
3838
Command::new("git")
39-
.args(&["submodule", "update", "--init"])
40-
.current_dir(sdl_path.clone())
39+
.args(["submodule", "update", "--init"])
40+
.current_dir(sdl_path)
4141
.status()
4242
.expect("Git is needed to retrieve the SDL source files");
4343
}
@@ -436,15 +436,17 @@ fn copy_library_file(src_path: &Path, target_path: &Path) {
436436
for path in &[target_path, &deps_path] {
437437
let dst_path = path.join(src_path.file_name().expect("Path missing filename"));
438438

439-
fs::copy(&src_path, &dst_path).expect(&format!(
440-
"Failed to copy SDL2 dynamic library from {} to {}",
441-
src_path.to_string_lossy(),
442-
dst_path.to_string_lossy()
443-
));
439+
fs::copy(src_path, &dst_path).unwrap_or_else(|_| {
440+
panic!(
441+
"Failed to copy SDL2 dynamic library from {} to {}",
442+
src_path.to_string_lossy(),
443+
dst_path.to_string_lossy()
444+
)
445+
});
444446
}
445447
}
446448

447-
fn copy_dynamic_libraries(sdl2_compiled_path: &PathBuf, target_os: &str) {
449+
fn copy_dynamic_libraries(sdl2_compiled_path: &Path, target_os: &str) {
448450
let target_path = find_cargo_target_dir();
449451

450452
// Windows binaries do not embed library search paths, so successfully
@@ -651,35 +653,35 @@ fn generate_bindings(target: &str, host: &str, headers_paths: &[String]) {
651653
// Set correct target triple for bindgen when cross-compiling
652654
if target != host {
653655
bindings = bindings.clang_arg("-target");
654-
bindings = bindings.clang_arg(target.clone());
656+
bindings = bindings.clang_arg(target);
655657

656658
if cfg!(feature = "image") {
657659
image_bindings = image_bindings.clang_arg("-target");
658-
image_bindings = image_bindings.clang_arg(target.clone());
660+
image_bindings = image_bindings.clang_arg(target);
659661
}
660662

661663
if cfg!(feature = "ttf") {
662664
ttf_bindings = ttf_bindings.clang_arg("-target");
663-
ttf_bindings = ttf_bindings.clang_arg(target.clone());
665+
ttf_bindings = ttf_bindings.clang_arg(target);
664666
}
665667

666668
if cfg!(feature = "mixer") {
667669
mixer_bindings = mixer_bindings.clang_arg("-target");
668-
mixer_bindings = mixer_bindings.clang_arg(target.clone());
670+
mixer_bindings = mixer_bindings.clang_arg(target);
669671
}
670672

671673
if cfg!(feature = "gfx") {
672674
gfx_framerate_bindings = gfx_framerate_bindings.clang_arg("-target");
673-
gfx_framerate_bindings = gfx_framerate_bindings.clang_arg(target.clone());
675+
gfx_framerate_bindings = gfx_framerate_bindings.clang_arg(target);
674676

675677
gfx_primitives_bindings = gfx_primitives_bindings.clang_arg("-target");
676-
gfx_primitives_bindings = gfx_primitives_bindings.clang_arg(target.clone());
678+
gfx_primitives_bindings = gfx_primitives_bindings.clang_arg(target);
677679

678680
gfx_imagefilter_bindings = gfx_imagefilter_bindings.clang_arg("-target");
679-
gfx_imagefilter_bindings = gfx_imagefilter_bindings.clang_arg(target.clone());
681+
gfx_imagefilter_bindings = gfx_imagefilter_bindings.clang_arg(target);
680682

681683
gfx_rotozoom_bindings = gfx_rotozoom_bindings.clang_arg("-target");
682-
gfx_rotozoom_bindings = gfx_rotozoom_bindings.clang_arg(target.clone());
684+
gfx_rotozoom_bindings = gfx_rotozoom_bindings.clang_arg(target);
683685
}
684686
}
685687

@@ -943,5 +945,5 @@ fn generate_bindings(target: &str, host: &str, headers_paths: &[String]) {
943945
}
944946

945947
fn get_os_from_triple(triple: &str) -> Option<&str> {
946-
triple.splitn(3, "-").nth(2)
948+
triple.splitn(3, '-').nth(2)
947949
}

src/sdl2/audio.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -774,10 +774,7 @@ impl<'a, Channel: AudioFormatNum> AudioQueue<Channel> {
774774

775775
let mut obtained = MaybeUninit::uninit();
776776
unsafe {
777-
let device = match device.into() {
778-
Some(device) => Some(CString::new(device).unwrap()),
779-
None => None,
780-
};
777+
let device = device.into().map(|device| CString::new(device).unwrap());
781778
// Warning: map_or consumes its argument; `device.map_or()` would therefore consume the
782779
// CString and drop it, making device_ptr a dangling pointer! To avoid that we downgrade
783780
// device to an Option<&_> first.
@@ -801,7 +798,7 @@ impl<'a, Channel: AudioFormatNum> AudioQueue<Channel> {
801798
Ok(AudioQueue {
802799
subsystem: a.clone(),
803800
device_id,
804-
phantom: PhantomData::default(),
801+
phantom: PhantomData,
805802
spec,
806803
})
807804
}
@@ -850,7 +847,7 @@ impl<'a, Channel: AudioFormatNum> AudioQueue<Channel> {
850847
sys::SDL_QueueAudio(
851848
self.device_id.id(),
852849
data.as_ptr() as *const c_void,
853-
(data.len() * mem::size_of::<Channel>()) as u32,
850+
mem::size_of_val(data) as u32,
854851
)
855852
};
856853
result == 0
@@ -863,7 +860,7 @@ impl<'a, Channel: AudioFormatNum> AudioQueue<Channel> {
863860
sys::SDL_QueueAudio(
864861
self.device_id.id(),
865862
data.as_ptr() as *const c_void,
866-
(data.len() * mem::size_of::<Channel>()) as u32,
863+
mem::size_of_val(data) as u32,
867864
)
868865
};
869866
if result == 0 {
@@ -918,10 +915,7 @@ impl<CB: AudioCallback> AudioDevice<CB> {
918915

919916
let mut obtained = MaybeUninit::uninit();
920917
unsafe {
921-
let device = match device.into() {
922-
Some(device) => Some(CString::new(device).unwrap()),
923-
None => None,
924-
};
918+
let device = device.into().map(|device| CString::new(device).unwrap());
925919
// Warning: map_or consumes its argument; `device.map_or()` would therefore consume the
926920
// CString and drop it, making device_ptr a dangling pointer! To avoid that we downgrade
927921
// device to an Option<&_> first.

src/sdl2/common.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,4 @@ impl fmt::Display for IntegerOrSdlError {
3636
}
3737
}
3838

39-
impl Error for IntegerOrSdlError {
40-
fn description(&self) -> &str {
41-
use self::IntegerOrSdlError::*;
42-
43-
match *self {
44-
IntegerOverflows(_, _) => "integer overflow",
45-
SdlError(ref e) => e,
46-
}
47-
}
48-
}
39+
impl Error for IntegerOrSdlError {}

src/sdl2/controller.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,10 @@ impl fmt::Display for AddMappingError {
4141
}
4242

4343
impl error::Error for AddMappingError {
44-
fn description(&self) -> &str {
45-
use self::AddMappingError::*;
46-
47-
match *self {
48-
InvalidMapping(_) => "invalid mapping",
49-
InvalidFilePath(_) => "invalid file path",
50-
ReadError(_) => "read error",
51-
SdlError(ref e) => e,
44+
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
45+
match self {
46+
Self::InvalidMapping(err) => Some(err),
47+
Self::InvalidFilePath(_) | Self::ReadError(_) | Self::SdlError(_) => None,
5248
}
5349
}
5450
}
@@ -126,9 +122,7 @@ impl GameControllerSubsystem {
126122
/// Return `true` if controller events are processed.
127123
#[doc(alias = "SDL_GameControllerEventState")]
128124
pub fn event_state(&self) -> bool {
129-
unsafe {
130-
sys::SDL_GameControllerEventState(sys::SDL_QUERY as i32) == sys::SDL_ENABLE as i32
131-
}
125+
unsafe { sys::SDL_GameControllerEventState(sys::SDL_QUERY) == sys::SDL_ENABLE as i32 }
132126
}
133127

134128
/// Add a new controller input mapping from a mapping string.
@@ -172,7 +166,7 @@ impl GameControllerSubsystem {
172166

173167
/// Load controller input mappings from an SDL [`RWops`] object.
174168
#[doc(alias = "SDL_GameControllerAddMappingsFromRW")]
175-
pub fn load_mappings_from_rw<'a>(&self, rw: RWops<'a>) -> Result<i32, AddMappingError> {
169+
pub fn load_mappings_from_rw(&self, rw: RWops<'_>) -> Result<i32, AddMappingError> {
176170
use self::AddMappingError::*;
177171

178172
let result = unsafe { sys::SDL_GameControllerAddMappingsFromRW(rw.raw(), 0) };

0 commit comments

Comments
 (0)