rust-lang / rust-lang/rust-bindgen

Method returning Class panics when the selector contains a colon ("take:" is not a valid Ident)

Open
#3,484 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

Input C/C++ Header
__attribute__((objc_root_class))
@interface Foo
- (Class)take:(int)t;
@end
Bindgen Invocation
$ bindgen input.h -- -x objective-c
Actual Results

bindgen aborts:

panicked at bindgen/ir/context.rs:903:9:
"take:" is not a valid Ident

CXType_ObjCClass goes through ObjCInterface::from_ty(&location). For a method return type, location is the method cursor, so the invented interface is named take:.

- (Class)cls does not panic (no colon) but still invents struct cls instead of using objc::runtime::Class. - (id)take:(int)t and - (SEL)take:(int)t are fine (ObjCId / ObjCSel). A Class parameter uses the ParmDecl name, so it does not hit this.

This is not #3386 (typedefs named id / SEL / Class).

Expected Results

Do not abort. Map Class to the existing Class / id alias rather than treating the method cursor as an interface declaration.

Environment
bindgen: 0.73.1 (rust-lang/rust-bindgen 77cbc723)
clang/libclang: Homebrew clang 21.1.8
rustc: 1.97.1
target: aarch64-apple-darwin
OS: macOS

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with bindgen/ir/context.rs around the panic at line 903 and trace how CXType_ObjCClass reaches ObjCInterface::from_ty for method return cursors. Reproduce the issue with the provided Objective-C header and bindgen invocation, then verify that Class return types no longer abort or invent an interface named after the selector, and instead use the existing Class/id alias.

Written by the indexing model from the issue text.

Assessment

Tech stack
objective-c, rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.