Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions crates/objc2/src/__macros/define_class/output_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ macro_rules! __define_class_strip_custom_method_attributes {
$($rest:tt)*
} => {
$($parsed)*
// The signature is dictated by the Objective-C method, so lints that
// suggest changing it cannot be followed.
#[allow(
clippy::unused_self,
clippy::unnecessary_wraps,
clippy::trivially_copy_pass_by_ref,
clippy::missing_const_for_fn
)]
$item

// Munch the rest.
Expand Down
36 changes: 36 additions & 0 deletions crates/objc2/tests/define_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,42 @@ fn test_unreachable() {
let _ = DefineClassUnreachable::class();
}

define_class!(
#[unsafe(super(NSObject))]
struct DefineClassSignatureLints;

// Ensure none of these warn, since the signature is dictated by Objective-C.
#[deny(
clippy::unused_self,
clippy::unnecessary_wraps,
clippy::trivially_copy_pass_by_ref,
clippy::missing_const_for_fn
)]
impl DefineClassSignatureLints {
#[unsafe(method(unusedSelf))]
fn unused_self(&self) -> i32 {
42
}

#[unsafe(method(alwaysSome))]
fn always_some(&self) -> Option<Retained<NSObject>> {
let _ = self;
Some(NSObject::new())
}

#[unsafe(method(byRef:))]
fn by_ref(&self, value: &u8) -> u8 {
let _ = self;
*value
}
}
);

#[test]
fn test_signature_lints() {
let _ = DefineClassSignatureLints::class();
}

#[test]
fn test_pointer_receiver_allowed() {
define_class!(
Expand Down
Loading