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

Commit

Permalink
Fix some clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
EPashkin committed Feb 27, 2019
1 parent 9a9dd5c commit eed62bb
Show file tree
Hide file tree
Showing 20 changed files with 68 additions and 76 deletions.
1 change: 1 addition & 0 deletions src/closure.rs
Expand Up @@ -82,6 +82,7 @@ impl Closure {
from_glib_none(closure)
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Expand Up @@ -85,7 +85,7 @@ impl Error {
}

// backcompat shim
#[cfg_attr(feature = "cargo-clippy", allow(not_unsafe_ptr_arg_deref))]
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn wrap(ptr: *mut glib_ffi::GError) -> Error {
unsafe { from_glib_full(ptr) }
}
Expand Down
2 changes: 1 addition & 1 deletion src/file_error.rs
Expand Up @@ -72,7 +72,7 @@ impl ErrorDomain for FileError {
}
}

#[cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity))]
#[allow(clippy::cyclomatic_complexity)]
fn from(code: i32) -> Option<Self> {
use self::FileError::*;
match code {
Expand Down
1 change: 0 additions & 1 deletion src/gobject/mod.rs
Expand Up @@ -4,7 +4,6 @@

//! GObject bindings

#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
pub mod auto;

pub use self::auto::*;
Expand Down
2 changes: 1 addition & 1 deletion src/key_file.rs
Expand Up @@ -48,7 +48,7 @@ impl KeyFile {
pub fn load_from_dirs<T: AsRef<std::path::Path>, U: AsRef<std::path::Path>>(&self, file: T, search_dirs: &[U],
flags: KeyFileFlags) -> Result<path::PathBuf, Error> {
unsafe {
let search_dirs: Vec<&std::path::Path> = search_dirs.iter().map(|p| p.as_ref()).collect();
let search_dirs: Vec<&std::path::Path> = search_dirs.iter().map(AsRef::as_ref).collect();
let mut error = ptr::null_mut();
let mut full_path: *mut libc::c_char = ptr::null_mut();
let _ = ffi::g_key_file_load_from_dirs(self.to_glib_none().0,
Expand Down
9 changes: 5 additions & 4 deletions src/lib.rs
Expand Up @@ -75,7 +75,8 @@
//! conversions between high level Rust types (including the aforementioned
//! wrappers) and their FFI counterparts.

#![cfg_attr(feature = "cargo-clippy", allow(doc_markdown))]
#![allow(clippy::doc_markdown)]
#![allow(clippy::unreadable_literal)]

#[macro_use]
extern crate bitflags;
Expand Down Expand Up @@ -164,9 +165,9 @@ pub mod object;

pub use auto::*;
pub use auto::functions::*;
#[cfg_attr(feature = "cargo-clippy", allow(let_and_return))]
#[cfg_attr(feature = "cargo-clippy", allow(let_unit_value))]
#[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))]
#[allow(clippy::let_and_return)]
#[allow(clippy::let_unit_value)]
#[allow(clippy::too_many_arguments)]
#[allow(non_upper_case_globals)]
mod auto;

Expand Down
4 changes: 1 addition & 3 deletions src/main_context.rs
Expand Up @@ -4,7 +4,6 @@

use ffi;
use translate::*;
use std::mem::transmute;
use std::mem;
use ffi as glib_ffi;
use ffi::{gpointer, gboolean};
Expand Down Expand Up @@ -96,9 +95,8 @@ impl MainContext {
}
}

#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
unsafe extern "C" fn trampoline<F: FnOnce() + 'static>(func: gpointer) -> gboolean {
let func: &mut Option<F> = transmute(func);
let func: &mut Option<F> = &mut *(func as *mut Option<F>);
let func = func.take().expect("MainContext::invoke() closure called multiple times");
func();
glib_ffi::G_SOURCE_REMOVE
Expand Down
6 changes: 2 additions & 4 deletions src/main_context_channel.rs
Expand Up @@ -496,16 +496,14 @@ impl<T> Receiver<T> {
}

let source = Source::from_glib_full(mut_override(&(*source).source));
let id = if let Some(context) = context {
if let Some(context) = context {
assert!(context.is_owner());
source.attach(Some(context))
} else {
let context = MainContext::ref_thread_default();
assert!(context.is_owner());
source.attach(Some(&context))
};

id
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/main_context_futures.rs
Expand Up @@ -28,6 +28,7 @@ const NOT_READY: usize = 1;
const READY: usize = 2;
const DONE: usize = 3;

#[allow(clippy::type_complexity)]
#[repr(C)]
struct TaskSource {
source: glib_ffi::GSource,
Expand Down Expand Up @@ -138,6 +139,7 @@ static SOURCE_FUNCS: glib_ffi::GSourceFuncs = glib_ffi::GSourceFuncs {
};

impl TaskSource {
#[allow(clippy::new_ret_no_self)]
fn new(
priority: Priority,
future: Box<Future<Item = (), Error = Never> + 'static + Send>,
Expand Down Expand Up @@ -275,6 +277,7 @@ impl MainContext {
///
/// This must only be called if no `MainLoop` or anything else is running on this specific main
/// context.
#[allow(clippy::transmute_ptr_to_ptr)]
pub fn block_on<F: Future>(&self, f: F) -> Result<F::Item, F::Error> {
let mut res = None;
let l = MainLoop::new(Some(&*self), false);
Expand Down
30 changes: 14 additions & 16 deletions src/object.rs
Expand Up @@ -343,7 +343,7 @@ pub trait Cast: ObjectType {
// same representation except for the name and the phantom data
// type. IsA<> is an unsafe trait that must only be implemented
// if this is a valid wrapper type
mem::transmute(self)
&*(self as *const Self as *const T)
}
}

Expand Down Expand Up @@ -532,7 +532,7 @@ macro_rules! glib_object_wrapper {
#[doc(hidden)]
impl $crate::translate::FromGlibPtrNone<*mut $ffi_name> for $name {
#[inline]
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
#[allow(clippy::cast_ptr_alignment)]
unsafe fn from_glib_none(ptr: *mut $ffi_name) -> Self {
debug_assert!($crate::types::instance_of::<Self>(ptr as *const _));
$name($crate::translate::from_glib_none(ptr as *mut _), ::std::marker::PhantomData)
Expand All @@ -542,7 +542,7 @@ macro_rules! glib_object_wrapper {
#[doc(hidden)]
impl $crate::translate::FromGlibPtrNone<*const $ffi_name> for $name {
#[inline]
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
#[allow(clippy::cast_ptr_alignment)]
unsafe fn from_glib_none(ptr: *const $ffi_name) -> Self {
debug_assert!($crate::types::instance_of::<Self>(ptr as *const _));
$name($crate::translate::from_glib_none(ptr as *mut _), ::std::marker::PhantomData)
Expand All @@ -552,7 +552,7 @@ macro_rules! glib_object_wrapper {
#[doc(hidden)]
impl $crate::translate::FromGlibPtrFull<*mut $ffi_name> for $name {
#[inline]
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
#[allow(clippy::cast_ptr_alignment)]
unsafe fn from_glib_full(ptr: *mut $ffi_name) -> Self {
debug_assert!($crate::types::instance_of::<Self>(ptr as *const _));
$name($crate::translate::from_glib_full(ptr as *mut _), ::std::marker::PhantomData)
Expand All @@ -562,7 +562,7 @@ macro_rules! glib_object_wrapper {
#[doc(hidden)]
impl $crate::translate::FromGlibPtrBorrow<*mut $ffi_name> for $name {
#[inline]
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
#[allow(clippy::cast_ptr_alignment)]
unsafe fn from_glib_borrow(ptr: *mut $ffi_name) -> Self {
debug_assert!($crate::types::instance_of::<Self>(ptr as *const _));
$name($crate::translate::from_glib_borrow(ptr as *mut _),
Expand All @@ -573,7 +573,7 @@ macro_rules! glib_object_wrapper {
#[doc(hidden)]
impl $crate::translate::FromGlibPtrBorrow<*const $ffi_name> for $name {
#[inline]
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
#[allow(clippy::cast_ptr_alignment)]
unsafe fn from_glib_borrow(ptr: *const $ffi_name) -> Self {
$crate::translate::from_glib_borrow(ptr as *mut $ffi_name)
}
Expand Down Expand Up @@ -704,15 +704,15 @@ macro_rules! glib_object_wrapper {

#[doc(hidden)]
impl $crate::value::SetValue for $name {
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
#[allow(clippy::cast_ptr_alignment)]
unsafe fn set_value(value: &mut $crate::Value, this: &Self) {
$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)
}
}

#[doc(hidden)]
impl $crate::value::SetValueOptional for $name {
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
#[allow(clippy::cast_ptr_alignment)]
unsafe fn set_value_optional(value: &mut $crate::Value, this: Option<&Self>) {
$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)
}
Expand Down Expand Up @@ -1063,11 +1063,9 @@ impl<T: ObjectType> ObjectExt for T {
}

unsafe fn connect_notify_unsafe<F: Fn(&Self, &::ParamSpec)>(&self, name: Option<&str>, f: F) -> SignalHandlerId {
use std::mem::transmute;

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)
where P: ObjectType {
let f: &F = transmute(f);
let f: &F = &*(f as *const F);
f(&Object::from_glib_borrow(this).unsafe_cast(), &from_glib_borrow(param_spec))
}

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

for i in 0..(details.n_params as usize) {
for (i, item) in args.iter().enumerate() {
let arg_type = *(details.param_types.add(i)) & (!gobject_ffi::G_TYPE_FLAG_RESERVED_ID_BIT);
if arg_type != args[i].to_value_type().to_glib() {
if arg_type != item.to_value_type().to_glib() {
return Err(glib_bool_error!("Incompatible argument types"));
}
}
Expand All @@ -1243,7 +1241,7 @@ impl<T: ObjectType> ObjectExt for T {
for (i, arg) in args.iter().enumerate() {
s_args[i+1] = arg.to_value();
}
&s_args[0..args.len()+1]
&s_args[0..=args.len()]
} else {
v_args = Vec::with_capacity(args.len() + 1);
v_args.push(self_v);
Expand Down Expand Up @@ -1437,7 +1435,7 @@ impl<T: ObjectType> ops::Deref for SendWeakRef<T> {
// Deriving this gives the wrong trait bounds
impl<T: ObjectType> Clone for SendWeakRef<T> {
fn clone(&self) -> Self {
SendWeakRef(self.0.clone(), self.1.clone())
SendWeakRef(self.0.clone(), self.1)
}
}

Expand Down Expand Up @@ -1510,7 +1508,7 @@ impl<'a> BindingBuilder<'a> {

pub fn flags(self, flags: ::BindingFlags) -> Self {
Self {
flags: flags,
flags,
..self
}
}
Expand Down
1 change: 1 addition & 0 deletions src/quark.rs
Expand Up @@ -19,6 +19,7 @@ impl Quark {
}
}

#[allow(clippy::trivially_copy_pass_by_ref)]
pub fn to_string(&self) -> &'static str {
unsafe {
CStr::from_ptr(ffi::g_quark_to_string(self.to_glib())).to_str().unwrap()
Expand Down
2 changes: 2 additions & 0 deletions src/send_unique.rs
Expand Up @@ -50,6 +50,7 @@ impl<T: SendUnique> SendUniqueCell<T> {
/// Borrow the contained object or panic if borrowing
/// is not possible at this time
pub fn borrow(&self) -> Ref<T> {
#[allow(clippy::match_wild_err_arm)]
match self.try_borrow() {
Err(_) => panic!("Can't borrow"),
Ok(r) => r,
Expand Down Expand Up @@ -97,6 +98,7 @@ impl<T: SendUnique> SendUniqueCell<T> {
/// Extract the contained object or panic if it is not possible
/// at this time
pub fn into_inner(self) -> T {
#[allow(clippy::match_wild_err_arm)]
match self.try_into_inner() {
Err(_) => panic!("Can't convert into inner type"),
Ok(obj) => obj,
Expand Down
2 changes: 1 addition & 1 deletion src/signal.rs
Expand Up @@ -71,7 +71,7 @@ pub fn signal_handler_unblock<T: ObjectType>(instance: &T, handler_id: &SignalHa
}
}

#[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))]
#[allow(clippy::needless_pass_by_value)]
pub fn signal_handler_disconnect<T: ObjectType>(instance: &T, handler_id: SignalHandlerId) {
unsafe {
gobject_ffi::g_signal_handler_disconnect(instance.as_object_ref().to_glib_none().0, handler_id.to_glib());
Expand Down
13 changes: 5 additions & 8 deletions src/source.rs
Expand Up @@ -98,9 +98,8 @@ impl Drop for CallbackGuard {
}
}

#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
unsafe extern "C" fn trampoline<F: FnMut() -> Continue + 'static>(func: gpointer) -> gboolean {
let func: &RefCell<F> = transmute(func);
let func: &RefCell<F> = &*(func as *const RefCell<F>);
(&mut *func.borrow_mut())().to_glib()
}

Expand All @@ -113,26 +112,24 @@ fn into_raw<F: FnMut() -> Continue + 'static>(func: F) -> gpointer {
Box::into_raw(func) as gpointer
}

#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
unsafe extern "C" fn trampoline_child_watch<F: FnMut(Pid, i32) + 'static>(pid: glib_ffi::GPid, status: i32, func: gpointer) {
let func: &RefCell<F> = transmute(func);
let func: &RefCell<F> = &*(func as *const RefCell<F>);
(&mut *func.borrow_mut())(Pid(pid), status)
}

unsafe extern "C" fn destroy_closure_child_watch<F: FnMut(Pid, i32) + 'static>(ptr: gpointer) {
Box::<RefCell<F>>::from_raw(ptr as *mut _);
}

#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
#[allow(clippy::type_complexity)]
fn into_raw_child_watch<F: FnMut(Pid, i32) + 'static>(func: F) -> gpointer {
let func: Box<RefCell<F>> = Box::new(RefCell::new(func));
Box::into_raw(func) as gpointer
}

#[cfg(any(unix, feature = "dox"))]
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
unsafe extern "C" fn trampoline_unix_fd<F: FnMut(RawFd, IOCondition) -> Continue + 'static>(fd: i32, condition: glib_ffi::GIOCondition, func: gpointer) -> gboolean {
let func: &RefCell<F> = transmute(func);
let func: &RefCell<F> = &*(func as *const RefCell<F>);
(&mut *func.borrow_mut())(fd, from_glib(condition)).to_glib()
}

Expand Down Expand Up @@ -384,7 +381,7 @@ where F: FnMut(RawFd, IOCondition) -> Continue + 'static {
///
/// For historical reasons, the native function always returns true, so we
/// ignore it here.
#[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))]
#[allow(clippy::needless_pass_by_value)]
pub fn source_remove(source_id: SourceId) {
unsafe {
glib_ffi::g_source_remove(source_id.to_glib());
Expand Down
2 changes: 2 additions & 0 deletions src/source_futures.rs
Expand Up @@ -72,6 +72,7 @@ where
let &mut (_, ref mut receiver) = source.as_mut().unwrap();
receiver.poll(ctx)
};
#[allow(clippy::match_wild_err_arm)]
match res {
Err(_) => panic!("Source sender was unexpectedly closed"),
Ok(Async::Ready(v)) => {
Expand Down Expand Up @@ -239,6 +240,7 @@ where
let &mut (_, ref mut receiver) = source.as_mut().unwrap();
receiver.poll_next(ctx)
};
#[allow(clippy::match_wild_err_arm)]
match res {
Err(_) => panic!("Source sender was unexpectedly closed"),
Ok(Async::Ready(v)) => {
Expand Down
2 changes: 1 addition & 1 deletion src/subclass/object.rs
Expand Up @@ -298,7 +298,7 @@ unsafe impl ObjectClassSubclassExt for ObjectClass {}
unsafe impl<T: ObjectSubclass> IsSubclassable<T> for ObjectClass {
fn override_vfuncs(&mut self) {
unsafe {
let klass = &mut *(self as *const Self as *mut gobject_ffi::GObjectClass);
let klass = &mut *(self as *mut Self as *mut gobject_ffi::GObjectClass);
klass.set_property = Some(set_property::<T>);
klass.get_property = Some(get_property::<T>);
klass.constructed = Some(constructed::<T>);
Expand Down
8 changes: 4 additions & 4 deletions src/subclass/types.rs
Expand Up @@ -507,7 +507,7 @@ pub(crate) unsafe fn add_signal(
arg_types: &[Type],
ret_type: Type,
) {
let arg_types = arg_types.iter().map(|t| t.to_glib()).collect::<Vec<_>>();
let arg_types = arg_types.iter().map(ToGlib::to_glib).collect::<Vec<_>>();

gobject_ffi::g_signal_newv(
name.to_glib_none().0,
Expand Down Expand Up @@ -555,7 +555,7 @@ pub(crate) unsafe fn add_signal_with_accumulator<F>(
) where
F: Fn(&SignalInvocationHint, &mut Value, &Value) -> bool + Send + Sync + 'static,
{
let arg_types = arg_types.iter().map(|t| t.to_glib()).collect::<Vec<_>>();
let arg_types = arg_types.iter().map(ToGlib::to_glib).collect::<Vec<_>>();

let accumulator: Box<F> = Box::new(accumulator);

Expand Down Expand Up @@ -610,7 +610,7 @@ pub(crate) unsafe fn add_signal_with_class_handler<F>(
) where
F: Fn(&SignalClassHandlerToken, &[Value]) -> Option<Value> + Send + Sync + 'static,
{
let arg_types = arg_types.iter().map(|t| t.to_glib()).collect::<Vec<_>>();
let arg_types = arg_types.iter().map(ToGlib::to_glib).collect::<Vec<_>>();
let class_handler = Closure::new(move |values| {
let instance = gobject_ffi::g_value_get_object(values[0].to_glib_none().0);
class_handler(&SignalClassHandlerToken(instance as *mut _), values)
Expand Down Expand Up @@ -642,7 +642,7 @@ pub(crate) unsafe fn add_signal_with_class_handler_and_accumulator<F, G>(
F: Fn(&SignalClassHandlerToken, &[Value]) -> Option<Value> + Send + Sync + 'static,
G: Fn(&SignalInvocationHint, &mut Value, &Value) -> bool + Send + Sync + 'static,
{
let arg_types = arg_types.iter().map(|t| t.to_glib()).collect::<Vec<_>>();
let arg_types = arg_types.iter().map(ToGlib::to_glib).collect::<Vec<_>>();

let class_handler = Closure::new(move |values| {
let instance = gobject_ffi::g_value_get_object(values[0].to_glib_none().0);
Expand Down

0 comments on commit eed62bb

Please sign in to comment.