File tree 3 files changed +40
-0
lines changed
3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ fn test_compile_errors() {
26
26
fn tests_rust_1_49 ( t : & trybuild:: TestCases ) {
27
27
t. compile_fail ( "tests/ui/invalid_frompy_derive.rs" ) ;
28
28
t. compile_fail ( "tests/ui/invalid_pymethod_receiver.rs" ) ;
29
+ t. compile_fail ( "tests/ui/pyclass_send.rs" ) ;
29
30
30
31
#[ cfg( Py_LIMITED_API ) ]
31
32
t. compile_fail ( "tests/ui/abi3_nativetype_inheritance.rs" ) ;
Original file line number Diff line number Diff line change
1
+ use pyo3:: prelude:: * ;
2
+ use std:: rc:: Rc ;
3
+
4
+ #[ pyclass]
5
+ struct NotThreadSafe {
6
+ data : Rc < i32 >
7
+ }
8
+
9
+ fn main ( ) {
10
+ let gil = Python :: acquire_gil ( ) ;
11
+ let py = gil. python ( ) ;
12
+
13
+ let obj = PyCell :: new ( py, NotThreadSafe { data : Rc :: new ( 5 ) } ) . unwrap ( ) . to_object ( py) ;
14
+ drop ( gil) ;
15
+
16
+ std:: thread:: spawn ( move || {
17
+ let gil = Python :: acquire_gil ( ) ;
18
+ let py = gil. python ( ) ;
19
+
20
+ // Uh oh, moved Rc to a new thread!
21
+ let c: & PyCell < NotThreadSafe > = obj. as_ref ( py) . downcast ( ) . unwrap ( ) ;
22
+
23
+ assert_eq ! ( * c. borrow( ) . data, 5 ) ;
24
+ } ) . join ( ) . unwrap ( ) ;
25
+ }
Original file line number Diff line number Diff line change
1
+ error[E0277]: `Rc<i32>` cannot be sent between threads safely
2
+ --> $DIR/pyclass_send.rs:4:1
3
+ |
4
+ 4 | #[pyclass]
5
+ | ^^^^^^^^^^ `Rc<i32>` cannot be sent between threads safely
6
+ |
7
+ ::: $WORKSPACE/src/pyclass.rs
8
+ |
9
+ | pub struct ThreadCheckerStub<T: Send>(PhantomData<T>);
10
+ | ---- required by this bound in `ThreadCheckerStub`
11
+ |
12
+ = help: within `NotThreadSafe`, the trait `Send` is not implemented for `Rc<i32>`
13
+ = note: required because it appears within the type `NotThreadSafe`
14
+ = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
You can’t perform that action at this time.
0 commit comments