-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
msg_send! still compiles when the return type cannot be inferred (relying on behavior that will change in future versions of Rust) #62
Comments
Any plans for a proper fix? This affects us greatly in metal-rs. |
@kvark I believe the fix should be either in metal-rs: adding |
I didn't even know it would compile if you omit the If the rustc change gets shipped again, it seems like the only way to fix would be to add the type annotations. I'll close this out because I'm not aware of any action |
I have an idea! I don't use MacOS, but I came across this issue when researching the stabilization of the never type Undefined behavior can be non-local, so it's hard to blame one thing specifically, but I would first look to
If R is constrained, The immediate effect will be that It is a breaking change; some users have been omitting |
This is a breaking change, to prevent misuses such as SSheldon#62
I haven't fully understood this issue. I thought this was unavoidable, but after @SimonSapin's comment rust-lang/rust#65355 (comment), it turns out that the un-annotated usage only compiles because of a quirk in objc's macro and the type resolution. For example, the following code will not compile: mem::zeroed(); You get an error stating "type annotations needed". I would expect that a bare msg_send![obj, release]; But as described above, that code is accepted! It infers a if false {
panic!("panic")
} else {
mem::zeroed()
}; For some reason, the compiler sees that one branch is With that understanding, there is in fact something we can do here: change the structure of the code inside the macro so that bare |
Fixes so the compiler can infer msg_send! return types Currently, due to a quirk in Rust's type inference interacting with the structure of the `msg_send!` macro, a `()` return type will be inferred when the compiler cannot otherwise determine the return type. This behavior is expected to change, and in the future could resolve to a `!` return type, which results in undefined behavior. Linting has previously been added for this in rust-lang/rust#39216, but it did not catch these cases due to SSheldon/rust-objc#62. An upcoming version of objc will be fixed to stop hiding these errors, at which point they will become compile errors. This change fixes these errors and allows cocoa to compile with the fixed version of objc.
Fixes so the compiler can infer msg_send! return types (backport to 0.18) This is a backport of #340 onto the 0.18 release. Currently, due to a quirk in Rust's type inference interacting with the structure of the `msg_send!` macro, a `()` return type will be inferred when the compiler cannot otherwise determine the return type. This behavior is expected to change, and in the future could resolve to a `!` return type, which results in undefined behavior. Linting has previously been added for this in rust-lang/rust#39216, but it did not catch these cases due to SSheldon/rust-objc#62. An upcoming version of objc will be fixed to stop hiding these errors, at which point they will become compile errors. This change fixes these errors and allows cocoa to compile with the fixed version of objc.
* Fix so the compiler can infer msg_send! return type Currently, due to a quirk in Rust's type inference interacting with the structure of the msg_send! macro, a () return type will be inferred when the compiler cannot otherwise determine the return type. This behavior is expected to change, and in the future could resolve to a ! return type, which results in undefined behavior. Linting has previously been added for this in rust-lang/rust#39216, but it did not catch these cases due to SSheldon/rust-objc#62. An upcoming version of objc will be fixed to stop hiding these errors, at which point they will become compile errors. This change fixes these errors and allows winit to compile with the fixed version of objc. * Bump cocoa to 0.19.1
Currently, due to a quirk in Rust's type inference interacting with the structure of the msg_send! macro, a () return type will be inferred when the compiler cannot otherwise determine the return type. This behavior is expected to change, and in the future could resolve to a ! return type, which results in undefined behavior. Linting has previously been added for this in rust-lang/rust#39216, but it did not catch these cases due to SSheldon/rust-objc#62. objc has been fixed to stop hiding these errors as of version 0.2.7, and they are now compile errors. This change fixes these errors and allows compiling with the latest version of objc.
…1227) * Fix so the compiler can infer msg_send! return type Currently, due to a quirk in Rust's type inference interacting with the structure of the msg_send! macro, a () return type will be inferred when the compiler cannot otherwise determine the return type. This behavior is expected to change, and in the future could resolve to a ! return type, which results in undefined behavior. Linting has previously been added for this in rust-lang/rust#39216, but it did not catch these cases due to SSheldon/rust-objc#62. An upcoming version of objc will be fixed to stop hiding these errors, at which point they will become compile errors. This change fixes these errors and allows winit to compile with the fixed version of objc. * Bump cocoa to 0.19.1
As described in [rust-objc#62][], the msg_send macro could cause UB in certain situations when built with a version of rustc that includes the ! type. rust-objc#62: SSheldon/rust-objc#62
As described in [rust-objc#62][], the msg_send macro could cause UB in certain situations when built with a version of rustc that includes the ! type. [rust-objc#62]: SSheldon/rust-objc#62
As described in [rust-objc#62][], the msg_send macro could cause UB in certain situations when built with a version of rustc that includes the ! type. [rust-objc#62]: SSheldon/rust-objc#62
As described in [rust-objc#62][], the msg_send macro could cause UB in certain situations when built with a version of rustc that includes the ! type. [rust-objc#62]: SSheldon/rust-objc#62
As described in [rust-objc#62][], the msg_send macro could cause UB in certain situations when built with a version of rustc that includes the ! type. [rust-objc#62]: SSheldon/rust-objc#62
As described in [rust-objc#62][], the msg_send macro could cause UB in certain situations when built with a version of rustc that includes the ! type. [rust-objc#62]: SSheldon/rust-objc#62
As described in [rust-objc#62][], the msg_send macro could cause UB in certain situations when built with a version of rustc that includes the ! type. [rust-objc#62]: SSheldon/rust-objc#62
As described in [rust-objc#62][], the msg_send macro could cause UB in certain situations when built with a version of rustc that includes the ! type. [rust-objc#62]: SSheldon/rust-objc#62
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:
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 ():
The text was updated successfully, but these errors were encountered: