Skip to content

Commit

Permalink
Fix generating documentation for structs containing objc2::rc::Id
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed May 13, 2023
1 parent f37bb84 commit 22e423a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,6 @@ jobs:
key: cargo-${{ github.job }}-${{ matrix.name }}-${{ hashFiles('**/Cargo.lock') }}

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

- name: cargo clippy
Expand Down
20 changes: 18 additions & 2 deletions crates/objc2/src/rc/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ impl<T: ?Sized> fmt::Pointer for Id<T> {

mod private {
use crate::runtime::Object;
use crate::ClassType;
use core::panic::{RefUnwindSafe, UnwindSafe};

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

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

Expand Down Expand Up @@ -714,6 +717,19 @@ mod private {
impl<T: ?Sized> IdSendSyncHelper<T> for mutability::MainThreadOnly {
type EquivalentType = ArcLikeStorage<T>;
}

/// Helper struct for avoiding a gnarly ICE in `rustdoc` when generating
/// documentation for `icrate` iterator helpers (in particular, it fails
/// in generating auto trait implementations).
///
/// See related issues:
/// - https://github.com/rust-lang/rust/issues/91380
/// - https://github.com/rust-lang/rust/issues/107715
pub struct EquivalentType<T: ?Sized + ClassType>(
<T::Mutability as IdSendSyncHelper<T>>::EquivalentType,
)
where
T::Mutability: IdSendSyncHelper<T>;
}

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

Expand All @@ -749,7 +765,7 @@ where
unsafe impl<T: ?Sized + ClassType + Sync> Sync for Id<T>
where
T::Mutability: private::IdSendSyncHelper<T>,
<T::Mutability as private::IdSendSyncHelper<T>>::EquivalentType: Sync,
private::EquivalentType<T>: Sync,
{
}

Expand Down

0 comments on commit 22e423a

Please sign in to comment.