Skip to content

Commit d6da7aa

Browse files
committed
Fix/silence various 1.72 clippy warnings
1 parent 8986eb9 commit d6da7aa

File tree

10 files changed

+74
-59
lines changed

10 files changed

+74
-59
lines changed

glib-macros/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ mod tests {
267267
.value_required();
268268
let found = parse_nested_meta_items(&input.attrs, "boxed_type", &mut [&mut gtype_name]);
269269
// The argument value was specified as required, so an error is returned
270-
matches!(found, Err(_));
270+
assert!(found.is_err());
271271
assert!(gtype_name.value.is_none());
272272

273273
// The argument key must be found though

glib-macros/tests/properties.rs

Lines changed: 57 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,11 @@ mod ext_trait {
426426
glib::Object::builder().build()
427427
}
428428
}
429+
impl Default for Author {
430+
fn default() -> Self {
431+
Self::new()
432+
}
433+
}
429434
}
430435

431436
#[test]
@@ -438,66 +443,65 @@ fn ext_trait() {
438443
assert_eq!(AuthorPropertiesExt::lastname(&author), "Doe");
439444
}
440445

441-
#[cfg(test)]
442-
mod kw_names {
443-
mod imp {
444-
445-
use glib::subclass::object::DerivedObjectProperties;
446-
use glib::ObjectExt;
447-
use std::cell::Cell;
448-
449-
use glib::subclass::{prelude::ObjectImpl, types::ObjectSubclass};
450-
use glib_macros::Properties;
451-
452-
#[derive(Properties, Default)]
453-
#[properties(wrapper_type = super::KwNames)]
454-
pub struct KwNames {
455-
// Some of the strict keywords
456-
#[property(get, set)]
457-
r#loop: Cell<u8>,
458-
#[property(get, set)]
459-
r#move: Cell<u8>,
460-
#[property(get, set)]
461-
r#type: Cell<u8>,
462-
463-
// Lexer 2018+ strict keywords
464-
#[property(get, set)]
465-
r#async: Cell<u8>,
466-
#[property(get, set)]
467-
r#await: Cell<u8>,
468-
#[property(get, set)]
469-
r#dyn: Cell<u8>,
446+
#[test]
447+
fn keyword_propnames() {
448+
mod kw_names {
449+
mod imp {
450+
451+
use glib::subclass::object::DerivedObjectProperties;
452+
use glib::ObjectExt;
453+
use std::cell::Cell;
454+
455+
use glib::subclass::{prelude::ObjectImpl, types::ObjectSubclass};
456+
use glib_macros::Properties;
457+
458+
#[derive(Properties, Default)]
459+
#[properties(wrapper_type = super::KwNames)]
460+
pub struct KwNames {
461+
// Some of the strict keywords
462+
#[property(get, set)]
463+
r#loop: Cell<u8>,
464+
#[property(get, set)]
465+
r#move: Cell<u8>,
466+
#[property(get, set)]
467+
r#type: Cell<u8>,
468+
469+
// Lexer 2018+ strict keywords
470+
#[property(get, set)]
471+
r#async: Cell<u8>,
472+
#[property(get, set)]
473+
r#await: Cell<u8>,
474+
#[property(get, set)]
475+
r#dyn: Cell<u8>,
476+
477+
// Some of the reserved keywords
478+
#[property(get, set)]
479+
r#become: Cell<u8>,
480+
#[property(get, set)]
481+
r#macro: Cell<u8>,
482+
#[property(get, set)]
483+
r#unsized: Cell<u8>,
484+
485+
// Lexer 2018+ reserved keywords
486+
#[property(get, set)]
487+
r#try: Cell<u8>,
488+
}
470489

471-
// Some of the reserved keywords
472-
#[property(get, set)]
473-
r#become: Cell<u8>,
474-
#[property(get, set)]
475-
r#macro: Cell<u8>,
476-
#[property(get, set)]
477-
r#unsized: Cell<u8>,
490+
#[glib::object_subclass]
491+
impl ObjectSubclass for KwNames {
492+
const NAME: &'static str = "MyKwNames";
493+
type Type = super::KwNames;
494+
}
478495

479-
// Lexer 2018+ reserved keywords
480-
#[property(get, set)]
481-
r#try: Cell<u8>,
496+
#[glib::derived_properties]
497+
impl ObjectImpl for KwNames {}
482498
}
483499

484-
#[glib::object_subclass]
485-
impl ObjectSubclass for KwNames {
486-
const NAME: &'static str = "MyKwNames";
487-
type Type = super::KwNames;
500+
glib::wrapper! {
501+
pub struct KwNames(ObjectSubclass<imp::KwNames>);
488502
}
489-
490-
#[glib::derived_properties]
491-
impl ObjectImpl for KwNames {}
492503
}
493504

494-
glib::wrapper! {
495-
pub struct KwNames(ObjectSubclass<imp::KwNames>);
496-
}
497-
}
498-
499-
#[test]
500-
fn keyword_propnames() {
501505
let mykwnames: kw_names::KwNames = glib::Object::new();
502506

503507
// make sure all 10 properties are registered

glib-macros/tests/test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ fn derive_boxed() {
149149
assert_eq!(b, v.get::<MyBoxed>().unwrap());
150150
}
151151

152+
#[allow(clippy::unnecessary_literal_unwrap)]
152153
#[test]
153154
fn derive_boxed_nullable() {
154155
#[derive(Clone, Debug, PartialEq, Eq, glib::Boxed)]

glib-macros/tests/value_delegate_derive.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ fn into_value() {
129129
.is_none());
130130
}
131131

132+
#[allow(clippy::unnecessary_literal_unwrap)]
132133
#[test]
133134
fn higher_level_types() {
134135
#[derive(Debug, ValueDelegate)]

glib/src/boxed_inline.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ macro_rules! glib_boxed_inline_wrapper {
1616
$(pub(crate) phantom: std::marker::PhantomData<$($generic),+>,)?
1717
}
1818

19+
#[allow(clippy::incorrect_clone_impl_on_copy_type)]
1920
impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? std::clone::Clone for $name $(<$($generic),+>)? {
2021
#[inline]
2122
fn clone(&self) -> Self {
@@ -48,6 +49,7 @@ macro_rules! glib_boxed_inline_wrapper {
4849
$(pub(crate) phantom: std::marker::PhantomData<$($generic),+>,)?
4950
}
5051

52+
#[allow(clippy::incorrect_clone_impl_on_copy_type)]
5153
impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? std::clone::Clone for $name $(<$($generic),+>)? {
5254
#[inline]
5355
fn clone(&self) -> Self {

glib/src/collections/strv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ impl StrV {
499499
} else {
500500
// Need to clone every item because we don't own it here
501501
for i in 0..len {
502-
let p = ptr.add(i) as *mut *const c_char;
502+
let p = ptr.add(i);
503503
*p = ffi::g_strdup(*p);
504504
}
505505

glib/src/gstring.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ impl GString {
12041204
pub fn as_str(&self) -> &str {
12051205
unsafe {
12061206
let (ptr, len) = match self.0 {
1207-
Inner::Native(ref s) => (s.as_ptr() as *const u8, s.len() - 1),
1207+
Inner::Native(ref s) => (s.as_ptr(), s.len() - 1),
12081208
Inner::Foreign { ptr, len } => (ptr.as_ptr() as *const u8, len),
12091209
Inner::Inline { len, ref data } => (data.as_ptr(), len as usize),
12101210
};
@@ -2006,6 +2006,7 @@ impl FromGlibPtrBorrow<*mut i8> for GString {
20062006
}
20072007
}
20082008

2009+
#[allow(clippy::unnecessary_cast)]
20092010
#[doc(hidden)]
20102011
impl<'a> ToGlibPtr<'a, *const u8> for GString {
20112012
type Storage = PhantomData<&'a Self>;
@@ -2021,6 +2022,7 @@ impl<'a> ToGlibPtr<'a, *const u8> for GString {
20212022
}
20222023
}
20232024

2025+
#[allow(clippy::unnecessary_cast)]
20242026
#[doc(hidden)]
20252027
impl<'a> ToGlibPtr<'a, *const i8> for GString {
20262028
type Storage = PhantomData<&'a Self>;
@@ -2036,6 +2038,7 @@ impl<'a> ToGlibPtr<'a, *const i8> for GString {
20362038
}
20372039
}
20382040

2041+
#[allow(clippy::unnecessary_cast)]
20392042
#[doc(hidden)]
20402043
impl<'a> ToGlibPtr<'a, *mut u8> for GString {
20412044
type Storage = PhantomData<&'a Self>;
@@ -2051,6 +2054,7 @@ impl<'a> ToGlibPtr<'a, *mut u8> for GString {
20512054
}
20522055
}
20532056

2057+
#[allow(clippy::unnecessary_cast)]
20542058
#[doc(hidden)]
20552059
impl<'a> ToGlibPtr<'a, *mut i8> for GString {
20562060
type Storage = PhantomData<&'a Self>;

glib/src/main_context_futures.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl TaskSource {
9595
ptr::drop_in_place(&mut (*source).future);
9696
}
9797
FutureWrapper::NonSend(ref mut future) => {
98-
let context = ffi::g_source_get_context(source as *mut Self as *mut ffi::GSource);
98+
let context = ffi::g_source_get_context(source as *mut ffi::GSource);
9999
if !context.is_null() {
100100
let future = ptr::read(future);
101101
let context = MainContext::from_glib_none(context);

glib/src/param_spec.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ unsafe impl<'a> crate::value::FromValue<'a> for ParamSpec {
4949
unsafe fn from_value(value: &'a crate::Value) -> Self {
5050
let ptr = gobject_ffi::g_value_dup_param(value.to_glib_none().0);
5151
debug_assert!(!ptr.is_null());
52-
from_glib_full(ptr as *mut gobject_ffi::GParamSpec)
52+
from_glib_full(ptr)
5353
}
5454
}
5555

@@ -530,6 +530,7 @@ macro_rules! define_param_spec_default {
530530
($rust_type:ident, $ffi_type:path, $value_type:ty, $from_glib:expr) => {
531531
impl $rust_type {
532532
#[inline]
533+
#[allow(clippy::redundant_closure_call)]
533534
pub fn default_value(&self) -> $value_type {
534535
unsafe {
535536
let ptr =

glib/src/value.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1216,13 +1216,15 @@ macro_rules! numeric {
12161216
type Checker = GenericValueTypeChecker<Self>;
12171217

12181218
#[inline]
1219+
#[allow(clippy::redundant_closure_call)]
12191220
unsafe fn from_value(value: &'a Value) -> Self {
12201221
$get(value.to_glib_none().0)
12211222
}
12221223
}
12231224

12241225
impl ToValue for $name {
12251226
#[inline]
1227+
#[allow(clippy::redundant_closure_call)]
12261228
fn to_value(&self) -> Value {
12271229
let mut value = Value::for_value_type::<Self>();
12281230
unsafe {
@@ -1487,7 +1489,7 @@ mod tests {
14871489

14881490
#[test]
14891491
fn test_strv() {
1490-
let v = vec!["123", "456"].to_value();
1492+
let v = ["123", "456"].to_value();
14911493
assert_eq!(
14921494
v.get::<Vec<GString>>(),
14931495
Ok(vec![GString::from("123"), GString::from("456")])

0 commit comments

Comments
 (0)