Skip to content

Commit

Permalink
Add a regression test to ensure AutoreleasePool is not Send nor Sync
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Jun 13, 2021
1 parent ff261e6 commit 93ca34a
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/rc/autorelease.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,21 @@ pub struct AutoreleasePool {
context: *mut c_void,
}

/// ```rust,compile_fail
/// use objc::rc::AutoreleasePool;
/// fn needs_sync<T: Send>() {}
/// needs_sync::<AutoreleasePool>();
/// ```
/// ```rust,compile_fail
/// use objc::rc::AutoreleasePool;
/// fn needs_send<T: Send>() {}
/// needs_send::<AutoreleasePool>();
/// ```
#[cfg(doctest)]
pub struct AutoreleasePoolNotSendNorSync;

impl AutoreleasePool {
/// Construct a new autoreleasepool.
/// Construct a new autorelease pool.
///
/// Use the [`autoreleasepool`] block for a safe alternative.
///
Expand All @@ -36,7 +49,7 @@ impl AutoreleasePool {
#[doc(alias = "objc_autoreleasePoolPush")]
unsafe fn new() -> Self {
// TODO: Make this function pub when we're more certain of the API
AutoreleasePool {
Self {
context: objc_autoreleasePoolPush(),
}
}
Expand Down

0 comments on commit 93ca34a

Please sign in to comment.