rust-lang / rust-lang/rust-bindgen

Functions with Block parameters in Objective-C templates don't erase types.

Open
#1,706 2 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

Some of the annoying things in the Foundation Framework have blocks in generics as seen here.

Another odd thing about this is that it may be dependent on clang itself as I've had different results from macOS 10.14 to 10.15.

Input C/C++ Header
// bindgen-flags: --generate-block --objc-extern-crate -- -x objective-c -fblocks
// bindgen-osx-only

@interface FooWithBlock<__covariant ObjectType>
- (void)enumerateObjectsUsingBlock:(void (^)(ObjectType obj, int idx))block;
@end

Bindgen Invocation
$ bindgen input.h --generate-block --objc-extern-crate --block-extern-crate -- -x objective-c -fblocks
Actual Results
/* automatically generated by rust-bindgen */

#[macro_use]
extern crate objc;
#[allow(non_camel_case_types)]
pub type id = *mut objc::runtime::Object;
use block;
pub trait FooWithBlock<ObjectType> {
    unsafe fn enumerateObjectsUsingBlock_(self, block: _bindgen_ty_id_5);
}
impl<ObjectType: 'static> FooWithBlock<ObjectType> for id {
    unsafe fn enumerateObjectsUsingBlock_(self, block: _bindgen_ty_id_5) {
        msg_send!(self, enumerateObjectsUsingBlock: block)
    }
}
pub type _bindgen_ty_id_5 =
    *const ::block::Block<(*mut ObjectType, ::std::os::raw::c_int), ()>;

The issue here being _bindgen_ty_id_5 having ObjectType outside of it.

Expected Results

It's unclear what _bindgen_ty_id_5_ really should be.

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 the supplied input.h and bindgen invocation, then reproduce the generated _bindgen_ty_id_5 that references ObjectType outside its generic scope. Compare the output across the noted macOS and Clang versions; done means the expected block type is defined and the input has a regression test covering the corrected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
objective-c, rust
Domain
compilers, tooling
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.