Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Commit c80276b

Browse files
committed
Fix some clippy warnings
1 parent 9a9dd5c commit c80276b

20 files changed

+66
-81
lines changed

src/closure.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ impl Closure {
8282
from_glib_none(closure)
8383
}
8484

85+
#[allow(clippy::redundant_closure)]
8586
pub fn invoke(&self, values: &[&ToValue]) -> Option<Value> {
8687
let mut result = unsafe { Value::uninitialized() };
8788

src/error.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,6 @@ impl Error {
8383
})
8484
}
8585
}
86-
87-
// backcompat shim
88-
#[cfg_attr(feature = "cargo-clippy", allow(not_unsafe_ptr_arg_deref))]
89-
pub fn wrap(ptr: *mut glib_ffi::GError) -> Error {
90-
unsafe { from_glib_full(ptr) }
91-
}
9286
}
9387

9488
impl fmt::Display for Error {

src/file_error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl ErrorDomain for FileError {
7272
}
7373
}
7474

75-
#[cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity))]
75+
#[allow(clippy::cyclomatic_complexity)]
7676
fn from(code: i32) -> Option<Self> {
7777
use self::FileError::*;
7878
match code {

src/gobject/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
//! GObject bindings
66
7-
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
87
pub mod auto;
98

109
pub use self::auto::*;

src/key_file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl KeyFile {
4848
pub fn load_from_dirs<T: AsRef<std::path::Path>, U: AsRef<std::path::Path>>(&self, file: T, search_dirs: &[U],
4949
flags: KeyFileFlags) -> Result<path::PathBuf, Error> {
5050
unsafe {
51-
let search_dirs: Vec<&std::path::Path> = search_dirs.iter().map(|p| p.as_ref()).collect();
51+
let search_dirs: Vec<&std::path::Path> = search_dirs.iter().map(AsRef::as_ref).collect();
5252
let mut error = ptr::null_mut();
5353
let mut full_path: *mut libc::c_char = ptr::null_mut();
5454
let _ = ffi::g_key_file_load_from_dirs(self.to_glib_none().0,

src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@
7575
//! conversions between high level Rust types (including the aforementioned
7676
//! wrappers) and their FFI counterparts.
7777
78-
#![cfg_attr(feature = "cargo-clippy", allow(doc_markdown))]
78+
#![allow(clippy::doc_markdown)]
79+
#![allow(clippy::unreadable_literal)]
7980

8081
#[macro_use]
8182
extern crate bitflags;
@@ -164,9 +165,9 @@ pub mod object;
164165

165166
pub use auto::*;
166167
pub use auto::functions::*;
167-
#[cfg_attr(feature = "cargo-clippy", allow(let_and_return))]
168-
#[cfg_attr(feature = "cargo-clippy", allow(let_unit_value))]
169-
#[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))]
168+
#[allow(clippy::let_and_return)]
169+
#[allow(clippy::let_unit_value)]
170+
#[allow(clippy::too_many_arguments)]
170171
#[allow(non_upper_case_globals)]
171172
mod auto;
172173

src/main_context.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use ffi;
66
use translate::*;
7-
use std::mem::transmute;
87
use std::mem;
98
use ffi as glib_ffi;
109
use ffi::{gpointer, gboolean};
@@ -96,9 +95,8 @@ impl MainContext {
9695
}
9796
}
9897

99-
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
10098
unsafe extern "C" fn trampoline<F: FnOnce() + 'static>(func: gpointer) -> gboolean {
101-
let func: &mut Option<F> = transmute(func);
99+
let func: &mut Option<F> = &mut *(func as *mut Option<F>);
102100
let func = func.take().expect("MainContext::invoke() closure called multiple times");
103101
func();
104102
glib_ffi::G_SOURCE_REMOVE

src/main_context_channel.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,16 +496,14 @@ impl<T> Receiver<T> {
496496
}
497497

498498
let source = Source::from_glib_full(mut_override(&(*source).source));
499-
let id = if let Some(context) = context {
499+
if let Some(context) = context {
500500
assert!(context.is_owner());
501501
source.attach(Some(context))
502502
} else {
503503
let context = MainContext::ref_thread_default();
504504
assert!(context.is_owner());
505505
source.attach(Some(&context))
506-
};
507-
508-
id
506+
}
509507
}
510508
}
511509
}

src/main_context_futures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const NOT_READY: usize = 1;
2828
const READY: usize = 2;
2929
const DONE: usize = 3;
3030

31+
#[allow(clippy::type_complexity)]
3132
#[repr(C)]
3233
struct TaskSource {
3334
source: glib_ffi::GSource,
@@ -138,6 +139,7 @@ static SOURCE_FUNCS: glib_ffi::GSourceFuncs = glib_ffi::GSourceFuncs {
138139
};
139140

140141
impl TaskSource {
142+
#[allow(clippy::new_ret_no_self)]
141143
fn new(
142144
priority: Priority,
143145
future: Box<Future<Item = (), Error = Never> + 'static + Send>,
@@ -275,6 +277,7 @@ impl MainContext {
275277
///
276278
/// This must only be called if no `MainLoop` or anything else is running on this specific main
277279
/// context.
280+
#[allow(clippy::transmute_ptr_to_ptr)]
278281
pub fn block_on<F: Future>(&self, f: F) -> Result<F::Item, F::Error> {
279282
let mut res = None;
280283
let l = MainLoop::new(Some(&*self), false);

src/object.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ pub trait Cast: ObjectType {
343343
// same representation except for the name and the phantom data
344344
// type. IsA<> is an unsafe trait that must only be implemented
345345
// if this is a valid wrapper type
346-
mem::transmute(self)
346+
&*(self as *const Self as *const T)
347347
}
348348
}
349349

@@ -532,7 +532,7 @@ macro_rules! glib_object_wrapper {
532532
#[doc(hidden)]
533533
impl $crate::translate::FromGlibPtrNone<*mut $ffi_name> for $name {
534534
#[inline]
535-
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
535+
#[allow(clippy::cast_ptr_alignment)]
536536
unsafe fn from_glib_none(ptr: *mut $ffi_name) -> Self {
537537
debug_assert!($crate::types::instance_of::<Self>(ptr as *const _));
538538
$name($crate::translate::from_glib_none(ptr as *mut _), ::std::marker::PhantomData)
@@ -542,7 +542,7 @@ macro_rules! glib_object_wrapper {
542542
#[doc(hidden)]
543543
impl $crate::translate::FromGlibPtrNone<*const $ffi_name> for $name {
544544
#[inline]
545-
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
545+
#[allow(clippy::cast_ptr_alignment)]
546546
unsafe fn from_glib_none(ptr: *const $ffi_name) -> Self {
547547
debug_assert!($crate::types::instance_of::<Self>(ptr as *const _));
548548
$name($crate::translate::from_glib_none(ptr as *mut _), ::std::marker::PhantomData)
@@ -552,7 +552,7 @@ macro_rules! glib_object_wrapper {
552552
#[doc(hidden)]
553553
impl $crate::translate::FromGlibPtrFull<*mut $ffi_name> for $name {
554554
#[inline]
555-
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
555+
#[allow(clippy::cast_ptr_alignment)]
556556
unsafe fn from_glib_full(ptr: *mut $ffi_name) -> Self {
557557
debug_assert!($crate::types::instance_of::<Self>(ptr as *const _));
558558
$name($crate::translate::from_glib_full(ptr as *mut _), ::std::marker::PhantomData)
@@ -562,7 +562,7 @@ macro_rules! glib_object_wrapper {
562562
#[doc(hidden)]
563563
impl $crate::translate::FromGlibPtrBorrow<*mut $ffi_name> for $name {
564564
#[inline]
565-
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
565+
#[allow(clippy::cast_ptr_alignment)]
566566
unsafe fn from_glib_borrow(ptr: *mut $ffi_name) -> Self {
567567
debug_assert!($crate::types::instance_of::<Self>(ptr as *const _));
568568
$name($crate::translate::from_glib_borrow(ptr as *mut _),
@@ -573,7 +573,7 @@ macro_rules! glib_object_wrapper {
573573
#[doc(hidden)]
574574
impl $crate::translate::FromGlibPtrBorrow<*const $ffi_name> for $name {
575575
#[inline]
576-
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
576+
#[allow(clippy::cast_ptr_alignment)]
577577
unsafe fn from_glib_borrow(ptr: *const $ffi_name) -> Self {
578578
$crate::translate::from_glib_borrow(ptr as *mut $ffi_name)
579579
}
@@ -704,15 +704,15 @@ macro_rules! glib_object_wrapper {
704704

705705
#[doc(hidden)]
706706
impl $crate::value::SetValue for $name {
707-
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
707+
#[allow(clippy::cast_ptr_alignment)]
708708
unsafe fn set_value(value: &mut $crate::Value, this: &Self) {
709709
$crate::gobject_ffi::g_value_set_object($crate::translate::ToGlibPtrMut::to_glib_none_mut(value).0, $crate::translate::ToGlibPtr::<*mut $ffi_name>::to_glib_none(this).0 as *mut $crate::gobject_ffi::GObject)
710710
}
711711
}
712712

713713
#[doc(hidden)]
714714
impl $crate::value::SetValueOptional for $name {
715-
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
715+
#[allow(clippy::cast_ptr_alignment)]
716716
unsafe fn set_value_optional(value: &mut $crate::Value, this: Option<&Self>) {
717717
$crate::gobject_ffi::g_value_set_object($crate::translate::ToGlibPtrMut::to_glib_none_mut(value).0, $crate::translate::ToGlibPtr::<*mut $ffi_name>::to_glib_none(&this).0 as *mut $crate::gobject_ffi::GObject)
718718
}
@@ -1063,11 +1063,9 @@ impl<T: ObjectType> ObjectExt for T {
10631063
}
10641064

10651065
unsafe fn connect_notify_unsafe<F: Fn(&Self, &::ParamSpec)>(&self, name: Option<&str>, f: F) -> SignalHandlerId {
1066-
use std::mem::transmute;
1067-
10681066
unsafe extern "C" fn notify_trampoline<P, F: Fn(&P, &::ParamSpec)>(this: *mut gobject_ffi::GObject, param_spec: *mut gobject_ffi::GParamSpec, f: glib_ffi::gpointer)
10691067
where P: ObjectType {
1070-
let f: &F = transmute(f);
1068+
let f: &F = &*(f as *const F);
10711069
f(&Object::from_glib_borrow(this).unsafe_cast(), &from_glib_borrow(param_spec))
10721070
}
10731071

@@ -1223,9 +1221,9 @@ impl<T: ObjectType> ObjectExt for T {
12231221
return Err(glib_bool_error!("Incompatible number of arguments"));
12241222
}
12251223

1226-
for i in 0..(details.n_params as usize) {
1224+
for (i, item) in args.iter().enumerate() {
12271225
let arg_type = *(details.param_types.add(i)) & (!gobject_ffi::G_TYPE_FLAG_RESERVED_ID_BIT);
1228-
if arg_type != args[i].to_value_type().to_glib() {
1226+
if arg_type != item.to_value_type().to_glib() {
12291227
return Err(glib_bool_error!("Incompatible argument types"));
12301228
}
12311229
}
@@ -1243,7 +1241,7 @@ impl<T: ObjectType> ObjectExt for T {
12431241
for (i, arg) in args.iter().enumerate() {
12441242
s_args[i+1] = arg.to_value();
12451243
}
1246-
&s_args[0..args.len()+1]
1244+
&s_args[0..=args.len()]
12471245
} else {
12481246
v_args = Vec::with_capacity(args.len() + 1);
12491247
v_args.push(self_v);
@@ -1437,7 +1435,7 @@ impl<T: ObjectType> ops::Deref for SendWeakRef<T> {
14371435
// Deriving this gives the wrong trait bounds
14381436
impl<T: ObjectType> Clone for SendWeakRef<T> {
14391437
fn clone(&self) -> Self {
1440-
SendWeakRef(self.0.clone(), self.1.clone())
1438+
SendWeakRef(self.0.clone(), self.1)
14411439
}
14421440
}
14431441

@@ -1510,7 +1508,7 @@ impl<'a> BindingBuilder<'a> {
15101508

15111509
pub fn flags(self, flags: ::BindingFlags) -> Self {
15121510
Self {
1513-
flags: flags,
1511+
flags,
15141512
..self
15151513
}
15161514
}

0 commit comments

Comments
 (0)