Skip to content

Does not compile if objc has verify_message feature turned on #655

@bryanlarsen

Description

@bryanlarsen

How to reproduce:

create an app that depends on both cocoa-foundation and objc with the "verify_message" feature turned on. cocoa-foundation fails to compile.

Example error (there are dozens very similar):

error[E0277]: the trait bound `*mut *mut Object: Encode` is not satisfied
    --> /Users/blarsen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cocoa-foundation-0.1.2/src/foundation.rs:1588:9
     |
1588 |         msg_send![self, writeToURL:aURL options:mask error:errorPtr]
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |         |
     |         the trait `Encode` is not implemented for `*mut *mut Object`
     |         required by a bound introduced by this call
     |
     = help: the following other types implement trait `Encode`:
               *const Object
               *mut Object
               &'a Object
               &'a mut Object
     = note: required for `(*mut Object, NSDataWritingOptions, *mut *mut Object)` to implement `EncodeArguments`
note: required by a bound in `__send_message`
    --> /Users/blarsen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/objc-0.2.7/src/message/mod.rs:186:49
     |
184  | pub unsafe fn send_message<T, A, R>(obj: *const T, sel: Sel, args: A)
     |               ------------ required by a bound in this function
185  |         -> Result<R, MessageError>
186  |         where T: Message, A: MessageArguments + EncodeArguments,
     |                                                 ^^^^^^^^^^^^^^^ required by this bound in `send_message`
     = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info)

Rationale:

I'm getting a segfault in objc::message::platform::send_unverified in a Tauri application of mine. The interwebs tell me that in this situation I should turn on the "verify_message" flag in objc, which should convert my runtime segfault into a compile time error.

And unfortunately the way rust feature flags work I believe I can't turn it on for some crates and turn it off for cocoa-foundation.

Repro specifics:

x86 Mac, MacOS 12.7.1, Rust 1.73

cargo new foo, replace Cargo.toml with

[package]
name = "foo"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cocoa-foundation = "0.1.2"
objc = {version = "0.2.7", features = [ "verify_message" ]}

and then cargo build.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions