-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move some compile_fail doctests to UI tests
- Loading branch information
Showing
21 changed files
with
389 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//! Test that AutoreleasePool is not Send and Sync, because it internally | ||
//! works with thread locals. | ||
|
||
use objc2::rc::AutoreleasePool; | ||
|
||
fn needs_sync<T: ?Sized + Sync>() {} | ||
fn needs_send<T: ?Sized + Send>() {} | ||
|
||
fn main() { | ||
needs_sync::<AutoreleasePool>(); | ||
needs_send::<AutoreleasePool>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
error[E0277]: `*mut c_void` cannot be shared between threads safely | ||
--> ui/autoreleasepool_not_send_sync.rs:10:5 | ||
| | ||
10 | needs_sync::<AutoreleasePool>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*mut c_void` cannot be shared between threads safely | ||
| | ||
= help: within `AutoreleasePool`, the trait `Sync` is not implemented for `*mut c_void` | ||
= note: required because it appears within the type `AutoreleasePool` | ||
note: required by a bound in `needs_sync` | ||
--> ui/autoreleasepool_not_send_sync.rs:6:27 | ||
| | ||
6 | fn needs_sync<T: ?Sized + Sync>() {} | ||
| ^^^^ required by this bound in `needs_sync` | ||
|
||
error[E0277]: `*mut UnsafeCell<c_void>` cannot be shared between threads safely | ||
--> ui/autoreleasepool_not_send_sync.rs:10:5 | ||
| | ||
10 | needs_sync::<AutoreleasePool>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*mut UnsafeCell<c_void>` cannot be shared between threads safely | ||
| | ||
= help: within `AutoreleasePool`, the trait `Sync` is not implemented for `*mut UnsafeCell<c_void>` | ||
= note: required because it appears within the type `PhantomData<*mut UnsafeCell<c_void>>` | ||
= note: required because it appears within the type `AutoreleasePool` | ||
note: required by a bound in `needs_sync` | ||
--> ui/autoreleasepool_not_send_sync.rs:6:27 | ||
| | ||
6 | fn needs_sync<T: ?Sized + Sync>() {} | ||
| ^^^^ required by this bound in `needs_sync` | ||
|
||
error[E0277]: `*mut c_void` cannot be sent between threads safely | ||
--> ui/autoreleasepool_not_send_sync.rs:11:5 | ||
| | ||
11 | needs_send::<AutoreleasePool>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*mut c_void` cannot be sent between threads safely | ||
| | ||
= help: within `AutoreleasePool`, the trait `Send` is not implemented for `*mut c_void` | ||
= note: required because it appears within the type `AutoreleasePool` | ||
note: required by a bound in `needs_send` | ||
--> ui/autoreleasepool_not_send_sync.rs:7:27 | ||
| | ||
7 | fn needs_send<T: ?Sized + Send>() {} | ||
| ^^^^ required by this bound in `needs_send` | ||
|
||
error[E0277]: `*mut UnsafeCell<c_void>` cannot be sent between threads safely | ||
--> ui/autoreleasepool_not_send_sync.rs:11:5 | ||
| | ||
11 | needs_send::<AutoreleasePool>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*mut UnsafeCell<c_void>` cannot be sent between threads safely | ||
| | ||
= help: within `AutoreleasePool`, the trait `Send` is not implemented for `*mut UnsafeCell<c_void>` | ||
= note: required because it appears within the type `PhantomData<*mut UnsafeCell<c_void>>` | ||
= note: required because it appears within the type `AutoreleasePool` | ||
note: required by a bound in `needs_send` | ||
--> ui/autoreleasepool_not_send_sync.rs:7:27 | ||
| | ||
7 | fn needs_send<T: ?Sized + Send>() {} | ||
| ^^^^ required by this bound in `needs_send` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use block2::global_block; | ||
|
||
global_block! { | ||
pub static BLOCK = |_b: Box<i32>| {}; | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0277]: the trait bound `Box<i32>: objc2_encode::encode::Encode` is not satisfied | ||
--> ui/global_block_not_encode.rs:3:1 | ||
| | ||
3 | / global_block! { | ||
4 | | pub static BLOCK = |_b: Box<i32>| {}; | ||
5 | | } | ||
| |_^ the trait `objc2_encode::encode::Encode` is not implemented for `Box<i32>` | ||
| | ||
= note: required because of the requirements on the impl of `objc2_encode::encode::EncodeArguments` for `(Box<i32>,)` | ||
= note: required because of the requirements on the impl of `Sync` for `GlobalBlock<(Box<i32>,)>` | ||
= note: shared static variables must have a type that implements `Sync` | ||
= note: this error originates in the macro `global_block` (in Nightly builds, run with -Z macro-backtrace for more info) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use objc2::rc::Shared; | ||
use objc2::runtime::Object; | ||
use objc2_foundation::NSArray; | ||
|
||
fn needs_sync<T: ?Sized + Sync>() {} | ||
fn needs_send<T: ?Sized + Send>() {} | ||
|
||
fn main() { | ||
needs_sync::<NSArray<Object, Shared>>(); | ||
needs_send::<NSArray<Object, Shared>>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
error[E0277]: `UnsafeCell<()>` cannot be shared between threads safely | ||
--> ui/nsarray_bound_not_send_sync.rs:9:5 | ||
| | ||
9 | needs_sync::<NSArray<Object, Shared>>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `UnsafeCell<()>` cannot be shared between threads safely | ||
| | ||
= help: within `objc2::runtime::Object`, the trait `Sync` is not implemented for `UnsafeCell<()>` | ||
= note: required because it appears within the type `(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)` | ||
= note: required because it appears within the type `PhantomData<(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)>` | ||
= note: required because it appears within the type `objc_object` | ||
= note: required because it appears within the type `objc2::runtime::Object` | ||
= note: required because of the requirements on the impl of `Sync` for `NSArray<objc2::runtime::Object, Shared>` | ||
note: required by a bound in `needs_sync` | ||
--> ui/nsarray_bound_not_send_sync.rs:5:27 | ||
| | ||
5 | fn needs_sync<T: ?Sized + Sync>() {} | ||
| ^^^^ required by this bound in `needs_sync` | ||
|
||
error[E0277]: `*const UnsafeCell<()>` cannot be shared between threads safely | ||
--> ui/nsarray_bound_not_send_sync.rs:9:5 | ||
| | ||
9 | needs_sync::<NSArray<Object, Shared>>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const UnsafeCell<()>` cannot be shared between threads safely | ||
| | ||
= help: within `objc2::runtime::Object`, the trait `Sync` is not implemented for `*const UnsafeCell<()>` | ||
= note: required because it appears within the type `(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)` | ||
= note: required because it appears within the type `PhantomData<(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)>` | ||
= note: required because it appears within the type `objc_object` | ||
= note: required because it appears within the type `objc2::runtime::Object` | ||
= note: required because of the requirements on the impl of `Sync` for `NSArray<objc2::runtime::Object, Shared>` | ||
note: required by a bound in `needs_sync` | ||
--> ui/nsarray_bound_not_send_sync.rs:5:27 | ||
| | ||
5 | fn needs_sync<T: ?Sized + Sync>() {} | ||
| ^^^^ required by this bound in `needs_sync` | ||
|
||
error[E0277]: `*const UnsafeCell<()>` cannot be sent between threads safely | ||
--> ui/nsarray_bound_not_send_sync.rs:9:5 | ||
| | ||
9 | needs_sync::<NSArray<Object, Shared>>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const UnsafeCell<()>` cannot be sent between threads safely | ||
| | ||
= help: within `objc2::runtime::Object`, the trait `Send` is not implemented for `*const UnsafeCell<()>` | ||
= note: required because it appears within the type `(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)` | ||
= note: required because it appears within the type `PhantomData<(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)>` | ||
= note: required because it appears within the type `objc_object` | ||
= note: required because it appears within the type `objc2::runtime::Object` | ||
= note: required because of the requirements on the impl of `Sync` for `NSArray<objc2::runtime::Object, Shared>` | ||
note: required by a bound in `needs_sync` | ||
--> ui/nsarray_bound_not_send_sync.rs:5:27 | ||
| | ||
5 | fn needs_sync<T: ?Sized + Sync>() {} | ||
| ^^^^ required by this bound in `needs_sync` | ||
|
||
error[E0277]: `UnsafeCell<()>` cannot be shared between threads safely | ||
--> ui/nsarray_bound_not_send_sync.rs:10:5 | ||
| | ||
10 | needs_send::<NSArray<Object, Shared>>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `UnsafeCell<()>` cannot be shared between threads safely | ||
| | ||
= help: within `objc2::runtime::Object`, the trait `Sync` is not implemented for `UnsafeCell<()>` | ||
= note: required because it appears within the type `(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)` | ||
= note: required because it appears within the type `PhantomData<(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)>` | ||
= note: required because it appears within the type `objc_object` | ||
= note: required because it appears within the type `objc2::runtime::Object` | ||
= note: required because of the requirements on the impl of `Send` for `NSArray<objc2::runtime::Object, Shared>` | ||
note: required by a bound in `needs_send` | ||
--> ui/nsarray_bound_not_send_sync.rs:6:27 | ||
| | ||
6 | fn needs_send<T: ?Sized + Send>() {} | ||
| ^^^^ required by this bound in `needs_send` | ||
|
||
error[E0277]: `*const UnsafeCell<()>` cannot be shared between threads safely | ||
--> ui/nsarray_bound_not_send_sync.rs:10:5 | ||
| | ||
10 | needs_send::<NSArray<Object, Shared>>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const UnsafeCell<()>` cannot be shared between threads safely | ||
| | ||
= help: within `objc2::runtime::Object`, the trait `Sync` is not implemented for `*const UnsafeCell<()>` | ||
= note: required because it appears within the type `(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)` | ||
= note: required because it appears within the type `PhantomData<(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)>` | ||
= note: required because it appears within the type `objc_object` | ||
= note: required because it appears within the type `objc2::runtime::Object` | ||
= note: required because of the requirements on the impl of `Send` for `NSArray<objc2::runtime::Object, Shared>` | ||
note: required by a bound in `needs_send` | ||
--> ui/nsarray_bound_not_send_sync.rs:6:27 | ||
| | ||
6 | fn needs_send<T: ?Sized + Send>() {} | ||
| ^^^^ required by this bound in `needs_send` | ||
|
||
error[E0277]: `*const UnsafeCell<()>` cannot be sent between threads safely | ||
--> ui/nsarray_bound_not_send_sync.rs:10:5 | ||
| | ||
10 | needs_send::<NSArray<Object, Shared>>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const UnsafeCell<()>` cannot be sent between threads safely | ||
| | ||
= help: within `objc2::runtime::Object`, the trait `Send` is not implemented for `*const UnsafeCell<()>` | ||
= note: required because it appears within the type `(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)` | ||
= note: required because it appears within the type `PhantomData<(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)>` | ||
= note: required because it appears within the type `objc_object` | ||
= note: required because it appears within the type `objc2::runtime::Object` | ||
= note: required because of the requirements on the impl of `Send` for `NSArray<objc2::runtime::Object, Shared>` | ||
note: required by a bound in `needs_send` | ||
--> ui/nsarray_bound_not_send_sync.rs:6:27 | ||
| | ||
6 | fn needs_send<T: ?Sized + Send>() {} | ||
| ^^^^ required by this bound in `needs_send` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//! Test that the lifetime of `NSString::as_str` is bound to the string. | ||
|
||
use objc2::rc::autoreleasepool; | ||
use objc2_foundation::NSString; | ||
|
||
fn main() { | ||
autoreleasepool(|pool| { | ||
let ns_string = NSString::new(); | ||
let s = ns_string.as_str(pool); | ||
drop(ns_string); | ||
println!("{}", s); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
error[E0505]: cannot move out of `ns_string` because it is borrowed | ||
--> ui/nsstring_as_str_use_after_release.rs:10:14 | ||
| | ||
9 | let s = ns_string.as_str(pool); | ||
| ---------------------- borrow of `ns_string` occurs here | ||
10 | drop(ns_string); | ||
| ^^^^^^^^^ move out of `ns_string` occurs here | ||
11 | println!("{}", s); | ||
| - borrow later used here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//! Test that the lifetime of `NSString::as_str` is bound to the pool. | ||
|
||
use objc2::rc::autoreleasepool; | ||
use objc2_foundation::NSString; | ||
|
||
fn main() { | ||
let ns_string = NSString::new(); | ||
let _s = autoreleasepool(|pool| ns_string.as_str(pool)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: lifetime may not live long enough | ||
--> ui/nsstring_as_str_use_outside_pool.rs:8:37 | ||
| | ||
8 | let _s = autoreleasepool(|pool| ns_string.as_str(pool)); | ||
| ----- ^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'2` | ||
| | | | ||
| | return type of closure is &'2 str | ||
| has type `&'1 AutoreleasePool` |
Oops, something went wrong.