From 95f684470232fe087018e59bfdec66e76529a8cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 21 Feb 2019 19:30:36 +0200 Subject: [PATCH] Fix various minor clippy warnings --- examples/src/bin/gtkvideooverlay.rs | 2 + examples/src/bin/rtpfecclient.rs | 1 - examples/src/bin/rtpfecserver.rs | 1 - examples/src/bin/tagsetter.rs | 2 +- gstreamer-app/src/app_sink.rs | 4 +- gstreamer-check/src/harness.rs | 8 ++-- gstreamer-pbutils/src/discoverer.rs | 3 +- gstreamer-player/src/lib.rs | 1 + gstreamer-player/src/player.rs | 12 +++--- gstreamer-rtsp-server/src/rtsp_auth.rs | 2 +- .../src/rtsp_session_pool.rs | 3 +- gstreamer-video/src/functions.rs | 1 - gstreamer-video/src/video_info.rs | 6 +-- gstreamer/src/bin.rs | 2 +- gstreamer/src/bufferlist_serde.rs | 4 +- gstreamer/src/bus.rs | 2 - gstreamer/src/clock.rs | 4 +- gstreamer/src/pad.rs | 40 ++++++------------- gstreamer/src/subclass/error.rs | 35 ++++++++-------- gstreamer/src/typefind.rs | 4 +- tutorials/src/bin/basic-tutorial-3.rs | 2 +- tutorials/src/bin/basic-tutorial-5.rs | 20 ++++------ tutorials/src/bin/basic-tutorial-9.rs | 2 +- 23 files changed, 69 insertions(+), 92 deletions(-) diff --git a/examples/src/bin/gtkvideooverlay.rs b/examples/src/bin/gtkvideooverlay.rs index f4a9d0dd5..e36642c4e 100644 --- a/examples/src/bin/gtkvideooverlay.rs +++ b/examples/src/bin/gtkvideooverlay.rs @@ -128,6 +128,7 @@ fn create_ui(app: >k::Application) { // This is unsafe because the "window handle" we pass here is basically like a raw pointer. // If a wrong value were to be passed here (and you can pass any integer), then the window // system will most likely cause the application to crash. + #[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))] unsafe { // Here we ask gdk what native window handle we got assigned for // our video region from the window system, and then we will @@ -151,6 +152,7 @@ fn create_ui(app: >k::Application) { // This is unsafe because the "window handle" we pass here is basically like a raw pointer. // If a wrong value were to be passed here (and you can pass any integer), then the window // system will most likely cause the application to crash. + #[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))] unsafe { // Here we ask gdk what native window handle we got assigned for // our video region from the windowing system, and then we will diff --git a/examples/src/bin/rtpfecclient.rs b/examples/src/bin/rtpfecclient.rs index 3d178d749..6211202d1 100644 --- a/examples/src/bin/rtpfecclient.rs +++ b/examples/src/bin/rtpfecclient.rs @@ -226,7 +226,6 @@ fn example_main() -> Result<(), Error> { ("Failed to link srcpad"), ["{}", err] ); - () } } }); diff --git a/examples/src/bin/rtpfecserver.rs b/examples/src/bin/rtpfecserver.rs index 93b340a8e..2ae6a9e20 100644 --- a/examples/src/bin/rtpfecserver.rs +++ b/examples/src/bin/rtpfecserver.rs @@ -154,7 +154,6 @@ fn example_main() -> Result<(), Error> { ("Failed to link decodebin srcpad"), ["{}", err] ); - () } } }); diff --git a/examples/src/bin/tagsetter.rs b/examples/src/bin/tagsetter.rs index d11b8d41e..c7259b402 100644 --- a/examples/src/bin/tagsetter.rs +++ b/examples/src/bin/tagsetter.rs @@ -64,7 +64,7 @@ fn example_main() -> Result<(), Error> { Ok(pipeline) => pipeline, Err(err) => { if let Some(gst::ParseError::NoSuchElement) = err.kind::() { - return Err(MissingElement(context.get_missing_elements().join(",".into())).into()); + return Err(MissingElement(context.get_missing_elements().join(",")).into()); } else { return Err(err.into()); } diff --git a/gstreamer-app/src/app_sink.rs b/gstreamer-app/src/app_sink.rs index bff01b1ed..bff56d686 100644 --- a/gstreamer-app/src/app_sink.rs +++ b/gstreamer-app/src/app_sink.rs @@ -216,7 +216,7 @@ unsafe extern "C" fn new_sample_trampoline< this: *mut ffi::GstAppSink, f: glib_ffi::gpointer, ) -> gst_ffi::GstFlowReturn { - let f: &F = transmute(f); + let f: &F = &*(f as *const F); let ret: gst::FlowReturn = f(&from_glib_borrow(this)).into(); ret.to_glib() } @@ -227,7 +227,7 @@ unsafe extern "C" fn new_preroll_trampoline< this: *mut ffi::GstAppSink, f: glib_ffi::gpointer, ) -> gst_ffi::GstFlowReturn { - let f: &F = transmute(f); + let f: &F = &*(f as *const F); let ret: gst::FlowReturn = f(&from_glib_borrow(this)).into(); ret.to_glib() } diff --git a/gstreamer-check/src/harness.rs b/gstreamer-check/src/harness.rs index 5f0de4753..aa9549444 100644 --- a/gstreamer-check/src/harness.rs +++ b/gstreamer-check/src/harness.rs @@ -704,7 +704,7 @@ impl Harness { } } - pub fn get_sink_harness<'a>(&'a self) -> Option> { + pub fn get_sink_harness(&self) -> Option { unsafe { let sink_harness = (*self.0.as_ptr()).sink_harness; if sink_harness.is_null() { @@ -721,7 +721,7 @@ impl Harness { } } - pub fn get_src_harness<'a>(&'a self) -> Option> { + pub fn get_src_harness(&self) -> Option { unsafe { let src_harness = (*self.0.as_ptr()).src_harness; if src_harness.is_null() { @@ -738,7 +738,7 @@ impl Harness { } } - pub fn get_mut_sink_harness<'a>(&'a mut self) -> Option> { + pub fn get_mut_sink_harness(&mut self) -> Option { unsafe { let sink_harness = (*self.0.as_ptr()).sink_harness; if sink_harness.is_null() { @@ -755,7 +755,7 @@ impl Harness { } } - pub fn get_mut_src_harness<'a>(&'a mut self) -> Option> { + pub fn get_mut_src_harness(&mut self) -> Option { unsafe { let src_harness = (*self.0.as_ptr()).src_harness; if src_harness.is_null() { diff --git a/gstreamer-pbutils/src/discoverer.rs b/gstreamer-pbutils/src/discoverer.rs index d3aafed9e..6a5288c97 100644 --- a/gstreamer-pbutils/src/discoverer.rs +++ b/gstreamer-pbutils/src/discoverer.rs @@ -71,7 +71,6 @@ unsafe extern "C" fn notify_timeout_trampoline, { - #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] - let f: &F = transmute(f); + let f: &F = &*(f as *const F); f(&Discoverer::from_glib_borrow(this).unsafe_cast()) } diff --git a/gstreamer-player/src/lib.rs b/gstreamer-player/src/lib.rs index 29dc1d082..3c8587b00 100644 --- a/gstreamer-player/src/lib.rs +++ b/gstreamer-player/src/lib.rs @@ -34,6 +34,7 @@ pub use glib::{Cast, Continue, Error, IsA, StaticType, ToValue, Type, TypedValue #[cfg_attr(feature = "cargo-clippy", allow(match_same_arms))] #[cfg_attr(feature = "cargo-clippy", allow(type_complexity))] #[cfg_attr(feature = "cargo-clippy", allow(useless_transmute))] +#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))] #[rustfmt::skip] mod auto; pub use auto::*; diff --git a/gstreamer-player/src/player.rs b/gstreamer-player/src/player.rs index 3666ae9b8..087d50e34 100644 --- a/gstreamer-player/src/player.rs +++ b/gstreamer-player/src/player.rs @@ -56,6 +56,7 @@ impl Player { &self, f: F, ) -> SignalHandlerId { + #[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))] unsafe { let f: Box_ = Box_::new(f); connect_raw( @@ -71,6 +72,7 @@ impl Player { &self, f: F, ) -> SignalHandlerId { + #[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))] unsafe { let f: Box_ = Box_::new(f); connect_raw( @@ -86,6 +88,7 @@ impl Player { &self, f: F, ) -> SignalHandlerId { + #[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))] unsafe { let f: Box_ = Box_::new(f); connect_raw( @@ -105,8 +108,7 @@ unsafe extern "C" fn duration_changed_trampoline< object: u64, f: glib_ffi::gpointer, ) { - #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] - let f: &F = transmute(f); + let f: &F = &*(f as *const F); f(&from_glib_borrow(this), gst::ClockTime(Some(object))) } @@ -117,8 +119,7 @@ unsafe extern "C" fn position_updated_trampoline< object: u64, f: glib_ffi::gpointer, ) { - #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] - let f: &F = transmute(f); + let f: &F = &*(f as *const F); f(&from_glib_borrow(this), gst::ClockTime(Some(object))) } @@ -127,7 +128,6 @@ unsafe extern "C" fn seek_done_trampoline, { - let f: &F = transmute(f); + let f: &F = &*(f as *const F); match f( &RTSPAuth::from_glib_borrow(this).unsafe_cast(), &from_glib_borrow(connection), diff --git a/gstreamer-rtsp-server/src/rtsp_session_pool.rs b/gstreamer-rtsp-server/src/rtsp_session_pool.rs index 1ff1b935c..492a68f4c 100644 --- a/gstreamer-rtsp-server/src/rtsp_session_pool.rs +++ b/gstreamer-rtsp-server/src/rtsp_session_pool.rs @@ -13,8 +13,7 @@ unsafe extern "C" fn trampoline_watch Continue + S pool: *mut ffi::GstRTSPSessionPool, func: gpointer, ) -> gboolean { - #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] - let func: &RefCell = transmute(func); + let func: &RefCell = &*(func as *const RefCell); (&mut *func.borrow_mut())(&from_glib_borrow(pool)).to_glib() } diff --git a/gstreamer-video/src/functions.rs b/gstreamer-video/src/functions.rs index 675fdcb15..b5c42376c 100644 --- a/gstreamer-video/src/functions.rs +++ b/gstreamer-video/src/functions.rs @@ -79,7 +79,6 @@ unsafe fn convert_sample_async_unsafe( ) where F: FnOnce(Result) + 'static, { - #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] let callback: &mut Option = &mut *(user_data as *mut Option); let callback = callback.take().unwrap(); diff --git a/gstreamer-video/src/video_info.rs b/gstreamer-video/src/video_info.rs index d42acf943..f32268afc 100644 --- a/gstreamer-video/src/video_info.rs +++ b/gstreamer-video/src/video_info.rs @@ -449,9 +449,9 @@ impl VideoInfo { #[cfg(not(any(feature = "v1_12", feature = "dox")))] { VideoInfoBuilder { - format: format, - width: width, - height: height, + format, + width, + height, interlace_mode: None, flags: None, size: None, diff --git a/gstreamer/src/bin.rs b/gstreamer/src/bin.rs index 7f736d5f3..dc9788d99 100644 --- a/gstreamer/src/bin.rs +++ b/gstreamer/src/bin.rs @@ -163,7 +163,7 @@ unsafe extern "C" fn do_latency_trampoline< where P: IsA, { - let f: &F = transmute(f); + let f: &F = &*(f as *const F); match f(&Bin::from_glib_borrow(this).unsafe_cast()) { Ok(()) => true, Err(err) => { diff --git a/gstreamer/src/bufferlist_serde.rs b/gstreamer/src/bufferlist_serde.rs index d6d82797c..cd0407b19 100644 --- a/gstreamer/src/bufferlist_serde.rs +++ b/gstreamer/src/bufferlist_serde.rs @@ -17,11 +17,11 @@ use BufferListRef; impl Serialize for BufferListRef { fn serialize(&self, serializer: S) -> Result { - let mut iter = self.iter(); + let iter = self.iter(); let (remaining, _) = iter.size_hint(); if remaining > 0 { let mut seq = serializer.serialize_seq(Some(remaining))?; - while let Some(ref buffer) = iter.next() { + for buffer in iter { seq.serialize_element(buffer)?; } seq.end() diff --git a/gstreamer/src/bus.rs b/gstreamer/src/bus.rs index 76252b788..b6c0e40e9 100644 --- a/gstreamer/src/bus.rs +++ b/gstreamer/src/bus.rs @@ -25,7 +25,6 @@ unsafe extern "C" fn trampoline_watch Continue + 'st msg: *mut ffi::GstMessage, func: gpointer, ) -> gboolean { - #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] let func: &RefCell = &*(func as *const RefCell); (&mut *func.borrow_mut())(&from_glib_borrow(bus), &Message::from_glib_borrow(msg)).to_glib() } @@ -49,7 +48,6 @@ unsafe extern "C" fn trampoline_sync< msg: *mut ffi::GstMessage, func: gpointer, ) -> ffi::GstBusSyncReply { - #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] let f: &F = &*(func as *const F); let res = f(&from_glib_borrow(bus), &Message::from_glib_borrow(msg)).to_glib(); diff --git a/gstreamer/src/clock.rs b/gstreamer/src/clock.rs index dec438902..836943fa9 100644 --- a/gstreamer/src/clock.rs +++ b/gstreamer/src/clock.rs @@ -14,7 +14,6 @@ use glib_ffi::{gboolean, gpointer}; use libc::c_void; use std::cmp; use std::mem; -use std::mem::transmute; use std::ptr; use Clock; use ClockError; @@ -39,8 +38,7 @@ unsafe extern "C" fn trampoline_wait_async gboolean { - #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] - let f: &F = transmute(func); + let f: &F = &*(func as *const F); f( &from_glib_borrow(clock), from_glib(time), diff --git a/gstreamer/src/pad.rs b/gstreamer/src/pad.rs index d56d9d9ea..418c61657 100644 --- a/gstreamer/src/pad.rs +++ b/gstreamer/src/pad.rs @@ -31,7 +31,6 @@ use StaticPadTemplate; use std::cell::RefCell; use std::mem; -use std::mem::transmute; use std::ptr; use glib; @@ -1009,8 +1008,7 @@ unsafe extern "C" fn trampoline_pad_probe< where T: IsA, { - #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] - let func: &F = transmute(func); + let func: &F = &*(func as *const F); let mut data_type = None; let mut probe_info = PadProbeInfo { @@ -1089,8 +1087,7 @@ unsafe extern "C" fn trampoline_activate_function< where T: IsA, { - #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] - let func: &F = transmute((*pad).activatedata); + let func: &F = &*((*pad).activatedata as *const F); match func( &Pad::from_glib_borrow(pad).unsafe_cast(), @@ -1117,8 +1114,7 @@ unsafe extern "C" fn trampoline_activatemode_function< where T: IsA, { - #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] - let func: &F = transmute((*pad).activatemodedata); + let func: &F = &*((*pad).activatemodedata as *const F); match func( &&Pad::from_glib_borrow(pad).unsafe_cast(), @@ -1146,8 +1142,7 @@ unsafe extern "C" fn trampoline_chain_function< where T: IsA, { - #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] - let func: &F = transmute((*pad).chaindata); + let func: &F = &*((*pad).chaindata as *const F); let res: FlowReturn = func( &Pad::from_glib_borrow(pad).unsafe_cast(), @@ -1172,8 +1167,7 @@ unsafe extern "C" fn trampoline_chain_list_function< where T: IsA, { - #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] - let func: &F = transmute((*pad).chainlistdata); + let func: &F = &*((*pad).chainlistdata as *const F); let res: FlowReturn = func( &Pad::from_glib_borrow(pad).unsafe_cast(), @@ -1195,8 +1189,7 @@ unsafe extern "C" fn trampoline_event_function< where T: IsA, { - #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] - let func: &F = transmute((*pad).eventdata); + let func: &F = &*((*pad).eventdata as *const F); func( &Pad::from_glib_borrow(pad).unsafe_cast(), @@ -1217,8 +1210,7 @@ unsafe extern "C" fn trampoline_event_full_function< where T: IsA, { - #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] - let func: &F = transmute((*pad).eventdata); + let func: &F = &*((*pad).eventdata as *const F); let res: FlowReturn = func( &Pad::from_glib_borrow(pad).unsafe_cast(), @@ -1242,8 +1234,7 @@ unsafe extern "C" fn trampoline_getrange_function< where T: IsA, { - #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] - let func: &F = transmute((*pad).getrangedata); + let func: &F = &*((*pad).getrangedata as *const F); match func( &Pad::from_glib_borrow(pad).unsafe_cast(), @@ -1269,8 +1260,7 @@ unsafe extern "C" fn trampoline_iterate_internal_links_function< where T: IsA, { - #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] - let func: &F = transmute((*pad).iterintlinkdata); + let func: &F = &*((*pad).iterintlinkdata as *const F); // Steal the iterator and return it let ret = func( @@ -1297,8 +1287,7 @@ unsafe extern "C" fn trampoline_link_function< where T: IsA, { - #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] - let func: &F = transmute((*pad).linkdata); + let func: &F = &*((*pad).linkdata as *const F); let res: ::PadLinkReturn = func( &Pad::from_glib_borrow(pad).unsafe_cast(), @@ -1320,8 +1309,7 @@ unsafe extern "C" fn trampoline_query_function< where T: IsA, { - #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] - let func: &F = transmute((*pad).querydata); + let func: &F = &*((*pad).querydata as *const F); func( &Pad::from_glib_borrow(pad).unsafe_cast(), @@ -1340,8 +1328,7 @@ unsafe extern "C" fn trampoline_unlink_function< ) where T: IsA, { - #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] - let func: &F = transmute((*pad).unlinkdata); + let func: &F = &*((*pad).unlinkdata as *const F); func( &Pad::from_glib_borrow(pad).unsafe_cast(), @@ -1354,8 +1341,7 @@ unsafe extern "C" fn destroy_closure(ptr: gpointer) { } unsafe extern "C" fn trampoline_pad_task(func: gpointer) { - #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] - let func: &RefCell = transmute(func); + let func: &RefCell = &*(func as *const RefCell); (&mut *func.borrow_mut())() } diff --git a/gstreamer/src/subclass/error.rs b/gstreamer/src/subclass/error.rs index b71366204..44e0ce90d 100644 --- a/gstreamer/src/subclass/error.rs +++ b/gstreamer/src/subclass/error.rs @@ -20,24 +20,27 @@ macro_rules! gst_panic_to_error( use std::sync::atomic::Ordering; use $crate::ElementExtManual; - if $panicked.load(Ordering::Relaxed) { - $element.post_error_message(&gst_error_msg!($crate::LibraryError::Failed, ["Panicked"])); - $ret - } else { - let result = panic::catch_unwind(AssertUnwindSafe(|| $code)); + #[cfg_attr(feature = "cargo-clippy", allow(unused_unit))] + { + if $panicked.load(Ordering::Relaxed) { + $element.post_error_message(&gst_error_msg!($crate::LibraryError::Failed, ["Panicked"])); + $ret + } else { + let result = panic::catch_unwind(AssertUnwindSafe(|| $code)); - match result { - Ok(result) => result, - Err(err) => { - $panicked.store(true, Ordering::Relaxed); - if let Some(cause) = err.downcast_ref::<&str>() { - $element.post_error_message(&gst_error_msg!($crate::LibraryError::Failed, ["Panicked: {}", cause])); - } else if let Some(cause) = err.downcast_ref::() { - $element.post_error_message(&gst_error_msg!($crate::LibraryError::Failed, ["Panicked: {}", cause])); - } else { - $element.post_error_message(&gst_error_msg!($crate::LibraryError::Failed, ["Panicked"])); + match result { + Ok(result) => result, + Err(err) => { + $panicked.store(true, Ordering::Relaxed); + if let Some(cause) = err.downcast_ref::<&str>() { + $element.post_error_message(&gst_error_msg!($crate::LibraryError::Failed, ["Panicked: {}", cause])); + } else if let Some(cause) = err.downcast_ref::() { + $element.post_error_message(&gst_error_msg!($crate::LibraryError::Failed, ["Panicked: {}", cause])); + } else { + $element.post_error_message(&gst_error_msg!($crate::LibraryError::Failed, ["Panicked"])); + } + $ret } - $ret } } } diff --git a/gstreamer/src/typefind.rs b/gstreamer/src/typefind.rs index 98133852d..16e478963 100644 --- a/gstreamer/src/typefind.rs +++ b/gstreamer/src/typefind.rs @@ -16,7 +16,6 @@ use glib; use glib::translate::*; use glib_ffi; use std::marker::PhantomData; -use std::mem; use std::ptr; use std::slice; @@ -119,8 +118,7 @@ unsafe extern "C" fn type_find_trampoline *mut c_void; } + #[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))] unsafe { let xid = gdk_x11_window_get_xid(gdk_window.as_ptr() as *mut _); video_overlay.set_window_handle(xid as usize); @@ -237,6 +232,7 @@ mod tutorial5 { ) -> *mut c_void; } + #[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))] unsafe { let window = gdk_quartz_window_get_nsview(gdk_window.as_ptr() as *mut _); video_overlay.set_window_handle(window as usize); diff --git a/tutorials/src/bin/basic-tutorial-9.rs b/tutorials/src/bin/basic-tutorial-9.rs index ae839f881..2dbdaa57f 100644 --- a/tutorials/src/bin/basic-tutorial-9.rs +++ b/tutorials/src/bin/basic-tutorial-9.rs @@ -18,7 +18,7 @@ fn send_value_as_str(v: &glib::SendValue) -> Option { if let Some(s) = v.get::<&str>() { Some(s.to_string()) } else if let Some(serialized) = v.serialize() { - Some(serialized.into()) + Some(serialized) } else { None }