Skip to content

msg_send! still compiles when the return type cannot be inferred (relying on behavior that will change in future versions of Rust) #62

Closed
@mrmekon

Description

@mrmekon

This is probably not a bug that needs to be fixed in rust-objc, but a warning to developers since it causes runtime crashes with unclear errors.

Previously, both of these worked, assuming setThing: returned void:

let _ = msg_send![obj, setThing: 1];
msg_send![obj, setThing: 0];

They worked because Rust inferred unknown types as (). As of recent Rust nightly builds, unknown types are inferred as a new '!' type (see: rust-lang/rust#48950).

Unfortunately, Rust will build it and the crashes occur at runtime. Depending on which features you have compiled rust-objc with, you either get a panic at the calling line, a panic in objc_exception, or a segfault.

The error messages are entirely unhelpful unless you build rust-objc with the verify_message feature, which catches it at compile-time.

Fix by forcing the type back to ():

let _: () = msg_send![obj, setThing: 1];

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions