Skip to content

Commit c50897d

Browse files
Make KindOf trait unsafe
1 parent 0f56bd7 commit c50897d

File tree

5 files changed

+30
-31
lines changed

5 files changed

+30
-31
lines changed

src/avfoundation.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl NSCopyingProtocol for AVAsset {
154154
}
155155
impl ValidObjCGeneric for AVAsset {}
156156

157-
impl IsKindOf<NSObject> for AVAsset {}
157+
unsafe impl IsKindOf<NSObject> for AVAsset {}
158158

159159
// AVAsset should be mostly fine to use from multiple threads at the same time.
160160
unsafe impl Send for AVAsset {}
@@ -236,8 +236,8 @@ impl NSCopyingProtocol for AVURLAsset {
236236
}
237237
impl ValidObjCGeneric for AVURLAsset {}
238238

239-
impl IsKindOf<NSObject> for AVURLAsset {}
240-
impl IsKindOf<AVAsset> for AVURLAsset {}
239+
unsafe impl IsKindOf<NSObject> for AVURLAsset {}
240+
unsafe impl IsKindOf<AVAsset> for AVURLAsset {}
241241

242242
// AVAsset should be mostly fine to use from multiple threads at the same time.
243243
unsafe impl Send for AVURLAsset {}
@@ -420,7 +420,7 @@ impl NSCopyingProtocol for AVAssetTrack {
420420
}
421421
impl ValidObjCGeneric for AVAssetTrack {}
422422

423-
impl IsKindOf<NSObject> for AVAssetTrack {}
423+
unsafe impl IsKindOf<NSObject> for AVAssetTrack {}
424424

425425
//-------------------------------------------------------------------
426426
// AVAssetReader
@@ -476,7 +476,7 @@ impl NSObjectInterface for AVAssetReader {}
476476
impl AVAssetReaderInterface for AVAssetReader {}
477477
impl ValidObjCGeneric for AVAssetReader {}
478478

479-
impl IsKindOf<NSObject> for AVAssetReader {}
479+
unsafe impl IsKindOf<NSObject> for AVAssetReader {}
480480

481481
//-------------------------------------------------------------------
482482
// AVAssetReaderTrackOutput
@@ -515,7 +515,7 @@ impl NSObjectInterface for AVAssetReaderTrackOutput {}
515515
impl AVAssetReaderTrackOutputInterface for AVAssetReaderTrackOutput {}
516516
impl ValidObjCGeneric for AVAssetReaderTrackOutput {}
517517

518-
impl IsKindOf<NSObject> for AVAssetReaderTrackOutput {}
518+
unsafe impl IsKindOf<NSObject> for AVAssetReaderTrackOutput {}
519519

520520
//-------------------------------------------------------------------
521521
// AVAssetReaderOutput
@@ -554,7 +554,7 @@ impl NSObjectInterface for AVAssetReaderOutput {}
554554
impl AVAssetReaderOutputInterface for AVAssetReaderOutput {}
555555
impl ValidObjCGeneric for AVAssetReaderOutput {}
556556

557-
impl IsKindOf<NSObject> for AVAssetReaderOutput {}
557+
unsafe impl IsKindOf<NSObject> for AVAssetReaderOutput {}
558558

559559
//-------------------------------------------------------------------
560560
// AVAssetReaderSampleReferenceOutput
@@ -594,8 +594,8 @@ impl AVAssetReaderOutputInterface for AVAssetReaderSampleReferenceOutput {}
594594
impl AVAssetReaderSampleReferenceOutputInterface for AVAssetReaderSampleReferenceOutput {}
595595
impl ValidObjCGeneric for AVAssetReaderSampleReferenceOutput {}
596596

597-
impl IsKindOf<NSObject> for AVAssetReaderSampleReferenceOutput {}
598-
impl IsKindOf<AVAssetReaderOutput> for AVAssetReaderSampleReferenceOutput {}
597+
unsafe impl IsKindOf<NSObject> for AVAssetReaderSampleReferenceOutput {}
598+
unsafe impl IsKindOf<AVAssetReaderOutput> for AVAssetReaderSampleReferenceOutput {}
599599

600600
//-------------------------------------------------------------------
601601
// AVPlayerItem
@@ -684,7 +684,7 @@ impl NSCopyingProtocol for AVPlayerItem {
684684
}
685685
impl ValidObjCGeneric for AVPlayerItem {}
686686

687-
impl IsKindOf<NSObject> for AVPlayerItem {}
687+
unsafe impl IsKindOf<NSObject> for AVPlayerItem {}
688688

689689
//-------------------------------------------------------------------
690690
// AVPlayer
@@ -798,7 +798,7 @@ impl AVAssetReaderOutputInterface for AVPlayer {}
798798
impl AVPlayerInterface for AVPlayer {}
799799
impl ValidObjCGeneric for AVPlayer {}
800800

801-
impl IsKindOf<NSObject> for AVPlayer {}
801+
unsafe impl IsKindOf<NSObject> for AVPlayer {}
802802

803803
//-------------------------------------------------------------------
804804
// AVAudioPlayer
@@ -879,4 +879,4 @@ impl AVAssetReaderOutputInterface for AVAudioPlayer {}
879879
impl AVAudioPlayerInterface for AVAudioPlayer {}
880880
impl ValidObjCGeneric for AVAudioPlayer {}
881881

882-
impl IsKindOf<NSObject> for AVAudioPlayer {}
882+
unsafe impl IsKindOf<NSObject> for AVAudioPlayer {}

src/base/objc.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,9 @@ where
6060
/// That does not include special types like StaticNSString or ImmutableNSString.
6161
pub trait ValidObjCGeneric: ptr::AsRaw + ptr::FromOwned {}
6262

63-
// TODO: IsKindOf should maybe be unsafe
6463
/// Marker trait used for handling of type parameters in NSArray and NSDictionary.
65-
pub trait IsKindOf<T: ValidObjCGeneric>: ptr::AsRaw {}
66-
impl<T: ValidObjCGeneric> IsKindOf<T> for T {}
64+
pub unsafe trait IsKindOf<T: ValidObjCGeneric>: ptr::AsRaw {}
65+
unsafe impl<T: ValidObjCGeneric> IsKindOf<T> for T {}
6766

6867
pub trait NSObjectProtocol
6968
where

src/foundation/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ impl NSCopyingProtocol for NSURL {
315315
type Immutable = Self;
316316
}
317317
impl ValidObjCGeneric for NSURL {}
318-
impl IsKindOf<NSObject> for NSURL {}
318+
unsafe impl IsKindOf<NSObject> for NSURL {}
319319

320320
// A NSSURL is immutable so can be shared between threads.
321321
unsafe impl Send for NSURL {}
@@ -441,7 +441,7 @@ impl NSCopyingProtocol for NSDate {
441441
type Immutable = Self;
442442
}
443443
impl ValidObjCGeneric for NSDate {}
444-
impl IsKindOf<NSObject> for NSDate {}
444+
unsafe impl IsKindOf<NSObject> for NSDate {}
445445

446446
impl std::ops::Sub for &NSDate {
447447
type Output = NSTimeInterval;
@@ -574,7 +574,7 @@ impl NSCopyingProtocol for NSNumber {
574574
type Immutable = Self;
575575
}
576576
impl ValidObjCGeneric for NSNumber {}
577-
impl IsKindOf<NSObject> for NSNumber {}
577+
unsafe impl IsKindOf<NSObject> for NSNumber {}
578578

579579
// A NSNumber is immutable so can be shared between threads.
580580
unsafe impl Send for NSNumber {}
@@ -688,7 +688,7 @@ impl NSCopyingProtocol for NSError {
688688
type Immutable = Self;
689689
}
690690
impl ValidObjCGeneric for NSError {}
691-
impl IsKindOf<NSObject> for NSError {}
691+
unsafe impl IsKindOf<NSObject> for NSError {}
692692

693693
// A NSError is immutable so can be shared between threads.
694694
unsafe impl Send for NSError {}

src/foundation/nsarray.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl<T: ValidObjCGeneric> NSMutableCopyingProtocol for NSArray<T> {
124124

125125
impl<T: ValidObjCGeneric> NSFastEnumerationProtocol<T> for NSArray<T> {}
126126
impl<T: ValidObjCGeneric> ValidObjCGeneric for NSArray<T> {}
127-
impl<T: ValidObjCGeneric> IsKindOf<NSObject> for NSArray<T> {}
127+
unsafe impl<T: ValidObjCGeneric> IsKindOf<NSObject> for NSArray<T> {}
128128

129129
#[cfg(test)]
130130
mod array_tests {
@@ -205,8 +205,8 @@ impl<T: ValidObjCGeneric> NSMutableCopyingProtocol for ImmutableNSArray<T> {
205205
}
206206

207207
impl<T: ValidObjCGeneric> NSFastEnumerationProtocol<T> for ImmutableNSArray<T> {}
208-
impl<T: ValidObjCGeneric> IsKindOf<NSObject> for ImmutableNSArray<T> {}
209-
impl<T: ValidObjCGeneric> IsKindOf<NSArray<T>> for ImmutableNSArray<T> {}
208+
unsafe impl<T: ValidObjCGeneric> IsKindOf<NSObject> for ImmutableNSArray<T> {}
209+
unsafe impl<T: ValidObjCGeneric> IsKindOf<NSArray<T>> for ImmutableNSArray<T> {}
210210

211211
// An ImmutableNSArray is known to be immutable so can be shared between threads.
212212
unsafe impl<T: ValidObjCGeneric> Send for ImmutableNSArray<T> {}
@@ -279,8 +279,8 @@ impl<T: ValidObjCGeneric> NSMutableCopyingProtocol for NSMutableArray<T> {
279279

280280
impl<T: ValidObjCGeneric> NSFastEnumerationProtocol<T> for NSMutableArray<T> {}
281281
impl<T: ValidObjCGeneric> ValidObjCGeneric for NSMutableArray<T> {}
282-
impl<T: ValidObjCGeneric> IsKindOf<NSObject> for NSMutableArray<T> {}
283-
impl<T: ValidObjCGeneric> IsKindOf<NSArray<T>> for NSMutableArray<T> {}
282+
unsafe impl<T: ValidObjCGeneric> IsKindOf<NSObject> for NSMutableArray<T> {}
283+
unsafe impl<T: ValidObjCGeneric> IsKindOf<NSArray<T>> for NSMutableArray<T> {}
284284

285285
#[cfg(test)]
286286
mod mutable_array_tests {

src/foundation/nsstring.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl NSObjectProtocol for NSString {
150150
impl NSObjectInterface for NSString {}
151151
impl NSStringInterface for NSString {}
152152
impl ValidObjCGeneric for NSString {}
153-
impl IsKindOf<NSObject> for NSString {}
153+
unsafe impl IsKindOf<NSObject> for NSString {}
154154

155155
impl<Rhs: NSStringInterface> std::cmp::PartialEq<Rhs> for NSString {
156156
fn eq(&self, other: &Rhs) -> bool {
@@ -227,8 +227,8 @@ impl NSStringInterface for ImmutableNSString {}
227227
impl NSCopyingProtocol for ImmutableNSString {
228228
type Immutable = Self;
229229
}
230-
impl IsKindOf<NSObject> for ImmutableNSString {}
231-
impl IsKindOf<NSString> for ImmutableNSString {}
230+
unsafe impl IsKindOf<NSObject> for ImmutableNSString {}
231+
unsafe impl IsKindOf<NSString> for ImmutableNSString {}
232232

233233
impl<Rhs: NSStringInterface> std::cmp::PartialEq<Rhs> for ImmutableNSString {
234234
fn eq(&self, other: &Rhs) -> bool {
@@ -281,8 +281,8 @@ impl NSStringInterface for StaticNSString {}
281281
impl NSCopyingProtocol for StaticNSString {
282282
type Immutable = ImmutableNSString;
283283
}
284-
impl IsKindOf<NSObject> for StaticNSString {}
285-
impl IsKindOf<NSString> for StaticNSString {}
284+
unsafe impl IsKindOf<NSObject> for StaticNSString {}
285+
unsafe impl IsKindOf<NSString> for StaticNSString {}
286286

287287
impl<Rhs: NSStringInterface> std::cmp::PartialEq<Rhs> for StaticNSString {
288288
fn eq(&self, other: &Rhs) -> bool {
@@ -336,8 +336,8 @@ impl NSObjectInterface for NSMutableString {}
336336
impl NSStringInterface for NSMutableString {}
337337
impl NSMutableStringInterface for NSMutableString {}
338338
impl ValidObjCGeneric for NSMutableString {}
339-
impl IsKindOf<NSObject> for NSMutableString {}
340-
impl IsKindOf<NSString> for NSMutableString {}
339+
unsafe impl IsKindOf<NSObject> for NSMutableString {}
340+
unsafe impl IsKindOf<NSString> for NSMutableString {}
341341

342342
impl<Rhs: NSStringInterface> std::cmp::PartialEq<Rhs> for NSMutableString {
343343
fn eq(&self, other: &Rhs) -> bool {

0 commit comments

Comments
 (0)