Skip to content

Commit ab38d3f

Browse files
committed
Fix a few pedantic clippy warnings
1 parent cdd2d46 commit ab38d3f

File tree

6 files changed

+47
-47
lines changed

6 files changed

+47
-47
lines changed

crates/objc2/src/declare/ivar_forwarding_impls.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use core::fmt;
1414
use core::future::Future;
1515
use core::hash;
1616
use core::iter::FusedIterator;
17-
use core::ops::{Deref, DerefMut};
17+
use core::ops::Deref;
1818
use core::pin::Pin;
1919
use core::task::{Context, Poll};
2020
use std::error::Error;
@@ -192,25 +192,27 @@ impl<I: IvarType> FusedIterator for Ivar<I> where <Self as Deref>::Target: Fused
192192

193193
// impl<T: IvarType> borrow::Borrow<<Self as Deref>::Target> for Ivar<T> {
194194
// fn borrow(&self) -> &<Self as Deref>::Target {
195-
// Deref::deref(self)
195+
// self
196196
// }
197197
// }
198198
//
199199
// impl<T: IvarType> borrow::BorrowMut<<Self as Deref>::Target> for Ivar<T> {
200200
// fn borrow_mut(&mut self) -> &mut <Self as Deref>::Target {
201-
// DerefMut::deref_mut(self)
201+
// self
202202
// }
203203
// }
204204

205205
impl<T: IvarType> AsRef<<Self as Deref>::Target> for Ivar<T> {
206206
fn as_ref(&self) -> &<Self as Deref>::Target {
207-
Deref::deref(self)
207+
// Auto-derefs
208+
self
208209
}
209210
}
210211

211212
impl<T: IvarType> AsMut<<Self as Deref>::Target> for Ivar<T> {
212213
fn as_mut(&mut self) -> &mut <Self as Deref>::Target {
213-
DerefMut::deref_mut(self)
214+
// Auto-derefs
215+
self
214216
}
215217
}
216218

crates/objc2/src/declare/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ impl ClassBuilder {
432432
self.add_method_inner(
433433
sel,
434434
F::Args::ENCODINGS,
435-
F::Ret::ENCODING_RETURN,
435+
&F::Ret::ENCODING_RETURN,
436436
func.__imp(),
437437
)
438438
}
@@ -442,7 +442,7 @@ impl ClassBuilder {
442442
&mut self,
443443
sel: Sel,
444444
enc_args: &[Encoding],
445-
enc_ret: Encoding,
445+
enc_ret: &Encoding,
446446
func: Imp,
447447
) {
448448
let sel_args = sel.number_of_arguments();
@@ -458,14 +458,14 @@ impl ClassBuilder {
458458
#[cfg(debug_assertions)]
459459
if let Some(superclass) = self.superclass() {
460460
if let Some(method) = superclass.instance_method(sel) {
461-
if let Err(err) = crate::verify::verify_method_signature(method, enc_args, &enc_ret)
461+
if let Err(err) = crate::verify::verify_method_signature(method, enc_args, enc_ret)
462462
{
463463
panic!("declared invalid method -[{} {sel}]: {err}", self.name())
464464
}
465465
}
466466
}
467467

468-
let types = method_type_encoding(&enc_ret, enc_args);
468+
let types = method_type_encoding(enc_ret, enc_args);
469469
let success = Bool::from_raw(unsafe {
470470
ffi::class_addMethod(self.as_mut_ptr(), sel.as_ptr(), Some(func), types.as_ptr())
471471
});
@@ -496,7 +496,7 @@ impl ClassBuilder {
496496
self.add_class_method_inner(
497497
sel,
498498
F::Args::ENCODINGS,
499-
F::Ret::ENCODING_RETURN,
499+
&F::Ret::ENCODING_RETURN,
500500
func.__imp(),
501501
)
502502
}
@@ -506,7 +506,7 @@ impl ClassBuilder {
506506
&mut self,
507507
sel: Sel,
508508
enc_args: &[Encoding],
509-
enc_ret: Encoding,
509+
enc_ret: &Encoding,
510510
func: Imp,
511511
) {
512512
let sel_args = sel.number_of_arguments();
@@ -522,14 +522,14 @@ impl ClassBuilder {
522522
#[cfg(debug_assertions)]
523523
if let Some(superclass) = self.superclass() {
524524
if let Some(method) = superclass.class_method(sel) {
525-
if let Err(err) = crate::verify::verify_method_signature(method, enc_args, &enc_ret)
525+
if let Err(err) = crate::verify::verify_method_signature(method, enc_args, enc_ret)
526526
{
527527
panic!("declared invalid method +[{} {sel}]: {err}", self.name())
528528
}
529529
}
530530
}
531531

532-
let types = method_type_encoding(&enc_ret, enc_args);
532+
let types = method_type_encoding(enc_ret, enc_args);
533533
let success = Bool::from_raw(unsafe {
534534
ffi::class_addMethod(
535535
self.metaclass_mut(),
@@ -681,7 +681,7 @@ impl ProtocolBuilder {
681681
&mut self,
682682
sel: Sel,
683683
enc_args: &[Encoding],
684-
enc_ret: Encoding,
684+
enc_ret: &Encoding,
685685
required: bool,
686686
instance_method: bool,
687687
) {
@@ -692,7 +692,7 @@ impl ProtocolBuilder {
692692
"selector {sel} accepts {sel_args} arguments, but function accepts {}",
693693
enc_args.len(),
694694
);
695-
let types = method_type_encoding(&enc_ret, enc_args);
695+
let types = method_type_encoding(enc_ret, enc_args);
696696
unsafe {
697697
ffi::protocol_addMethodDescription(
698698
self.as_mut_ptr(),
@@ -713,7 +713,7 @@ impl ProtocolBuilder {
713713
self.add_method_description_inner(
714714
sel,
715715
Args::ENCODINGS,
716-
Ret::ENCODING_RETURN,
716+
&Ret::ENCODING_RETURN,
717717
required,
718718
true,
719719
)
@@ -728,7 +728,7 @@ impl ProtocolBuilder {
728728
self.add_method_description_inner(
729729
sel,
730730
Args::ENCODINGS,
731-
Ret::ENCODING_RETURN,
731+
&Ret::ENCODING_RETURN,
732732
required,
733733
false,
734734
)

crates/objc2/src/message/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn msg_send_check(
6868
VerificationError::from(Inner::MethodNotFound)
6969
};
7070

71-
panic_verify(cls, sel, err);
71+
panic_verify(cls, sel, &err);
7272
}
7373

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

8080
#[cfg(debug_assertions)]
8181
#[track_caller]
82-
fn panic_verify(cls: &AnyClass, sel: Sel, err: crate::runtime::VerificationError) -> ! {
82+
fn panic_verify(cls: &AnyClass, sel: Sel, err: &crate::runtime::VerificationError) -> ! {
8383
panic!(
8484
"invalid message send to {}[{cls} {sel}]: {err}",
8585
if cls.is_metaclass() { "+" } else { "-" },
@@ -269,7 +269,7 @@ pub unsafe trait MessageReceiver: private::Sealed + Sized {
269269
panic_null(sel);
270270
}
271271
if let Err(err) = superclass.verify_sel::<A, R>(sel) {
272-
panic_verify(superclass, sel, err);
272+
panic_verify(superclass, sel, &err);
273273
}
274274
}
275275
unsafe {

crates/objc2/src/rc/id_forwarding_impls.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use core::cmp::Ordering;
1313
use core::fmt;
1414
use core::future::Future;
1515
use core::hash;
16-
use core::ops::{Deref, DerefMut};
1716
use core::pin::Pin;
1817
use core::task::{Context, Poll};
1918
use std::error::Error;
@@ -132,25 +131,29 @@ impl<T: fmt::Debug + ?Sized> fmt::Debug for Id<T> {
132131

133132
impl<T: ?Sized> borrow::Borrow<T> for Id<T> {
134133
fn borrow(&self) -> &T {
135-
Deref::deref(self)
134+
// Auto-derefs
135+
self
136136
}
137137
}
138138

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

145146
impl<T: ?Sized> AsRef<T> for Id<T> {
146147
fn as_ref(&self) -> &T {
147-
Deref::deref(self)
148+
// Auto-derefs
149+
self
148150
}
149151
}
150152

151153
impl<T: ?Sized + IsMutable> AsMut<T> for Id<T> {
152154
fn as_mut(&mut self) -> &mut T {
153-
DerefMut::deref_mut(self)
155+
// Auto-derefs
156+
self
154157
}
155158
}
156159

crates/objc2/src/rc/test_object.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl __ThreadTestData {
5454
}
5555

5656
std::thread_local! {
57-
static TEST_DATA: RefCell<__ThreadTestData> = RefCell::new(Default::default());
57+
static TEST_DATA: RefCell<__ThreadTestData> = RefCell::default();
5858
}
5959

6060
declare_class!(

crates/objc2/src/runtime/protocol_object.rs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -137,29 +137,24 @@ impl<P: ?Sized + ProtocolType + NSObjectProtocol> hash::Hash for ProtocolObject<
137137

138138
impl<P: ?Sized + ProtocolType + NSObjectProtocol> fmt::Debug for ProtocolObject<P> {
139139
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
140-
let description = self.__description();
141-
142-
match description {
143-
// Attempt to format description string
144-
Some(description) => {
145-
// We use a leaking autorelease pool since often the string
146-
// will be UTF-8, and in that case the pool will be
147-
// irrelevant. Also, it allows us to pass the formatter into
148-
// the pool (since it may contain a pool internally that it
149-
// assumes is current when writing).
150-
autoreleasepool_leaking(|pool| {
151-
// SAFETY: `description` selector is guaranteed to always
152-
// return an instance of `NSString`.
153-
let s = unsafe { nsstring_to_str(&description, pool) };
154-
fmt::Display::fmt(s, f)
155-
})
156-
}
140+
// Attempt to format description string
141+
if let Some(description) = self.__description() {
142+
// We use a leaking autorelease pool since often the string
143+
// will be UTF-8, and in that case the pool will be
144+
// irrelevant. Also, it allows us to pass the formatter into
145+
// the pool (since it may contain a pool internally that it
146+
// assumes is current when writing).
147+
autoreleasepool_leaking(|pool| {
148+
// SAFETY: `description` selector is guaranteed to always
149+
// return an instance of `NSString`.
150+
let s = unsafe { nsstring_to_str(&description, pool) };
151+
fmt::Display::fmt(s, f)
152+
})
153+
} else {
157154
// If description was `NULL`, use `AnyObject`'s `Debug` impl
158155
// instead
159-
None => {
160-
let obj: &AnyObject = &self.inner;
161-
fmt::Debug::fmt(obj, f)
162-
}
156+
let obj: &AnyObject = &self.inner;
157+
fmt::Debug::fmt(obj, f)
163158
}
164159
}
165160
}

0 commit comments

Comments
 (0)