Skip to content

Commit

Permalink
Fix a few pedantic clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Aug 28, 2023
1 parent bdd9d39 commit c357318
Show file tree
Hide file tree
Showing 12 changed files with 687 additions and 687 deletions.
12 changes: 7 additions & 5 deletions crates/objc2/src/declare/ivar_forwarding_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use core::fmt;
use core::future::Future;
use core::hash;
use core::iter::FusedIterator;
use core::ops::{Deref, DerefMut};
use core::ops::Deref;
use core::pin::Pin;
use core::task::{Context, Poll};
use std::error::Error;
Expand Down Expand Up @@ -192,25 +192,27 @@ impl<I: IvarType> FusedIterator for Ivar<I> where <Self as Deref>::Target: Fused

// impl<T: IvarType> borrow::Borrow<<Self as Deref>::Target> for Ivar<T> {
// fn borrow(&self) -> &<Self as Deref>::Target {
// Deref::deref(self)
// self
// }
// }
//
// impl<T: IvarType> borrow::BorrowMut<<Self as Deref>::Target> for Ivar<T> {
// fn borrow_mut(&mut self) -> &mut <Self as Deref>::Target {
// DerefMut::deref_mut(self)
// self
// }
// }

impl<T: IvarType> AsRef<<Self as Deref>::Target> for Ivar<T> {
fn as_ref(&self) -> &<Self as Deref>::Target {
Deref::deref(self)
// Auto-derefs
self
}
}

impl<T: IvarType> AsMut<<Self as Deref>::Target> for Ivar<T> {
fn as_mut(&mut self) -> &mut <Self as Deref>::Target {
DerefMut::deref_mut(self)
// Auto-derefs
self
}
}

Expand Down
24 changes: 12 additions & 12 deletions crates/objc2/src/declare/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ impl ClassBuilder {
self.add_method_inner(
sel,
F::Args::ENCODINGS,
F::Ret::ENCODING_RETURN,
&F::Ret::ENCODING_RETURN,
func.__imp(),
)
}
Expand All @@ -442,7 +442,7 @@ impl ClassBuilder {
&mut self,
sel: Sel,
enc_args: &[Encoding],
enc_ret: Encoding,
enc_ret: &Encoding,
func: Imp,
) {
let sel_args = sel.number_of_arguments();
Expand All @@ -458,14 +458,14 @@ impl ClassBuilder {
#[cfg(debug_assertions)]
if let Some(superclass) = self.superclass() {
if let Some(method) = superclass.instance_method(sel) {
if let Err(err) = crate::verify::verify_method_signature(method, enc_args, &enc_ret)
if let Err(err) = crate::verify::verify_method_signature(method, enc_args, enc_ret)
{
panic!("declared invalid method -[{} {sel}]: {err}", self.name())
}
}
}

let types = method_type_encoding(&enc_ret, enc_args);
let types = method_type_encoding(enc_ret, enc_args);
let success = Bool::from_raw(unsafe {
ffi::class_addMethod(self.as_mut_ptr(), sel.as_ptr(), Some(func), types.as_ptr())
});
Expand Down Expand Up @@ -496,7 +496,7 @@ impl ClassBuilder {
self.add_class_method_inner(
sel,
F::Args::ENCODINGS,
F::Ret::ENCODING_RETURN,
&F::Ret::ENCODING_RETURN,
func.__imp(),
)
}
Expand All @@ -506,7 +506,7 @@ impl ClassBuilder {
&mut self,
sel: Sel,
enc_args: &[Encoding],
enc_ret: Encoding,
enc_ret: &Encoding,
func: Imp,
) {
let sel_args = sel.number_of_arguments();
Expand All @@ -522,14 +522,14 @@ impl ClassBuilder {
#[cfg(debug_assertions)]
if let Some(superclass) = self.superclass() {
if let Some(method) = superclass.class_method(sel) {
if let Err(err) = crate::verify::verify_method_signature(method, enc_args, &enc_ret)
if let Err(err) = crate::verify::verify_method_signature(method, enc_args, enc_ret)
{
panic!("declared invalid method +[{} {sel}]: {err}", self.name())
}
}
}

let types = method_type_encoding(&enc_ret, enc_args);
let types = method_type_encoding(enc_ret, enc_args);
let success = Bool::from_raw(unsafe {
ffi::class_addMethod(
self.metaclass_mut(),
Expand Down Expand Up @@ -681,7 +681,7 @@ impl ProtocolBuilder {
&mut self,
sel: Sel,
enc_args: &[Encoding],
enc_ret: Encoding,
enc_ret: &Encoding,
required: bool,
instance_method: bool,
) {
Expand All @@ -692,7 +692,7 @@ impl ProtocolBuilder {
"selector {sel} accepts {sel_args} arguments, but function accepts {}",
enc_args.len(),
);
let types = method_type_encoding(&enc_ret, enc_args);
let types = method_type_encoding(enc_ret, enc_args);
unsafe {
ffi::protocol_addMethodDescription(
self.as_mut_ptr(),
Expand All @@ -713,7 +713,7 @@ impl ProtocolBuilder {
self.add_method_description_inner(
sel,
Args::ENCODINGS,
Ret::ENCODING_RETURN,
&Ret::ENCODING_RETURN,
required,
true,
)
Expand All @@ -728,7 +728,7 @@ impl ProtocolBuilder {
self.add_method_description_inner(
sel,
Args::ENCODINGS,
Ret::ENCODING_RETURN,
&Ret::ENCODING_RETURN,
required,
false,
)
Expand Down
6 changes: 3 additions & 3 deletions crates/objc2/src/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn msg_send_check(
VerificationError::from(Inner::MethodNotFound)
};

panic_verify(cls, sel, err);
panic_verify(cls, sel, &err);
}

#[cfg(debug_assertions)]
Expand All @@ -79,7 +79,7 @@ fn panic_null(sel: Sel) -> ! {

#[cfg(debug_assertions)]
#[track_caller]
fn panic_verify(cls: &AnyClass, sel: Sel, err: crate::runtime::VerificationError) -> ! {
fn panic_verify(cls: &AnyClass, sel: Sel, err: &crate::runtime::VerificationError) -> ! {
panic!(
"invalid message send to {}[{cls} {sel}]: {err}",
if cls.is_metaclass() { "+" } else { "-" },
Expand Down Expand Up @@ -269,7 +269,7 @@ pub unsafe trait MessageReceiver: private::Sealed + Sized {
panic_null(sel);
}
if let Err(err) = superclass.verify_sel::<A, R>(sel) {
panic_verify(superclass, sel, err);
panic_verify(superclass, sel, &err);
}
}
unsafe {
Expand Down
13 changes: 8 additions & 5 deletions crates/objc2/src/rc/id_forwarding_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use core::cmp::Ordering;
use core::fmt;
use core::future::Future;
use core::hash;
use core::ops::{Deref, DerefMut};
use core::pin::Pin;
use core::task::{Context, Poll};
use std::error::Error;
Expand Down Expand Up @@ -132,25 +131,29 @@ impl<T: fmt::Debug + ?Sized> fmt::Debug for Id<T> {

impl<T: ?Sized> borrow::Borrow<T> for Id<T> {
fn borrow(&self) -> &T {
Deref::deref(self)
// Auto-derefs
self
}
}

impl<T: ?Sized + IsMutable> borrow::BorrowMut<T> for Id<T> {
fn borrow_mut(&mut self) -> &mut T {
DerefMut::deref_mut(self)
// Auto-derefs
self
}
}

impl<T: ?Sized> AsRef<T> for Id<T> {
fn as_ref(&self) -> &T {
Deref::deref(self)
// Auto-derefs
self
}
}

impl<T: ?Sized + IsMutable> AsMut<T> for Id<T> {
fn as_mut(&mut self) -> &mut T {
DerefMut::deref_mut(self)
// Auto-derefs
self
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/objc2/src/rc/test_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl __ThreadTestData {
}

std::thread_local! {
static TEST_DATA: RefCell<__ThreadTestData> = RefCell::new(Default::default());
static TEST_DATA: RefCell<__ThreadTestData> = RefCell::default();
}

declare_class!(
Expand Down
37 changes: 16 additions & 21 deletions crates/objc2/src/runtime/protocol_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,29 +137,24 @@ impl<P: ?Sized + ProtocolType + NSObjectProtocol> hash::Hash for ProtocolObject<

impl<P: ?Sized + ProtocolType + NSObjectProtocol> fmt::Debug for ProtocolObject<P> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let description = self.__description();

match description {
// Attempt to format description string
Some(description) => {
// We use a leaking autorelease pool since often the string
// will be UTF-8, and in that case the pool will be
// irrelevant. Also, it allows us to pass the formatter into
// the pool (since it may contain a pool internally that it
// assumes is current when writing).
autoreleasepool_leaking(|pool| {
// SAFETY: `description` selector is guaranteed to always
// return an instance of `NSString`.
let s = unsafe { nsstring_to_str(&description, pool) };
fmt::Display::fmt(s, f)
})
}
// Attempt to format description string
if let Some(description) = self.__description() {
// We use a leaking autorelease pool since often the string
// will be UTF-8, and in that case the pool will be
// irrelevant. Also, it allows us to pass the formatter into
// the pool (since it may contain a pool internally that it
// assumes is current when writing).
autoreleasepool_leaking(|pool| {
// SAFETY: `description` selector is guaranteed to always
// return an instance of `NSString`.
let s = unsafe { nsstring_to_str(&description, pool) };
fmt::Display::fmt(s, f)
})
} else {
// If description was `NULL`, use `AnyObject`'s `Debug` impl
// instead
None => {
let obj: &AnyObject = &self.inner;
fmt::Debug::fmt(obj, f)
}
let obj: &AnyObject = &self.inner;
fmt::Debug::fmt(obj, f)
}
}
}
Expand Down
Loading

0 comments on commit c357318

Please sign in to comment.