diff --git a/crates/header-translator/src/rust_type.rs b/crates/header-translator/src/rust_type.rs index fdfd17aab..738318b90 100644 --- a/crates/header-translator/src/rust_type.rs +++ b/crates/header-translator/src/rust_type.rs @@ -1454,54 +1454,34 @@ impl Ty { } pub(crate) fn method_return(&self) -> impl fmt::Display + '_ { - FormatterFn(move |f| { - if let Self::Primitive(Primitive::Void) = self { - // Don't output anything - return Ok(()); - } - - write!(f, " -> ")?; - - match self { - Self::Pointer { - nullability, - pointee, - .. - } if pointee.is_static_object() => { - if *nullability == Nullability::NonNull { - write!(f, "&'static {}", pointee.behind_pointer()) - } else { - write!(f, "Option<&'static {}>", pointee.behind_pointer()) - } - } - Self::Pointer { - nullability, - lifetime: Lifetime::Unspecified, - pointee, - .. - } if pointee.is_object_like() => { - if *nullability == Nullability::NonNull { - write!(f, "Retained<{}>", pointee.behind_pointer()) - } else { - write!(f, "Option>", pointee.behind_pointer()) - } - } - Self::TypeDef { - id, nullability, .. - } if self.is_object_like() => { - if *nullability == Nullability::NonNull { - write!(f, "Retained<{}>", id.path()) - } else { - write!(f, "Option>", id.path()) - } + FormatterFn(move |f| match self { + Self::Pointer { + nullability, + lifetime: Lifetime::Unspecified, + pointee, + .. + } if pointee.is_object_like() && !pointee.is_static_object() => { + if *nullability == Nullability::NonNull { + write!(f, " -> Retained<{}>", pointee.behind_pointer()) + } else { + write!(f, " -> Option>", pointee.behind_pointer()) } - Self::Primitive(Primitive::C99Bool) => { - warn!("C99's bool as Objective-C method return is ill supported"); - write!(f, "bool") + } + Self::TypeDef { + id, nullability, .. + } if self.is_object_like() && !self.is_static_object() => { + if *nullability == Nullability::NonNull { + write!(f, " -> Retained<{}>", id.path()) + } else { + write!(f, " -> Option>", id.path()) } - Self::Primitive(Primitive::ObjcBool) => write!(f, "bool"), - _ => write!(f, "{}", self.plain()), } + Self::Primitive(Primitive::C99Bool) => { + warn!("C99's bool as Objective-C method return is ill supported"); + write!(f, " -> bool") + } + Self::Primitive(Primitive::ObjcBool) => write!(f, " -> bool"), + _ => write!(f, "{}", self.fn_return()), }) } @@ -1573,7 +1553,20 @@ impl Ty { return Ok(()); } - write!(f, " -> {}", self.plain()) + match self { + Self::Pointer { + nullability, + pointee, + .. + } if pointee.is_static_object() => { + if *nullability == Nullability::NonNull { + write!(f, " -> &'static {}", pointee.behind_pointer()) + } else { + write!(f, " -> Option<&'static {}>", pointee.behind_pointer()) + } + } + _ => write!(f, " -> {}", self.plain()), + } }) } diff --git a/crates/objc2/src/topics/about_generated/CHANGELOG.md b/crates/objc2/src/topics/about_generated/CHANGELOG.md index 28f13da37..abe0ecc5f 100644 --- a/crates/objc2/src/topics/about_generated/CHANGELOG.md +++ b/crates/objc2/src/topics/about_generated/CHANGELOG.md @@ -134,10 +134,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - A bunch of things in `WebKit`. * **BREAKING**: Marked methods on the `NSObjectUIAccessibility` category as `MainThreadOnly`. -* Fixed `AnyClass` and `AnyProtocol` mapping. For example +* **BREAKING**: Fixed `AnyClass` and `AnyProtocol` mapping. For example `NSStringFromProtocol` now takes `&AnyProtocol`, `NSPasteboard::readObjectsForClasses_options` now takes `&NSArray`, and `UITrait` is now exposed more correctly. +* **BREAKING**: Fixed the return type of `NSClassFromString`. ## 0.2.2 - 2024-05-21 diff --git a/generated b/generated index 3799cada3..451dd12ac 160000 --- a/generated +++ b/generated @@ -1 +1 @@ -Subproject commit 3799cada34e580f3e3a7888e6c8742acff7dee67 +Subproject commit 451dd12ac215d33d40f9e7502f8b7791835fbb46