Skip to content

Commit

Permalink
Merge pull request #1173 from sdroege/clippy-warnings
Browse files Browse the repository at this point in the history
Fix/silence various 1.72 clippy warnings
  • Loading branch information
sdroege committed Aug 24, 2023
2 parents 8986eb9 + d6da7aa commit cab7e1c
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 59 deletions.
2 changes: 1 addition & 1 deletion glib-macros/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
110 changes: 57 additions & 53 deletions glib-macros/tests/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,11 @@ mod ext_trait {
glib::Object::builder().build()
}
}
impl Default for Author {
fn default() -> Self {
Self::new()
}
}
}

#[test]
Expand All @@ -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<u8>,
#[property(get, set)]
r#move: Cell<u8>,
#[property(get, set)]
r#type: Cell<u8>,

// Lexer 2018+ strict keywords
#[property(get, set)]
r#async: Cell<u8>,
#[property(get, set)]
r#await: Cell<u8>,
#[property(get, set)]
r#dyn: Cell<u8>,
#[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<u8>,
#[property(get, set)]
r#move: Cell<u8>,
#[property(get, set)]
r#type: Cell<u8>,

// Lexer 2018+ strict keywords
#[property(get, set)]
r#async: Cell<u8>,
#[property(get, set)]
r#await: Cell<u8>,
#[property(get, set)]
r#dyn: Cell<u8>,

// Some of the reserved keywords
#[property(get, set)]
r#become: Cell<u8>,
#[property(get, set)]
r#macro: Cell<u8>,
#[property(get, set)]
r#unsized: Cell<u8>,

// Lexer 2018+ reserved keywords
#[property(get, set)]
r#try: Cell<u8>,
}

// Some of the reserved keywords
#[property(get, set)]
r#become: Cell<u8>,
#[property(get, set)]
r#macro: Cell<u8>,
#[property(get, set)]
r#unsized: Cell<u8>,
#[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<u8>,
#[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<imp::KwNames>);
}

#[glib::derived_properties]
impl ObjectImpl for KwNames {}
}

glib::wrapper! {
pub struct KwNames(ObjectSubclass<imp::KwNames>);
}
}

#[test]
fn keyword_propnames() {
let mykwnames: kw_names::KwNames = glib::Object::new();

// make sure all 10 properties are registered
Expand Down
1 change: 1 addition & 0 deletions glib-macros/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ fn derive_boxed() {
assert_eq!(b, v.get::<MyBoxed>().unwrap());
}

#[allow(clippy::unnecessary_literal_unwrap)]
#[test]
fn derive_boxed_nullable() {
#[derive(Clone, Debug, PartialEq, Eq, glib::Boxed)]
Expand Down
1 change: 1 addition & 0 deletions glib-macros/tests/value_delegate_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ fn into_value() {
.is_none());
}

#[allow(clippy::unnecessary_literal_unwrap)]
#[test]
fn higher_level_types() {
#[derive(Debug, ValueDelegate)]
Expand Down
2 changes: 2 additions & 0 deletions glib/src/boxed_inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion glib/src/collections/strv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 5 additions & 1 deletion glib/src/gstring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
Expand Down Expand Up @@ -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>;
Expand All @@ -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>;
Expand All @@ -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>;
Expand All @@ -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>;
Expand Down
2 changes: 1 addition & 1 deletion glib/src/main_context_futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion glib/src/param_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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 =
Expand Down
4 changes: 3 additions & 1 deletion glib/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1216,13 +1216,15 @@ macro_rules! numeric {
type Checker = GenericValueTypeChecker<Self>;

#[inline]
#[allow(clippy::redundant_closure_call)]
unsafe fn from_value(value: &'a Value) -> Self {
$get(value.to_glib_none().0)
}
}

impl ToValue for $name {
#[inline]
#[allow(clippy::redundant_closure_call)]
fn to_value(&self) -> Value {
let mut value = Value::for_value_type::<Self>();
unsafe {
Expand Down Expand Up @@ -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::<Vec<GString>>(),
Ok(vec![GString::from("123"), GString::from("456")])
Expand Down

0 comments on commit cab7e1c

Please sign in to comment.