Skip to content

Commit 3f869ec

Browse files
authored
Merge pull request #447 from madsmtm/fix-docs
Fix generating documentation for structs containing `objc2::rc::Id`
2 parents f37bb84 + b8122c3 commit 3f869ec

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,6 @@ jobs:
144144
key: cargo-${{ github.job }}-${{ matrix.name }}-${{ hashFiles('**/Cargo.lock') }}
145145

146146
- name: cargo doc
147-
# Disable cargo doc checking for now, `NSEnumerator2<'a, T>` is broken
148-
# on current nightly.
149-
if: false
150147
run: cargo doc --no-deps --document-private-items ${{ matrix.args }}
151148

152149
- name: cargo clippy

crates/objc2/src/rc/id.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ impl<T: ?Sized> fmt::Pointer for Id<T> {
663663

664664
mod private {
665665
use crate::runtime::Object;
666+
use crate::ClassType;
666667
use core::panic::{RefUnwindSafe, UnwindSafe};
667668

668669
pub struct UnknownStorage<T: ?Sized>(*const T, Object);
@@ -682,6 +683,8 @@ mod private {
682683

683684
#[doc(hidden)]
684685
pub trait IdSendSyncHelper<T: ?Sized>: mutability::Mutability {
686+
// TODO: Move this to be a hidden type under `Mutability` once GATs
687+
// are in our MSRV.
685688
type EquivalentType: ?Sized;
686689
}
687690

@@ -714,6 +717,19 @@ mod private {
714717
impl<T: ?Sized> IdSendSyncHelper<T> for mutability::MainThreadOnly {
715718
type EquivalentType = ArcLikeStorage<T>;
716719
}
720+
721+
/// Helper struct for avoiding a gnarly ICE in `rustdoc` when generating
722+
/// documentation for `icrate` iterator helpers (in particular, it fails
723+
/// in generating auto trait implementations).
724+
///
725+
/// See related issues:
726+
/// - <https://github.com/rust-lang/rust/issues/91380>
727+
/// - <https://github.com/rust-lang/rust/issues/107715>
728+
pub struct EquivalentType<T: ?Sized + ClassType>(
729+
<T::Mutability as IdSendSyncHelper<T>>::EquivalentType,
730+
)
731+
where
732+
T::Mutability: IdSendSyncHelper<T>;
717733
}
718734

719735
// https://doc.rust-lang.org/nomicon/arc-mutex/arc-base.html#send-and-sync
@@ -732,7 +748,7 @@ mod private {
732748
unsafe impl<T: ?Sized + ClassType + Send> Send for Id<T>
733749
where
734750
T::Mutability: private::IdSendSyncHelper<T>,
735-
<T::Mutability as private::IdSendSyncHelper<T>>::EquivalentType: Send,
751+
private::EquivalentType<T>: Send,
736752
{
737753
}
738754

@@ -749,7 +765,7 @@ where
749765
unsafe impl<T: ?Sized + ClassType + Sync> Sync for Id<T>
750766
where
751767
T::Mutability: private::IdSendSyncHelper<T>,
752-
<T::Mutability as private::IdSendSyncHelper<T>>::EquivalentType: Sync,
768+
private::EquivalentType<T>: Sync,
753769
{
754770
}
755771

crates/test-ui/ui/nsarray_bound_not_send_sync.stderr

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ error[E0277]: `*const NSObject` cannot be shared between threads safely
44
| needs_sync::<NSArray<NSObject>>();
55
| ^^^^^^^^^^^^^^^^^ `*const NSObject` cannot be shared between threads safely
66
|
7-
= help: within `icrate::objc2::rc::id::private::UnknownStorage<NSObject>`, the trait `Sync` is not implemented for `*const NSObject`
7+
= help: within `icrate::objc2::rc::id::private::EquivalentType<NSObject>`, the trait `Sync` is not implemented for `*const NSObject`
88
= note: required because it appears within the type `UnknownStorage<NSObject>`
9+
= note: required because it appears within the type `EquivalentType<NSObject>`
910
= note: required for `Id<NSObject>` to implement `Sync`
1011
= note: required because it appears within the type `PhantomData<Id<NSObject>>`
1112
= note: required because it appears within the type `NSArray<NSObject>`
@@ -40,8 +41,9 @@ error[E0277]: `*const NSObject` cannot be sent between threads safely
4041
| needs_send::<NSArray<NSObject>>();
4142
| ^^^^^^^^^^^^^^^^^ `*const NSObject` cannot be sent between threads safely
4243
|
43-
= help: within `icrate::objc2::rc::id::private::UnknownStorage<NSObject>`, the trait `Send` is not implemented for `*const NSObject`
44+
= help: within `icrate::objc2::rc::id::private::EquivalentType<NSObject>`, the trait `Send` is not implemented for `*const NSObject`
4445
= note: required because it appears within the type `UnknownStorage<NSObject>`
46+
= note: required because it appears within the type `EquivalentType<NSObject>`
4547
= note: required for `Id<NSObject>` to implement `Send`
4648
= note: required because it appears within the type `PhantomData<Id<NSObject>>`
4749
= note: required because it appears within the type `NSArray<NSObject>`
@@ -79,8 +81,9 @@ error[E0277]: `*const NSObject` cannot be shared between threads safely
7981
| needs_sync::<NSMutableArray<NSObject>>();
8082
| ^^^^^^^^^^^^^^^^^^^^^^^^ `*const NSObject` cannot be shared between threads safely
8183
|
82-
= help: within `icrate::objc2::rc::id::private::UnknownStorage<NSObject>`, the trait `Sync` is not implemented for `*const NSObject`
84+
= help: within `icrate::objc2::rc::id::private::EquivalentType<NSObject>`, the trait `Sync` is not implemented for `*const NSObject`
8385
= note: required because it appears within the type `UnknownStorage<NSObject>`
86+
= note: required because it appears within the type `EquivalentType<NSObject>`
8487
= note: required for `Id<NSObject>` to implement `Sync`
8588
= note: required because it appears within the type `PhantomData<Id<NSObject>>`
8689
= note: required because it appears within the type `NSArray<NSObject>`
@@ -117,8 +120,9 @@ error[E0277]: `*const NSObject` cannot be sent between threads safely
117120
| needs_send::<NSMutableArray<NSObject>>();
118121
| ^^^^^^^^^^^^^^^^^^^^^^^^ `*const NSObject` cannot be sent between threads safely
119122
|
120-
= help: within `icrate::objc2::rc::id::private::UnknownStorage<NSObject>`, the trait `Send` is not implemented for `*const NSObject`
123+
= help: within `icrate::objc2::rc::id::private::EquivalentType<NSObject>`, the trait `Send` is not implemented for `*const NSObject`
121124
= note: required because it appears within the type `UnknownStorage<NSObject>`
125+
= note: required because it appears within the type `EquivalentType<NSObject>`
122126
= note: required for `Id<NSObject>` to implement `Send`
123127
= note: required because it appears within the type `PhantomData<Id<NSObject>>`
124128
= note: required because it appears within the type `NSArray<NSObject>`

0 commit comments

Comments
 (0)