From 8912e1fb0dad64d655b6c59879f46512de4bffbe Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Fri, 6 Sep 2024 13:20:53 +0200 Subject: [PATCH] Disallow `&mut` message receivers --- crates/objc2/CHANGELOG.md | 3 + crates/objc2/src/__macro_helpers/msg_send.rs | 10 --- crates/objc2/src/runtime/message_receiver.rs | 46 +++++----- .../ui/declare_class_invalid_receiver.stderr | 20 ++--- .../declare_class_mut_self_not_mutable.stderr | 89 +++++++++++-------- .../extern_methods_not_allowed_mutable.stderr | 40 +++++---- .../ui/msg_send_id_invalid_receiver.stderr | 4 +- crates/test-ui/ui/msg_send_mutable.rs | 4 +- crates/test-ui/ui/msg_send_mutable.stderr | 4 +- .../ui/msg_send_not_allowed_mutable.rs | 6 +- .../ui/msg_send_not_allowed_mutable.stderr | 52 ++++++----- .../test-ui/ui/msg_send_only_message.stderr | 2 +- 12 files changed, 144 insertions(+), 136 deletions(-) diff --git a/crates/objc2/CHANGELOG.md b/crates/objc2/CHANGELOG.md index 50c4ba852..b0e288141 100644 --- a/crates/objc2/CHANGELOG.md +++ b/crates/objc2/CHANGELOG.md @@ -43,6 +43,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). * **BREAKING**: Removed `ffi` exception function pointer aliases. * **BREAKING**: Removed `mutability::HasStableHash`. * **BREAKING**: Removed `DeclaredClass::ivars_mut`. +* **BREAKING**: Disallow `&mut` message receivers (except in the special case + when the object is `AnyObject`, for better backwards compatibility with + `objc`). ### Fixed * Remove an incorrect assertion when adding protocols to classes in an unexpected diff --git a/crates/objc2/src/__macro_helpers/msg_send.rs b/crates/objc2/src/__macro_helpers/msg_send.rs index a8812997e..550ca66d0 100644 --- a/crates/objc2/src/__macro_helpers/msg_send.rs +++ b/crates/objc2/src/__macro_helpers/msg_send.rs @@ -2,7 +2,6 @@ use core::mem::ManuallyDrop; use core::ptr; use crate::encode::RefEncode; -use crate::mutability::IsMutable; use crate::rc::Retained; use crate::runtime::{AnyClass, AnyObject, MessageReceiver, Sel}; use crate::{ClassType, Encode, Message}; @@ -172,15 +171,6 @@ impl<'a, T: ?Sized + Message> MsgSend for &'a Retained { } } -impl<'a, T: ?Sized + Message + IsMutable> MsgSend for &'a mut Retained { - type Inner = T; - - #[inline] - fn into_raw_receiver(self) -> *mut AnyObject { - Retained::as_mut_ptr(self).cast() - } -} - impl MsgSend for ManuallyDrop> { type Inner = T; diff --git a/crates/objc2/src/runtime/message_receiver.rs b/crates/objc2/src/runtime/message_receiver.rs index 8159b29ce..cf206bf7e 100644 --- a/crates/objc2/src/runtime/message_receiver.rs +++ b/crates/objc2/src/runtime/message_receiver.rs @@ -1,7 +1,6 @@ use core::ptr::NonNull; use crate::encode::{EncodeArguments, EncodeReturn, RefEncode}; -use crate::mutability::IsAllowedMutable; use crate::runtime::{AnyClass, AnyObject, Sel}; use crate::Message; @@ -521,14 +520,18 @@ unsafe impl<'a, T: ?Sized + Message> MessageReceiver for &'a T { } } -impl<'a, T: ?Sized + Message + IsAllowedMutable> private::Sealed for &'a mut T {} -unsafe impl<'a, T: ?Sized + Message + IsAllowedMutable> MessageReceiver for &'a mut T { - type __Inner = T; +impl<'a> private::Sealed for &'a mut AnyObject {} +/// `&mut AnyObject` is allowed as mutable, for easier transition from `objc`, +/// even though it's basically always incorrect to hold `&mut AnyObject`. +/// +/// Use `*mut AnyObject` instead if you know for certain you need mutability, +/// and cannot make do with interior mutability. +unsafe impl<'a> MessageReceiver for &'a mut AnyObject { + type __Inner = AnyObject; #[inline] fn __as_raw_receiver(self) -> *mut AnyObject { - let ptr: *mut T = self; - ptr.cast() + self } } @@ -558,37 +561,30 @@ mod tests { use core::ptr; use super::*; - use crate::mutability; use crate::rc::{Allocated, Retained}; use crate::runtime::NSObject; use crate::test_utils; - use crate::{declare_class, msg_send, msg_send_id, ClassType, DeclaredClass}; - - declare_class!( - struct MutableObject; - - unsafe impl ClassType for MutableObject { - type Super = NSObject; - type Mutability = mutability::Mutable; - const NAME: &'static str = "TestMutableObject"; - } - - impl DeclaredClass for MutableObject {} - ); + use crate::{msg_send, msg_send_id}; #[allow(unused)] - fn test_different_receivers(mut obj: Retained) { + fn test_different_receivers(obj: &mut AnyObject) { unsafe { - let x = &mut obj; + let x = &mut *obj; let _: () = msg_send![x, mutable1]; + // `x` is consumed by the above, so this won't work: // let _: () = msg_send![x, mutable2]; + + // It is only possible if we reborrow: let _: () = msg_send![&mut *obj, mutable1]; let _: () = msg_send![&mut *obj, mutable2]; - #[allow(clippy::needless_borrow)] - let obj: NonNull = (&mut *obj).into(); + + // Test NonNull + let obj = NonNull::from(obj); let _: () = msg_send![obj, mutable1]; let _: () = msg_send![obj, mutable2]; - let obj: *mut MutableObject = obj.as_ptr(); + + // And test raw pointers + let obj: *mut AnyObject = obj.as_ptr(); let _: () = msg_send![obj, mutable1]; let _: () = msg_send![obj, mutable2]; } diff --git a/crates/test-ui/ui/declare_class_invalid_receiver.stderr b/crates/test-ui/ui/declare_class_invalid_receiver.stderr index 173b4a7a9..f3d536cb7 100644 --- a/crates/test-ui/ui/declare_class_invalid_receiver.stderr +++ b/crates/test-ui/ui/declare_class_invalid_receiver.stderr @@ -16,7 +16,7 @@ error[E0277]: the trait bound `Box: MessageReceiver` is not satisf = help: the following other types implement trait `MessageReceiver`: &'a AnyClass &'a T - &'a mut T + &'a mut AnyObject *const AnyClass *const T *mut T @@ -50,7 +50,7 @@ error[E0277]: the trait bound `Retained: MessageReceiver` is not s = help: the following other types implement trait `MessageReceiver`: &'a AnyClass &'a T - &'a mut T + &'a mut AnyObject *const AnyClass *const T *mut T @@ -84,7 +84,7 @@ error[E0277]: the trait bound `CustomObject: MessageReceiver` is not satisfied = help: the following other types implement trait `MessageReceiver`: &'a AnyClass &'a T - &'a mut T + &'a mut AnyObject *const AnyClass *const T *mut T @@ -168,7 +168,7 @@ error[E0277]: the trait bound `Box: MessageReceiver` is not satisf = help: the following other types implement trait `MessageReceiver`: &'a AnyClass &'a T - &'a mut T + &'a mut AnyObject *const AnyClass *const T *mut T @@ -202,7 +202,7 @@ error[E0277]: the trait bound `Retained: MessageReceiver` is not s = help: the following other types implement trait `MessageReceiver`: &'a AnyClass &'a T - &'a mut T + &'a mut AnyObject *const AnyClass *const T *mut T @@ -236,7 +236,7 @@ error[E0277]: the trait bound `CustomObject: MessageReceiver` is not satisfied = help: the following other types implement trait `MessageReceiver`: &'a AnyClass &'a T - &'a mut T + &'a mut AnyObject *const AnyClass *const T *mut T @@ -267,7 +267,7 @@ error[E0277]: the trait bound `Box: MessageReceiver` is not satisf = help: the following other types implement trait `MessageReceiver`: &'a AnyClass &'a T - &'a mut T + &'a mut AnyObject *const AnyClass *const T *mut T @@ -290,7 +290,7 @@ error[E0277]: the trait bound `Retained: MessageReceiver` is not s = help: the following other types implement trait `MessageReceiver`: &'a AnyClass &'a T - &'a mut T + &'a mut AnyObject *const AnyClass *const T *mut T @@ -313,7 +313,7 @@ error[E0277]: the trait bound `CustomObject: MessageReceiver` is not satisfied = help: the following other types implement trait `MessageReceiver`: &'a AnyClass &'a T - &'a mut T + &'a mut AnyObject *const AnyClass *const T *mut T @@ -336,7 +336,7 @@ error[E0277]: the trait bound `Allocated: MessageReceiver` is not = help: the following other types implement trait `MessageReceiver`: &'a AnyClass &'a T - &'a mut T + &'a mut AnyObject *const AnyClass *const T *mut T diff --git a/crates/test-ui/ui/declare_class_mut_self_not_mutable.stderr b/crates/test-ui/ui/declare_class_mut_self_not_mutable.stderr index 182638f6a..330ae51eb 100644 --- a/crates/test-ui/ui/declare_class_mut_self_not_mutable.stderr +++ b/crates/test-ui/ui/declare_class_mut_self_not_mutable.stderr @@ -1,4 +1,4 @@ -error[E0277]: the trait bound `InteriorMutable: mutability::MutabilityIsAllowedMutable` is not satisfied +error[E0277]: the trait bound `&mut CustomObject: MessageReceiver` is not satisfied --> ui/declare_class_mut_self_not_mutable.rs | | / declare_class!( @@ -10,16 +10,19 @@ error[E0277]: the trait bound `InteriorMutable: mutability::MutabilityIsAllowedM | | ); | | ^ | | | - | |_the trait `mutability::MutabilityIsAllowedMutable` is not implemented for `InteriorMutable`, which is required by `&mut CustomObject: MessageReceiver` + | |_the trait `MessageReceiver` is not implemented for `&mut CustomObject`, which is required by `extern "C" fn(&mut CustomObject, objc2::runtime::Sel) -> &mut CustomObject: MethodImplementation` | required by a bound introduced by this call | - = help: the following other types implement trait `mutability::MutabilityIsAllowedMutable`: - ImmutableWithMutableSubclass - Mutable - MutableWithImmutableSuperclass - Root - = note: required for `CustomObject` to implement `IsAllowedMutable` - = note: required for `&mut CustomObject` to implement `MessageReceiver` + = help: the following other types implement trait `MessageReceiver`: + &'a AnyClass + &'a T + &'a mut AnyObject + *const AnyClass + *const T + *mut T + NonNull + = note: `MessageReceiver` is implemented for `&CustomObject`, but not for `&mut CustomObject` + = note: required for `extern "C" fn(&mut CustomObject, objc2::runtime::Sel) -> &mut CustomObject` to implement `MethodImplementation` note: required by a bound in `ClassBuilderHelper::::add_method` --> $WORKSPACE/crates/objc2/src/__macro_helpers/declare_class.rs | @@ -27,10 +30,10 @@ note: required by a bound in `ClassBuilderHelper::::add_method` | ---------- required by a bound in this associated function | where | F: MethodImplementation, - | ^^^^^^^^^^ required by this bound in `ClassBuilderHelper::::add_method` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ClassBuilderHelper::::add_method` = note: this error originates in the macro `$crate::__declare_class_register_out` which comes from the expansion of the macro `declare_class` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `InteriorMutable: mutability::MutabilityIsAllowedMutable` is not satisfied +error[E0277]: the trait bound `&mut CustomObject: MessageReceiver` is not satisfied --> ui/declare_class_mut_self_not_mutable.rs | | / declare_class!( @@ -42,16 +45,19 @@ error[E0277]: the trait bound `InteriorMutable: mutability::MutabilityIsAllowedM | | ); | | ^ | | | - | |_the trait `mutability::MutabilityIsAllowedMutable` is not implemented for `InteriorMutable`, which is required by `&mut CustomObject: MessageReceiver` + | |_the trait `MessageReceiver` is not implemented for `&mut CustomObject`, which is required by `extern "C" fn(&mut CustomObject, objc2::runtime::Sel): MethodImplementation` | required by a bound introduced by this call | - = help: the following other types implement trait `mutability::MutabilityIsAllowedMutable`: - ImmutableWithMutableSubclass - Mutable - MutableWithImmutableSuperclass - Root - = note: required for `CustomObject` to implement `IsAllowedMutable` - = note: required for `&mut CustomObject` to implement `MessageReceiver` + = help: the following other types implement trait `MessageReceiver`: + &'a AnyClass + &'a T + &'a mut AnyObject + *const AnyClass + *const T + *mut T + NonNull + = note: `MessageReceiver` is implemented for `&CustomObject`, but not for `&mut CustomObject` + = note: required for `extern "C" fn(&mut CustomObject, objc2::runtime::Sel)` to implement `MethodImplementation` note: required by a bound in `ClassBuilderHelper::::add_method` --> $WORKSPACE/crates/objc2/src/__macro_helpers/declare_class.rs | @@ -59,10 +65,10 @@ note: required by a bound in `ClassBuilderHelper::::add_method` | ---------- required by a bound in this associated function | where | F: MethodImplementation, - | ^^^^^^^^^^ required by this bound in `ClassBuilderHelper::::add_method` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ClassBuilderHelper::::add_method` = note: this error originates in the macro `$crate::__declare_class_register_out` which comes from the expansion of the macro `declare_class` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `InteriorMutable: mutability::MutabilityIsAllowedMutable` is not satisfied +error[E0277]: the trait bound `&mut CustomObject: MessageReceiver` is not satisfied --> ui/declare_class_mut_self_not_mutable.rs | | / declare_class!( @@ -74,16 +80,19 @@ error[E0277]: the trait bound `InteriorMutable: mutability::MutabilityIsAllowedM | | ); | | ^ | | | - | |_the trait `mutability::MutabilityIsAllowedMutable` is not implemented for `InteriorMutable`, which is required by `&mut CustomObject: MessageReceiver` + | |_the trait `MessageReceiver` is not implemented for `&mut CustomObject`, which is required by `extern "C" fn(&mut CustomObject, objc2::runtime::Sel) -> IdReturnValue: MethodImplementation` | required by a bound introduced by this call | - = help: the following other types implement trait `mutability::MutabilityIsAllowedMutable`: - ImmutableWithMutableSubclass - Mutable - MutableWithImmutableSuperclass - Root - = note: required for `CustomObject` to implement `IsAllowedMutable` - = note: required for `&mut CustomObject` to implement `MessageReceiver` + = help: the following other types implement trait `MessageReceiver`: + &'a AnyClass + &'a T + &'a mut AnyObject + *const AnyClass + *const T + *mut T + NonNull + = note: `MessageReceiver` is implemented for `&CustomObject`, but not for `&mut CustomObject` + = note: required for `extern "C" fn(&mut CustomObject, objc2::runtime::Sel) -> IdReturnValue` to implement `MethodImplementation` note: required by a bound in `ClassBuilderHelper::::add_method` --> $WORKSPACE/crates/objc2/src/__macro_helpers/declare_class.rs | @@ -91,10 +100,10 @@ note: required by a bound in `ClassBuilderHelper::::add_method` | ---------- required by a bound in this associated function | where | F: MethodImplementation, - | ^^^^^^^^^^ required by this bound in `ClassBuilderHelper::::add_method` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ClassBuilderHelper::::add_method` = note: this error originates in the macro `$crate::__declare_class_register_out` which comes from the expansion of the macro `declare_class` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `InteriorMutable: mutability::MutabilityIsAllowedMutable` is not satisfied +error[E0277]: the trait bound `&mut CustomObject: MessageReceiver` is not satisfied --> ui/declare_class_mut_self_not_mutable.rs | | / declare_class!( @@ -104,14 +113,16 @@ error[E0277]: the trait bound `InteriorMutable: mutability::MutabilityIsAllowedM ... | | | } | | ); - | |_^ the trait `mutability::MutabilityIsAllowedMutable` is not implemented for `InteriorMutable`, which is required by `RetainSemantics<5>: MessageRecieveId<&mut CustomObject, Retained>` + | |_^ the trait `MessageReceiver` is not implemented for `&mut CustomObject`, which is required by `RetainSemantics<5>: MessageRecieveId<&mut CustomObject, Retained>` | - = help: the following other types implement trait `mutability::MutabilityIsAllowedMutable`: - ImmutableWithMutableSubclass - Mutable - MutableWithImmutableSuperclass - Root - = note: required for `CustomObject` to implement `IsAllowedMutable` - = note: required for `&mut CustomObject` to implement `MessageReceiver` + = help: the following other types implement trait `MessageReceiver`: + &'a AnyClass + &'a T + &'a mut AnyObject + *const AnyClass + *const T + *mut T + NonNull + = note: `MessageReceiver` is implemented for `&CustomObject`, but not for `&mut CustomObject` = note: required for `RetainSemantics<5>` to implement `MessageRecieveId<&mut CustomObject, Retained>` = note: this error originates in the macro `$crate::__declare_class_method_out_inner` which comes from the expansion of the macro `declare_class` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/test-ui/ui/extern_methods_not_allowed_mutable.stderr b/crates/test-ui/ui/extern_methods_not_allowed_mutable.stderr index 8ce2a8ca7..8bc49b6e9 100644 --- a/crates/test-ui/ui/extern_methods_not_allowed_mutable.stderr +++ b/crates/test-ui/ui/extern_methods_not_allowed_mutable.stderr @@ -1,4 +1,4 @@ -error[E0277]: the trait bound `InteriorMutable: mutability::MutabilityIsAllowedMutable` is not satisfied +error[E0277]: the trait bound `&mut MyObject: MsgSend` is not satisfied --> ui/extern_methods_not_allowed_mutable.rs | | / extern_methods!( @@ -9,20 +9,22 @@ error[E0277]: the trait bound `InteriorMutable: mutability::MutabilityIsAllowedM | | ); | | ^ | | | - | |_the trait `mutability::MutabilityIsAllowedMutable` is not implemented for `InteriorMutable`, which is required by `&mut MyObject: MsgSend` + | |_the trait `MessageReceiver` is not implemented for `&mut MyObject`, which is required by `&mut MyObject: MsgSend` | required by a bound introduced by this call | - = help: the following other types implement trait `mutability::MutabilityIsAllowedMutable`: - ImmutableWithMutableSubclass - Mutable - MutableWithImmutableSuperclass - Root - = note: required for `MyObject` to implement `IsAllowedMutable` - = note: required for `&mut MyObject` to implement `MessageReceiver` + = help: the following other types implement trait `MessageReceiver`: + &'a AnyClass + &'a T + &'a mut AnyObject + *const AnyClass + *const T + *mut T + NonNull + = note: `MessageReceiver` is implemented for `&MyObject`, but not for `&mut MyObject` = note: required for `&mut MyObject` to implement `MsgSend` = note: this error originates in the macro `$crate::__rewrite_self_param_inner` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `InteriorMutable: mutability::MutabilityIsAllowedMutable` is not satisfied +error[E0277]: the trait bound `&mut MyObject: MessageReceiver` is not satisfied --> ui/extern_methods_not_allowed_mutable.rs | | / extern_methods!( @@ -31,15 +33,17 @@ error[E0277]: the trait bound `InteriorMutable: mutability::MutabilityIsAllowedM | | fn test_id(&mut self) -> Retained; | | } | | ); - | |_^ the trait `mutability::MutabilityIsAllowedMutable` is not implemented for `InteriorMutable`, which is required by `RetainSemantics<5>: MsgSendId<_, _>` + | |_^ the trait `MessageReceiver` is not implemented for `&mut MyObject`, which is required by `RetainSemantics<5>: MsgSendId<_, _>` | - = help: the following other types implement trait `mutability::MutabilityIsAllowedMutable`: - ImmutableWithMutableSubclass - Mutable - MutableWithImmutableSuperclass - Root - = note: required for `MyObject` to implement `IsAllowedMutable` - = note: required for `&mut MyObject` to implement `MessageReceiver` + = help: the following other types implement trait `MessageReceiver`: + &'a AnyClass + &'a T + &'a mut AnyObject + *const AnyClass + *const T + *mut T + NonNull + = note: `MessageReceiver` is implemented for `&MyObject`, but not for `&mut MyObject` = note: required for `&mut MyObject` to implement `MsgSend` = note: required for `RetainSemantics<5>` to implement `MsgSendId<&mut MyObject, Option>>` = note: this error originates in the macro `$crate::__msg_send_id_helper` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/test-ui/ui/msg_send_id_invalid_receiver.stderr b/crates/test-ui/ui/msg_send_id_invalid_receiver.stderr index 4884c9a1d..3f7cf7521 100644 --- a/crates/test-ui/ui/msg_send_id_invalid_receiver.stderr +++ b/crates/test-ui/ui/msg_send_id_invalid_receiver.stderr @@ -92,7 +92,7 @@ error[E0277]: the trait bound `Retained: MessageReceiver` is not satis = help: the following other types implement trait `MessageReceiver`: &'a AnyClass &'a T - &'a mut T + &'a mut AnyObject *const AnyClass *const T *mut T @@ -110,7 +110,7 @@ error[E0277]: the trait bound `Retained: MessageReceiver` is not satis = help: the following other types implement trait `MessageReceiver`: &'a AnyClass &'a T - &'a mut T + &'a mut AnyObject *const AnyClass *const T *mut T diff --git a/crates/test-ui/ui/msg_send_mutable.rs b/crates/test-ui/ui/msg_send_mutable.rs index 78659fa17..7cfb0f337 100644 --- a/crates/test-ui/ui/msg_send_mutable.rs +++ b/crates/test-ui/ui/msg_send_mutable.rs @@ -1,12 +1,12 @@ //! Test that `msg_send!` consumes their arguments, including the receiver. //! //! Ideally, it shouldn't be so, but that's how it works currently. -use objc2::runtime::NSObject; +use objc2::runtime::AnyObject; use objc2::{class, msg_send}; fn main() { let cls = class!(NSObject); - let obj: &mut NSObject = unsafe { msg_send![cls, new] }; + let obj: &mut AnyObject = unsafe { msg_send![cls, new] }; let _: () = unsafe { msg_send![obj, selector] }; // Could be solved with a reborrow diff --git a/crates/test-ui/ui/msg_send_mutable.stderr b/crates/test-ui/ui/msg_send_mutable.stderr index d58cd19e2..94137593a 100644 --- a/crates/test-ui/ui/msg_send_mutable.stderr +++ b/crates/test-ui/ui/msg_send_mutable.stderr @@ -1,8 +1,8 @@ error[E0382]: use of moved value: `obj` --> ui/msg_send_mutable.rs | - | let obj: &mut NSObject = unsafe { msg_send![cls, new] }; - | --- move occurs because `obj` has type `&mut NSObject`, which does not implement the `Copy` trait + | let obj: &mut AnyObject = unsafe { msg_send![cls, new] }; + | --- move occurs because `obj` has type `&mut AnyObject`, which does not implement the `Copy` trait | | let _: () = unsafe { msg_send![obj, selector] }; | --- value moved here diff --git a/crates/test-ui/ui/msg_send_not_allowed_mutable.rs b/crates/test-ui/ui/msg_send_not_allowed_mutable.rs index 01795f13b..426b58689 100644 --- a/crates/test-ui/ui/msg_send_not_allowed_mutable.rs +++ b/crates/test-ui/ui/msg_send_not_allowed_mutable.rs @@ -1,12 +1,12 @@ //! Test msg_send! with mutable receivers that are not IsAllowedMutable. use objc2::rc::Retained; +use objc2::runtime::NSObject; use objc2::{msg_send, msg_send_id}; -use objc2_foundation::NSThread; fn main() { - let obj: &mut NSThread; + let obj: &mut NSObject; let _: () = unsafe { msg_send![&mut *obj, test] }; - let _: Retained = unsafe { msg_send_id![obj, test] }; + let _: Retained = unsafe { msg_send_id![obj, test] }; } diff --git a/crates/test-ui/ui/msg_send_not_allowed_mutable.stderr b/crates/test-ui/ui/msg_send_not_allowed_mutable.stderr index da1493239..9429e2e4b 100644 --- a/crates/test-ui/ui/msg_send_not_allowed_mutable.stderr +++ b/crates/test-ui/ui/msg_send_not_allowed_mutable.stderr @@ -1,34 +1,38 @@ -error[E0277]: the trait bound `InteriorMutable: mutability::MutabilityIsAllowedMutable` is not satisfied +error[E0277]: the trait bound `&mut NSObject: MsgSend` is not satisfied --> ui/msg_send_not_allowed_mutable.rs | | let _: () = unsafe { msg_send![&mut *obj, test] }; - | ---------------^^^^------- - | | | - | | the trait `mutability::MutabilityIsAllowedMutable` is not implemented for `InteriorMutable`, which is required by `&mut NSThread: MsgSend` + | ----------^^^^^^^^^------- + | | | + | | the trait `MessageReceiver` is not implemented for `&mut NSObject`, which is required by `&mut NSObject: MsgSend` | required by a bound introduced by this call | - = help: the following other types implement trait `mutability::MutabilityIsAllowedMutable`: - ImmutableWithMutableSubclass - Mutable - MutableWithImmutableSuperclass - Root - = note: required for `NSThread` to implement `IsAllowedMutable` - = note: required for `&mut NSThread` to implement `MessageReceiver` - = note: required for `&mut NSThread` to implement `MsgSend` + = help: the following other types implement trait `MessageReceiver`: + &'a AnyClass + &'a T + &'a mut AnyObject + *const AnyClass + *const T + *mut T + NonNull + = note: `MessageReceiver` is implemented for `&NSObject`, but not for `&mut NSObject` + = note: required for `&mut NSObject` to implement `MsgSend` -error[E0277]: the trait bound `InteriorMutable: mutability::MutabilityIsAllowedMutable` is not satisfied +error[E0277]: the trait bound `&mut NSObject: MessageReceiver` is not satisfied --> ui/msg_send_not_allowed_mutable.rs | - | let _: Retained = unsafe { msg_send_id![obj, test] }; - | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `mutability::MutabilityIsAllowedMutable` is not implemented for `InteriorMutable`, which is required by `RetainSemantics<5>: MsgSendId<_, _>` + | let _: Retained = unsafe { msg_send_id![obj, test] }; + | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `MessageReceiver` is not implemented for `&mut NSObject`, which is required by `RetainSemantics<5>: MsgSendId<_, _>` | - = help: the following other types implement trait `mutability::MutabilityIsAllowedMutable`: - ImmutableWithMutableSubclass - Mutable - MutableWithImmutableSuperclass - Root - = note: required for `NSThread` to implement `IsAllowedMutable` - = note: required for `&mut NSThread` to implement `MessageReceiver` - = note: required for `&mut NSThread` to implement `MsgSend` - = note: required for `RetainSemantics<5>` to implement `MsgSendId<&mut NSThread, Option>>` + = help: the following other types implement trait `MessageReceiver`: + &'a AnyClass + &'a T + &'a mut AnyObject + *const AnyClass + *const T + *mut T + NonNull + = note: `MessageReceiver` is implemented for `&NSObject`, but not for `&mut NSObject` + = note: required for `&mut NSObject` to implement `MsgSend` + = note: required for `RetainSemantics<5>` to implement `MsgSendId<&mut NSObject, Option>>` = note: this error originates in the macro `$crate::__msg_send_id_helper` which comes from the expansion of the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/test-ui/ui/msg_send_only_message.stderr b/crates/test-ui/ui/msg_send_only_message.stderr index 6a1ac1ef5..10c802bf0 100644 --- a/crates/test-ui/ui/msg_send_only_message.stderr +++ b/crates/test-ui/ui/msg_send_only_message.stderr @@ -10,7 +10,7 @@ error[E0277]: the trait bound `{integer}: MsgSend` is not satisfied = help: the following other types implement trait `MessageReceiver`: &'a AnyClass &'a T - &'a mut T + &'a mut AnyObject *const AnyClass *const T *mut T