Skip to content

Commit f9a31b5

Browse files
committed
Replace the nightly UI tests by doctests since we cannot keep up with the changing error outputs of nightly in any case.
1 parent 7c4cdd2 commit f9a31b5

10 files changed

+84
-159
lines changed

src/marker.rs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,42 @@ use std::os::raw::c_int;
140140
/// the GIL is not held.
141141
///
142142
/// See the [module-level documentation](self) for more information.
143+
///
144+
/// # Examples
145+
///
146+
/// This tracking is currently imprecise as it relies on the [`Send`] auto trait on stable Rust.
147+
/// For example, an `Rc` smart pointer should be usable without the GIL, but we currently prevent that:
148+
///
149+
/// ```compile_fail
150+
/// # use pyo3::prelude::*;
151+
/// Python::with_gil(|py| {
152+
/// let rc = Rc::new(42);
153+
///
154+
/// py.allow_threads(|| {
155+
/// println!("{:?}", rc);
156+
/// });
157+
/// });
158+
/// ```
159+
///
160+
/// This also implies that one can circumvent this protection using e.g. the [`send_wrapper`] crate:
161+
///
162+
/// ```no_run
163+
/// # use pyo3::prelude::*;
164+
/// # use pyo3::types::PyString;
165+
/// use send_wrapper::SendWrapper;
166+
///
167+
/// Python::with_gil(|py| {
168+
/// let string = PyString::new(py, "foo");
169+
///
170+
/// let wrapped = SendWrapper::new(string);
171+
///
172+
/// py.allow_threads(|| {
173+
/// let sneaky: &PyString = *wrapped;
174+
///
175+
/// println!("{:?}", sneaky);
176+
/// });
177+
/// });
178+
/// ```
143179
#[cfg_attr(docsrs, doc(cfg(all())))] // Hide the cfg flag
144180
#[cfg(not(feature = "nightly"))]
145181
pub unsafe trait Ungil {}
@@ -156,6 +192,54 @@ unsafe impl<T: Send> Ungil for T {}
156192
/// the GIL is not held.
157193
///
158194
/// See the [module-level documentation](self) for more information.
195+
///
196+
/// # Examples
197+
///
198+
/// Types which are `Ungil` cannot be used in contexts where the GIL was released, e.g.
199+
///
200+
/// ```compile_fail
201+
/// # use pyo3::prelude::*;
202+
/// # use pyo3::types::PyString;
203+
/// Python::with_gil(|py| {
204+
/// let string = PyString::new(py, "foo");
205+
///
206+
/// py.allow_threads(|| {
207+
/// println!("{:?}", string);
208+
/// });
209+
/// });
210+
/// ```
211+
///
212+
/// This applies to the GIL token `Python` itself as well, e.g.
213+
///
214+
/// ```compile_fail
215+
/// # use pyo3::prelude::*;
216+
/// Python::with_gil(|py| {
217+
/// py.allow_threads(|| {
218+
/// drop(py);
219+
/// });
220+
/// });
221+
/// ```
222+
///
223+
/// On nightly Rust, this is not based on the [`Send`] auto trait and hence we are able
224+
/// to prevent incorrectly circumventing it using e.g. the [`send_wrapper`] crate:
225+
///
226+
/// ```compile_fail
227+
/// # use pyo3::prelude::*;
228+
/// # use pyo3::types::PyString;
229+
/// use send_wrapper::SendWrapper;
230+
///
231+
/// Python::with_gil(|py| {
232+
/// let string = PyString::new(py, "foo");
233+
///
234+
/// let wrapped = SendWrapper::new(string);
235+
///
236+
/// py.allow_threads(|| {
237+
/// let sneaky: &PyString = *wrapped;
238+
///
239+
/// println!("{:?}", sneaky);
240+
/// });
241+
/// });
242+
/// ```
159243
#[cfg(feature = "nightly")]
160244
pub unsafe auto trait Ungil {}
161245

tests/test_compile_error.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,4 @@ fn test_compile_errors() {
3737
t.compile_fail("tests/ui/not_send.rs");
3838
t.compile_fail("tests/ui/not_send2.rs");
3939
t.compile_fail("tests/ui/get_set_all.rs");
40-
#[cfg(not(feature = "nightly"))]
41-
t.compile_fail("tests/ui/not_send3.rs");
42-
#[cfg(feature = "nightly")]
43-
t.compile_fail("tests/ui/not_send_auto_trait.rs");
44-
#[cfg(feature = "nightly")]
45-
t.compile_fail("tests/ui/not_send_auto_trait2.rs");
46-
#[cfg(feature = "nightly")]
47-
t.compile_fail("tests/ui/send_wrapper.rs");
4840
}

tests/ui/not_send3.rs

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/ui/not_send3.stderr

Lines changed: 0 additions & 24 deletions
This file was deleted.

tests/ui/not_send_auto_trait.rs

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/ui/not_send_auto_trait.stderr

Lines changed: 0 additions & 21 deletions
This file was deleted.

tests/ui/not_send_auto_trait2.rs

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/ui/not_send_auto_trait2.stderr

Lines changed: 0 additions & 26 deletions
This file was deleted.

tests/ui/send_wrapper.rs

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/ui/send_wrapper.stderr

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)