File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed
Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ fn test_compile_errors() {
66 t. compile_fail ( "tests/ui/invalid_pyclass_args.rs" ) ;
77 t. compile_fail ( "tests/ui/invalid_pymethod_names.rs" ) ;
88 t. compile_fail ( "tests/ui/missing_clone.rs" ) ;
9+ t. compile_fail ( "tests/ui/pyclass_send.rs" ) ;
910 t. compile_fail ( "tests/ui/reject_generics.rs" ) ;
1011 t. compile_fail ( "tests/ui/wrong_aspyref_lifetimes.rs" ) ;
1112 // Since the current minimum nightly(2020-01-20) has a different error message,
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]: `std::rc::Rc<i32>` cannot be sent between threads safely
2+ --> $DIR/pyclass_send.rs:4:1
3+ |
4+ 4 | #[pyclass]
5+ | ^^^^^^^^^^ `std::rc::Rc<i32>` cannot be sent between threads safely
6+ |
7+ ::: $WORKSPACE/src/pyclass.rs:76:76
8+ |
9+ 76 | PyTypeInfo<Layout = PyCell<Self>> + Sized + PyClassAlloc + PyMethods + Send
10+ | ---- required by this bound in `pyo3::pyclass::PyClass`
11+ |
12+ = help: within `NotThreadSafe`, the trait `std::marker::Send` is not implemented for `std::rc::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