diff --git a/glib-macros/src/utils.rs b/glib-macros/src/utils.rs index c71e1ad5b48d..47b28133f86a 100644 --- a/glib-macros/src/utils.rs +++ b/glib-macros/src/utils.rs @@ -267,7 +267,7 @@ mod tests { .value_required(); let found = parse_nested_meta_items(&input.attrs, "boxed_type", &mut [&mut gtype_name]); // The argument value was specified as required, so an error is returned - matches!(found, Err(_)); + assert!(found.is_err()); assert!(gtype_name.value.is_none()); // The argument key must be found though diff --git a/glib-macros/tests/properties.rs b/glib-macros/tests/properties.rs index f64949ff85b3..e59548cbd21c 100644 --- a/glib-macros/tests/properties.rs +++ b/glib-macros/tests/properties.rs @@ -426,6 +426,11 @@ mod ext_trait { glib::Object::builder().build() } } + impl Default for Author { + fn default() -> Self { + Self::new() + } + } } #[test] @@ -438,66 +443,65 @@ fn ext_trait() { assert_eq!(AuthorPropertiesExt::lastname(&author), "Doe"); } -#[cfg(test)] -mod kw_names { - mod imp { - - use glib::subclass::object::DerivedObjectProperties; - use glib::ObjectExt; - use std::cell::Cell; - - use glib::subclass::{prelude::ObjectImpl, types::ObjectSubclass}; - use glib_macros::Properties; - - #[derive(Properties, Default)] - #[properties(wrapper_type = super::KwNames)] - pub struct KwNames { - // Some of the strict keywords - #[property(get, set)] - r#loop: Cell, - #[property(get, set)] - r#move: Cell, - #[property(get, set)] - r#type: Cell, - - // Lexer 2018+ strict keywords - #[property(get, set)] - r#async: Cell, - #[property(get, set)] - r#await: Cell, - #[property(get, set)] - r#dyn: Cell, +#[test] +fn keyword_propnames() { + mod kw_names { + mod imp { + + use glib::subclass::object::DerivedObjectProperties; + use glib::ObjectExt; + use std::cell::Cell; + + use glib::subclass::{prelude::ObjectImpl, types::ObjectSubclass}; + use glib_macros::Properties; + + #[derive(Properties, Default)] + #[properties(wrapper_type = super::KwNames)] + pub struct KwNames { + // Some of the strict keywords + #[property(get, set)] + r#loop: Cell, + #[property(get, set)] + r#move: Cell, + #[property(get, set)] + r#type: Cell, + + // Lexer 2018+ strict keywords + #[property(get, set)] + r#async: Cell, + #[property(get, set)] + r#await: Cell, + #[property(get, set)] + r#dyn: Cell, + + // Some of the reserved keywords + #[property(get, set)] + r#become: Cell, + #[property(get, set)] + r#macro: Cell, + #[property(get, set)] + r#unsized: Cell, + + // Lexer 2018+ reserved keywords + #[property(get, set)] + r#try: Cell, + } - // Some of the reserved keywords - #[property(get, set)] - r#become: Cell, - #[property(get, set)] - r#macro: Cell, - #[property(get, set)] - r#unsized: Cell, + #[glib::object_subclass] + impl ObjectSubclass for KwNames { + const NAME: &'static str = "MyKwNames"; + type Type = super::KwNames; + } - // Lexer 2018+ reserved keywords - #[property(get, set)] - r#try: Cell, + #[glib::derived_properties] + impl ObjectImpl for KwNames {} } - #[glib::object_subclass] - impl ObjectSubclass for KwNames { - const NAME: &'static str = "MyKwNames"; - type Type = super::KwNames; + glib::wrapper! { + pub struct KwNames(ObjectSubclass); } - - #[glib::derived_properties] - impl ObjectImpl for KwNames {} } - glib::wrapper! { - pub struct KwNames(ObjectSubclass); - } -} - -#[test] -fn keyword_propnames() { let mykwnames: kw_names::KwNames = glib::Object::new(); // make sure all 10 properties are registered diff --git a/glib-macros/tests/test.rs b/glib-macros/tests/test.rs index 39803d4211b5..59bfdb12cc55 100644 --- a/glib-macros/tests/test.rs +++ b/glib-macros/tests/test.rs @@ -149,6 +149,7 @@ fn derive_boxed() { assert_eq!(b, v.get::().unwrap()); } +#[allow(clippy::unnecessary_literal_unwrap)] #[test] fn derive_boxed_nullable() { #[derive(Clone, Debug, PartialEq, Eq, glib::Boxed)] diff --git a/glib-macros/tests/value_delegate_derive.rs b/glib-macros/tests/value_delegate_derive.rs index 61a42be94e64..df1dce9dd642 100644 --- a/glib-macros/tests/value_delegate_derive.rs +++ b/glib-macros/tests/value_delegate_derive.rs @@ -129,6 +129,7 @@ fn into_value() { .is_none()); } +#[allow(clippy::unnecessary_literal_unwrap)] #[test] fn higher_level_types() { #[derive(Debug, ValueDelegate)] diff --git a/glib/src/boxed_inline.rs b/glib/src/boxed_inline.rs index a341d8da2e31..fd01ca20676e 100644 --- a/glib/src/boxed_inline.rs +++ b/glib/src/boxed_inline.rs @@ -16,6 +16,7 @@ macro_rules! glib_boxed_inline_wrapper { $(pub(crate) phantom: std::marker::PhantomData<$($generic),+>,)? } + #[allow(clippy::incorrect_clone_impl_on_copy_type)] impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? std::clone::Clone for $name $(<$($generic),+>)? { #[inline] fn clone(&self) -> Self { @@ -48,6 +49,7 @@ macro_rules! glib_boxed_inline_wrapper { $(pub(crate) phantom: std::marker::PhantomData<$($generic),+>,)? } + #[allow(clippy::incorrect_clone_impl_on_copy_type)] impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? std::clone::Clone for $name $(<$($generic),+>)? { #[inline] fn clone(&self) -> Self { diff --git a/glib/src/collections/strv.rs b/glib/src/collections/strv.rs index eee1f6f5f6cb..c3de86c334e0 100644 --- a/glib/src/collections/strv.rs +++ b/glib/src/collections/strv.rs @@ -499,7 +499,7 @@ impl StrV { } else { // Need to clone every item because we don't own it here for i in 0..len { - let p = ptr.add(i) as *mut *const c_char; + let p = ptr.add(i); *p = ffi::g_strdup(*p); } diff --git a/glib/src/gstring.rs b/glib/src/gstring.rs index 6ac012b1abf7..edabfb2a20b0 100644 --- a/glib/src/gstring.rs +++ b/glib/src/gstring.rs @@ -1204,7 +1204,7 @@ impl GString { pub fn as_str(&self) -> &str { unsafe { let (ptr, len) = match self.0 { - Inner::Native(ref s) => (s.as_ptr() as *const u8, s.len() - 1), + Inner::Native(ref s) => (s.as_ptr(), s.len() - 1), Inner::Foreign { ptr, len } => (ptr.as_ptr() as *const u8, len), Inner::Inline { len, ref data } => (data.as_ptr(), len as usize), }; @@ -2006,6 +2006,7 @@ impl FromGlibPtrBorrow<*mut i8> for GString { } } +#[allow(clippy::unnecessary_cast)] #[doc(hidden)] impl<'a> ToGlibPtr<'a, *const u8> for GString { type Storage = PhantomData<&'a Self>; @@ -2021,6 +2022,7 @@ impl<'a> ToGlibPtr<'a, *const u8> for GString { } } +#[allow(clippy::unnecessary_cast)] #[doc(hidden)] impl<'a> ToGlibPtr<'a, *const i8> for GString { type Storage = PhantomData<&'a Self>; @@ -2036,6 +2038,7 @@ impl<'a> ToGlibPtr<'a, *const i8> for GString { } } +#[allow(clippy::unnecessary_cast)] #[doc(hidden)] impl<'a> ToGlibPtr<'a, *mut u8> for GString { type Storage = PhantomData<&'a Self>; @@ -2051,6 +2054,7 @@ impl<'a> ToGlibPtr<'a, *mut u8> for GString { } } +#[allow(clippy::unnecessary_cast)] #[doc(hidden)] impl<'a> ToGlibPtr<'a, *mut i8> for GString { type Storage = PhantomData<&'a Self>; diff --git a/glib/src/main_context_futures.rs b/glib/src/main_context_futures.rs index 59a2ddf82b76..04d3e9282164 100644 --- a/glib/src/main_context_futures.rs +++ b/glib/src/main_context_futures.rs @@ -95,7 +95,7 @@ impl TaskSource { ptr::drop_in_place(&mut (*source).future); } FutureWrapper::NonSend(ref mut future) => { - let context = ffi::g_source_get_context(source as *mut Self as *mut ffi::GSource); + let context = ffi::g_source_get_context(source as *mut ffi::GSource); if !context.is_null() { let future = ptr::read(future); let context = MainContext::from_glib_none(context); diff --git a/glib/src/param_spec.rs b/glib/src/param_spec.rs index 59bd4d5983b4..890b0b033c42 100644 --- a/glib/src/param_spec.rs +++ b/glib/src/param_spec.rs @@ -49,7 +49,7 @@ unsafe impl<'a> crate::value::FromValue<'a> for ParamSpec { unsafe fn from_value(value: &'a crate::Value) -> Self { let ptr = gobject_ffi::g_value_dup_param(value.to_glib_none().0); debug_assert!(!ptr.is_null()); - from_glib_full(ptr as *mut gobject_ffi::GParamSpec) + from_glib_full(ptr) } } @@ -530,6 +530,7 @@ macro_rules! define_param_spec_default { ($rust_type:ident, $ffi_type:path, $value_type:ty, $from_glib:expr) => { impl $rust_type { #[inline] + #[allow(clippy::redundant_closure_call)] pub fn default_value(&self) -> $value_type { unsafe { let ptr = diff --git a/glib/src/value.rs b/glib/src/value.rs index 8468e8b327b0..a462b84a735c 100644 --- a/glib/src/value.rs +++ b/glib/src/value.rs @@ -1216,6 +1216,7 @@ macro_rules! numeric { type Checker = GenericValueTypeChecker; #[inline] + #[allow(clippy::redundant_closure_call)] unsafe fn from_value(value: &'a Value) -> Self { $get(value.to_glib_none().0) } @@ -1223,6 +1224,7 @@ macro_rules! numeric { impl ToValue for $name { #[inline] + #[allow(clippy::redundant_closure_call)] fn to_value(&self) -> Value { let mut value = Value::for_value_type::(); unsafe { @@ -1487,7 +1489,7 @@ mod tests { #[test] fn test_strv() { - let v = vec!["123", "456"].to_value(); + let v = ["123", "456"].to_value(); assert_eq!( v.get::>(), Ok(vec![GString::from("123"), GString::from("456")])