Skip to content

Commit 70e70e3

Browse files
committed
Add notes about object safety of traits
1 parent 99553cb commit 70e70e3

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

crates/objc2/src/declare/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ pub(crate) mod private {
152152
///
153153
/// This is a sealed trait that is implemented for a lot of `extern "C"`
154154
/// function pointer types.
155-
pub trait MethodImplementation: private::Sealed {
155+
//
156+
// Note: `Sized` is intentionally added to make the trait not object safe.
157+
pub trait MethodImplementation: private::Sealed + Sized {
156158
/// The callee type of the method.
157159
type Callee: RefEncode + ?Sized;
158160
/// The return type of the method.

crates/objc2/src/mutability.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ mod private {
256256
///
257257
/// This is a sealed trait, and should not need to be implemented. Open an
258258
/// issue if you know a use-case where this restrition should be lifted!
259+
//
260+
// Note: `Sized` is intentionally added to make the trait not object safe.
259261
pub trait Mutability: private::Sealed + Sized {}
260262
impl Mutability for Root {}
261263
impl Mutability for Immutable {}

crates/objc2/src/rc/autorelease.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,9 @@ mod tests {
551551
pool
552552
}
553553

554+
#[allow(unused)]
555+
fn assert_object_safe(_: &dyn AutoreleaseSafe) {}
556+
554557
#[cfg_attr(
555558
not(feature = "unstable-autoreleasesafe"),
556559
ignore = "only stably ZST when `unstable-autoreleasesafe` is enabled"

crates/objc2/src/runtime/nscopying.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::mutability::{
2-
Immutable, ImmutableWithMutableSubclass, InteriorMutable, MainThreadOnly, Mutable,
2+
Immutable, ImmutableWithMutableSubclass, InteriorMutable, MainThreadOnly, Mutability, Mutable,
33
MutableWithImmutableSuperclass, Root,
44
};
55
use crate::rc::Id;
@@ -12,7 +12,9 @@ use crate::{msg_send_id, ClassType, ProtocolType};
1212
/// and because the return type of those differ if the class has a mutable or
1313
/// an immutable counterpart (as is the case for `NSString` and
1414
/// `NSMutableString`).
15-
pub trait Copyhelper<T: ?Sized> {
15+
//
16+
// Note: This trait is intentionally not object safe.
17+
pub trait Copyhelper<T: ?Sized>: Mutability {
1618
/// The output type of [`NSCopying`] for the given `T`.
1719
type CopyOutput: ?Sized + ClassType;
1820
/// The output type of [`NSMutableCopying`] for the given `T`.

0 commit comments

Comments
 (0)