Repository navigation
objc: Don't panic on Objective-C methods returning Class - #3526
Merged
Merged
Conversation
`CXType_ObjCClass` shared a match arm with `CXType_ObjCInterface`, so
the builtin `Class` type was parsed with `ObjCInterface::from_ty` on
whatever cursor the type was seen at. For a method return type that is
the method cursor, so the invented interface was named after the
selector and `rust_ident("take:")` panicked. Without a colon it did not
panic but still generated a bogus `struct cls(pub id)` interface.
Add `TypeKind::ObjCClass`, treated like `ObjCId` everywhere and
generated as `*mut objc::runtime::Class`.
Fixes rust-lang#3484.
emilio
approved these changes
Oct 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3484.
CXType_ObjCClassshared a match arm withCXType_ObjCInterface, so the builtinClasstype went throughObjCInterface::from_tyon whatever cursor it was seen at. For a method return type that is the method cursor, and the invented interface is named after the selector:- (Class)clsdid not panic but generated an unrelatedstruct cls(pub id)interface, and aClassparameter did the same with the parameter name.This adds
TypeKind::ObjCClass, handled likeObjCIdin the analyses and generated as*mut objc::runtime::Class, which matches howSELalready maps toobjc::runtime::Sel.The only existing expectation that changes is
objc_builtin_typedef_cycle: theisafield is now*mut objc::runtime::Classand the spuriousstruct Class(pub id)interface is gone.Tested with a new
objc_class_type.hheader covering the return, no-colon and parameter cases.cargo test -p bindgen-tests: 640 passed, 1 failed (objc_template, which fails identically on the base commit with the libclang on my machine).cargo fmt --checkand the CI clippy invocation are clean.r? @pvdrz