From db29cc06c1951bd52964f2bd3d694bf5a5740ef0 Mon Sep 17 00:00:00 2001 From: mejrs <> Date: Thu, 6 Oct 2022 02:04:34 +0200 Subject: [PATCH 1/8] Don't use intocallback in method macros --- pyo3-macros-backend/src/method.rs | 11 ++-- pyo3-macros-backend/src/pymethod.rs | 7 +-- src/callback.rs | 27 +++++++++- src/impl_.rs | 1 - src/impl_/ghost.rs | 18 ------- src/pyclass.rs | 3 +- tests/ui/invalid_result_conversion.stderr | 38 +++++--------- tests/ui/missing_intopy.stderr | 63 +++++++---------------- 8 files changed, 64 insertions(+), 104 deletions(-) delete mode 100644 src/impl_/ghost.rs diff --git a/pyo3-macros-backend/src/method.rs b/pyo3-macros-backend/src/method.rs index dcb0d91b05c..5beeeaa70ab 100644 --- a/pyo3-macros-backend/src/method.rs +++ b/pyo3-macros-backend/src/method.rs @@ -468,17 +468,12 @@ impl<'a> FnSpec<'a> { quote!(#func_name) }; - // The method call is necessary to generate a decent error message. let rust_call = |args: Vec| { quote! { let mut ret = #rust_name(#self_arg #(#args),*); - - if false { - use _pyo3::impl_::ghost::IntoPyResult; - ret.assert_into_py_result(); - } - - _pyo3::callback::convert(#py, ret) + let owned = _pyo3::callback::OkWrap::wrap(ret, #py); + owned.map(|obj| _pyo3::conversion::IntoPyPointer::into_ptr(obj)) + .map_err(::core::convert::Into::into) } }; diff --git a/pyo3-macros-backend/src/pymethod.rs b/pyo3-macros-backend/src/pymethod.rs index 3bf3e6f4471..2800b21e884 100644 --- a/pyo3-macros-backend/src/pymethod.rs +++ b/pyo3-macros-backend/src/pymethod.rs @@ -389,11 +389,8 @@ fn impl_py_class_attribute(cls: &syn::Type, spec: &FnSpec<'_>) -> syn::Result) -> _pyo3::PyResult<_pyo3::PyObject> { #deprecations let mut ret = #fncall; - if false { - use _pyo3::impl_::ghost::IntoPyResult; - ret.assert_into_py_result(); - } - _pyo3::callback::convert(py, ret) + let owned = _pyo3::callback::OkWrap::wrap(ret, py); + owned.map_err(::core::convert::Into::into) } }; diff --git a/src/callback.rs b/src/callback.rs index 457c9a53b38..2c986586052 100644 --- a/src/callback.rs +++ b/src/callback.rs @@ -8,7 +8,7 @@ use crate::ffi::{self, Py_hash_t}; use crate::impl_::panic::PanicTrap; use crate::panic::PanicException; use crate::{GILPool, IntoPyPointer}; -use crate::{IntoPy, PyObject, Python}; +use crate::{IntoPy, Py, PyAny, PyObject, Python}; use std::any::Any; use std::os::raw::c_int; use std::panic::UnwindSafe; @@ -134,6 +134,31 @@ pub trait WrappingCastTo { fn wrapping_cast(self) -> T; } +pub trait OkWrap { + type Error; + fn wrap(self, py: Python<'_>) -> Result, Self::Error>; +} + +impl OkWrap for T +where + T: IntoPy, +{ + type Error = PyErr; + fn wrap(self, py: Python<'_>) -> PyResult> { + Ok(self.into_py(py)) + } +} + +impl OkWrap for Result +where + T: IntoPy, +{ + type Error = E; + fn wrap(self, py: Python<'_>) -> Result, Self::Error> { + self.map(|o| o.into_py(py)) + } +} + macro_rules! wrapping_cast { ($from:ty, $to:ty) => { impl WrappingCastTo<$to> for $from { diff --git a/src/impl_.rs b/src/impl_.rs index 08ef053b072..6b4db2b8634 100644 --- a/src/impl_.rs +++ b/src/impl_.rs @@ -10,7 +10,6 @@ pub mod deprecations; pub mod extract_argument; pub mod freelist; pub mod frompyobject; -pub mod ghost; pub(crate) mod not_send; pub mod panic; pub mod pycell; diff --git a/src/impl_/ghost.rs b/src/impl_/ghost.rs deleted file mode 100644 index 667607dd001..00000000000 --- a/src/impl_/ghost.rs +++ /dev/null @@ -1,18 +0,0 @@ -/// If it does nothing, was it ever really there? 👻 -/// -/// This is code that is just type checked to e.g. create better compile errors, -/// but that never affects anything at runtime, -use crate::{IntoPy, PyErr, PyObject}; - -pub trait IntoPyResult { - fn assert_into_py_result(&mut self) {} -} - -impl IntoPyResult for T where T: IntoPy {} - -impl IntoPyResult for Result -where - T: IntoPy, - E: Into, -{ -} diff --git a/src/pyclass.rs b/src/pyclass.rs index ffec5c9a350..1bd06d56d9b 100644 --- a/src/pyclass.rs +++ b/src/pyclass.rs @@ -341,6 +341,8 @@ impl PyTypeBuilder { module_name: Option<&'static str>, basicsize: usize, ) -> PyResult<*mut ffi::PyTypeObject> { + #![allow(clippy::useless_conversion)] + self.finalize_methods_and_properties(); if !self.has_new { @@ -378,7 +380,6 @@ impl PyTypeBuilder { itemsize: 0, // `c_ulong` and `c_uint` have the same size // on some platforms (like windows) - #[allow(clippy::useless_conversion)] flags: (ffi::Py_TPFLAGS_DEFAULT | self.class_flags) .try_into() .unwrap(), diff --git a/tests/ui/invalid_result_conversion.stderr b/tests/ui/invalid_result_conversion.stderr index a92e8ccc91a..a22455aeb4f 100644 --- a/tests/ui/invalid_result_conversion.stderr +++ b/tests/ui/invalid_result_conversion.stderr @@ -1,30 +1,18 @@ -error[E0599]: no method named `assert_into_py_result` found for enum `Result` in the current scope +error[E0277]: the trait bound `PyErr: From` is not satisfied --> tests/ui/invalid_result_conversion.rs:21:1 | 21 | #[pyfunction] - | ^^^^^^^^^^^^^ method not found in `Result<(), MyError>` + | ^^^^^^^^^^^^^ the trait `From` is not implemented for `PyErr` | -note: the method `assert_into_py_result` exists on the type `()` - --> src/impl_/ghost.rs - | - | fn assert_into_py_result(&mut self) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = help: the following other types implement trait `From`: + > + > + > + > + > + > + > + > + and 77 others + = note: required because of the requirements on the impl of `Into` for `MyError` = note: this error originates in the attribute macro `pyfunction` (in Nightly builds, run with -Z macro-backtrace for more info) -help: use the `?` operator to extract the `()` value, propagating a `Result::Err` value to the caller - | -21 | #[pyfunction]? - | + - -error[E0277]: the trait bound `Result<(), MyError>: IntoPyCallbackOutput<_>` is not satisfied - --> tests/ui/invalid_result_conversion.rs:21:1 - | -21 | #[pyfunction] - | ^^^^^^^^^^^^^ the trait `IntoPyCallbackOutput<_>` is not implemented for `Result<(), MyError>` - | - = help: the trait `IntoPyCallbackOutput` is implemented for `Result` -note: required by a bound in `pyo3::callback::convert` - --> src/callback.rs - | - | T: IntoPyCallbackOutput, - | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `pyo3::callback::convert` - = note: this error originates in the attribute macro `pyfunction` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/missing_intopy.stderr b/tests/ui/missing_intopy.stderr index f9a90788117..e82526dbf04 100644 --- a/tests/ui/missing_intopy.stderr +++ b/tests/ui/missing_intopy.stderr @@ -1,45 +1,18 @@ -error[E0599]: the method `assert_into_py_result` exists for struct `Blah`, but its trait bounds were not satisfied - --> tests/ui/missing_intopy.rs:3:1 - | -1 | struct Blah; - | ----------- - | | - | method `assert_into_py_result` not found for this struct - | doesn't satisfy `Blah: IntoPy>` - | doesn't satisfy `Blah: IntoPyResult` -2 | -3 | #[pyo3::pyfunction] - | ^^^^^^^^^^^^^^^^^^^ method cannot be called on `Blah` due to unsatisfied trait bounds - | - = note: the following trait bounds were not satisfied: - `Blah: IntoPy>` - which is required by `Blah: IntoPyResult` -note: the following trait must be implemented - --> src/conversion.rs - | - | pub trait IntoPy: Sized { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in the attribute macro `pyo3::pyfunction` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the trait bound `Blah: IntoPyCallbackOutput<_>` is not satisfied - --> tests/ui/missing_intopy.rs:3:1 - | -3 | #[pyo3::pyfunction] - | ^^^^^^^^^^^^^^^^^^^ the trait `IntoPyCallbackOutput<_>` is not implemented for `Blah` - | - = help: the following other types implement trait `IntoPyCallbackOutput`: - <() as IntoPyCallbackOutput<()>> - <() as IntoPyCallbackOutput> - <*mut PyObject as IntoPyCallbackOutput<*mut PyObject>> - > - , Py> as IntoPyCallbackOutput<*mut PyObject>> - as IntoPyCallbackOutput, Py>>> - , Py> as IntoPyCallbackOutput<*mut PyObject>> - as IntoPyCallbackOutput, Py>>> - and 7 others -note: required by a bound in `pyo3::callback::convert` - --> src/callback.rs - | - | T: IntoPyCallbackOutput, - | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `pyo3::callback::convert` - = note: this error originates in the attribute macro `pyo3::pyfunction` (in Nightly builds, run with -Z macro-backtrace for more info) +error[E0277]: the trait bound `Blah: IntoPy>` is not satisfied + --> tests/ui/missing_intopy.rs:3:1 + | +3 | #[pyo3::pyfunction] + | ^^^^^^^^^^^^^^^^^^^ the trait `IntoPy>` is not implemented for `Blah` + | + = help: the following other types implement trait `IntoPy`: + <&'a OsString as IntoPy>> + <&'a Path as IntoPy>> + <&'a PathBuf as IntoPy>> + <&'a PyErr as IntoPy>> + <&'a String as IntoPy>> + <&'a [u8] as IntoPy>> + <&'a str as IntoPy>> + <&'a str as IntoPy>> + and 173 others + = note: required because of the requirements on the impl of `OkWrap` for `Blah` + = note: this error originates in the attribute macro `pyo3::pyfunction` (in Nightly builds, run with -Z macro-backtrace for more info) From 261058d51e1e09dd5902ce4af716ab0ad4495b1a Mon Sep 17 00:00:00 2001 From: mejrs <> Date: Fri, 7 Oct 2022 00:03:29 +0200 Subject: [PATCH 2/8] Move to impl_/pymethod --- pyo3-macros-backend/src/method.rs | 2 +- pyo3-macros-backend/src/pymethod.rs | 2 +- src/callback.rs | 27 +-------------------------- src/impl_/pymethods.rs | 28 +++++++++++++++++++++++++++- src/pyclass.rs | 5 +++-- tests/ui/missing_intopy.stderr | 2 +- 6 files changed, 34 insertions(+), 32 deletions(-) diff --git a/pyo3-macros-backend/src/method.rs b/pyo3-macros-backend/src/method.rs index 5beeeaa70ab..c120b2026f9 100644 --- a/pyo3-macros-backend/src/method.rs +++ b/pyo3-macros-backend/src/method.rs @@ -471,7 +471,7 @@ impl<'a> FnSpec<'a> { let rust_call = |args: Vec| { quote! { let mut ret = #rust_name(#self_arg #(#args),*); - let owned = _pyo3::callback::OkWrap::wrap(ret, #py); + let owned = _pyo3::impl_::pymethods::OkWrap::wrap(ret, #py); owned.map(|obj| _pyo3::conversion::IntoPyPointer::into_ptr(obj)) .map_err(::core::convert::Into::into) } diff --git a/pyo3-macros-backend/src/pymethod.rs b/pyo3-macros-backend/src/pymethod.rs index 2800b21e884..ba9b66c2b1b 100644 --- a/pyo3-macros-backend/src/pymethod.rs +++ b/pyo3-macros-backend/src/pymethod.rs @@ -389,7 +389,7 @@ fn impl_py_class_attribute(cls: &syn::Type, spec: &FnSpec<'_>) -> syn::Result) -> _pyo3::PyResult<_pyo3::PyObject> { #deprecations let mut ret = #fncall; - let owned = _pyo3::callback::OkWrap::wrap(ret, py); + let owned = _pyo3::impl_::pymethods::OkWrap::wrap(ret, py); owned.map_err(::core::convert::Into::into) } }; diff --git a/src/callback.rs b/src/callback.rs index 2c986586052..457c9a53b38 100644 --- a/src/callback.rs +++ b/src/callback.rs @@ -8,7 +8,7 @@ use crate::ffi::{self, Py_hash_t}; use crate::impl_::panic::PanicTrap; use crate::panic::PanicException; use crate::{GILPool, IntoPyPointer}; -use crate::{IntoPy, Py, PyAny, PyObject, Python}; +use crate::{IntoPy, PyObject, Python}; use std::any::Any; use std::os::raw::c_int; use std::panic::UnwindSafe; @@ -134,31 +134,6 @@ pub trait WrappingCastTo { fn wrapping_cast(self) -> T; } -pub trait OkWrap { - type Error; - fn wrap(self, py: Python<'_>) -> Result, Self::Error>; -} - -impl OkWrap for T -where - T: IntoPy, -{ - type Error = PyErr; - fn wrap(self, py: Python<'_>) -> PyResult> { - Ok(self.into_py(py)) - } -} - -impl OkWrap for Result -where - T: IntoPy, -{ - type Error = E; - fn wrap(self, py: Python<'_>) -> Result, Self::Error> { - self.map(|o| o.into_py(py)) - } -} - macro_rules! wrapping_cast { ($from:ty, $to:ty) => { impl WrappingCastTo<$to> for $from { diff --git a/src/impl_/pymethods.rs b/src/impl_/pymethods.rs index 6234d297000..50634323b11 100644 --- a/src/impl_/pymethods.rs +++ b/src/impl_/pymethods.rs @@ -1,5 +1,5 @@ use crate::internal_tricks::{extract_cstr_or_leak_cstring, NulByteInString}; -use crate::{ffi, PyAny, PyObject, PyResult, PyTraverseError, Python}; +use crate::{ffi, IntoPy, Py, PyAny, PyErr, PyObject, PyResult, PyTraverseError, Python}; use std::ffi::CStr; use std::fmt; use std::os::raw::c_int; @@ -262,3 +262,29 @@ pub fn unwrap_traverse_result(result: Result<(), PyTraverseError>) -> c_int { Err(PyTraverseError(value)) => value, } } + +// The macros need to Ok-wrap the output of user defined functions; i.e. if they're not a result, make them into one. +pub trait OkWrap { + type Error; + fn wrap(self, py: Python<'_>) -> Result, Self::Error>; +} + +impl OkWrap for T +where + T: IntoPy, +{ + type Error = PyErr; + fn wrap(self, py: Python<'_>) -> PyResult> { + Ok(self.into_py(py)) + } +} + +impl OkWrap for Result +where + T: IntoPy, +{ + type Error = E; + fn wrap(self, py: Python<'_>) -> Result, Self::Error> { + self.map(|o| o.into_py(py)) + } +} diff --git a/src/pyclass.rs b/src/pyclass.rs index 1bd06d56d9b..d82cdd7348e 100644 --- a/src/pyclass.rs +++ b/src/pyclass.rs @@ -341,6 +341,8 @@ impl PyTypeBuilder { module_name: Option<&'static str>, basicsize: usize, ) -> PyResult<*mut ffi::PyTypeObject> { + // `c_ulong` and `c_uint` have the same size + // on some platforms (like windows) #![allow(clippy::useless_conversion)] self.finalize_methods_and_properties(); @@ -378,8 +380,7 @@ impl PyTypeBuilder { name: py_class_qualified_name(module_name, name)?, basicsize: basicsize as c_int, itemsize: 0, - // `c_ulong` and `c_uint` have the same size - // on some platforms (like windows) + flags: (ffi::Py_TPFLAGS_DEFAULT | self.class_flags) .try_into() .unwrap(), diff --git a/tests/ui/missing_intopy.stderr b/tests/ui/missing_intopy.stderr index e82526dbf04..4212b66b0f9 100644 --- a/tests/ui/missing_intopy.stderr +++ b/tests/ui/missing_intopy.stderr @@ -13,6 +13,6 @@ error[E0277]: the trait bound `Blah: IntoPy>` is not satisfied <&'a [u8] as IntoPy>> <&'a str as IntoPy>> <&'a str as IntoPy>> - and 173 others + and 156 others = note: required because of the requirements on the impl of `OkWrap` for `Blah` = note: this error originates in the attribute macro `pyo3::pyfunction` (in Nightly builds, run with -Z macro-backtrace for more info) From 2f92ebba5741b3e6172f8612426b7c2aa68b892a Mon Sep 17 00:00:00 2001 From: mejrs <> Date: Fri, 7 Oct 2022 00:38:58 +0200 Subject: [PATCH 3/8] Fix CI --- tests/ui/invalid_result_conversion.stderr | 2 +- tests/ui/missing_intopy.stderr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ui/invalid_result_conversion.stderr b/tests/ui/invalid_result_conversion.stderr index a22455aeb4f..2f99be0ff9a 100644 --- a/tests/ui/invalid_result_conversion.stderr +++ b/tests/ui/invalid_result_conversion.stderr @@ -13,6 +13,6 @@ error[E0277]: the trait bound `PyErr: From` is not satisfied > > > - and 77 others + and 76 others = note: required because of the requirements on the impl of `Into` for `MyError` = note: this error originates in the attribute macro `pyfunction` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/missing_intopy.stderr b/tests/ui/missing_intopy.stderr index 4212b66b0f9..fc09d471332 100644 --- a/tests/ui/missing_intopy.stderr +++ b/tests/ui/missing_intopy.stderr @@ -13,6 +13,6 @@ error[E0277]: the trait bound `Blah: IntoPy>` is not satisfied <&'a [u8] as IntoPy>> <&'a str as IntoPy>> <&'a str as IntoPy>> - and 156 others + and 172 others = note: required because of the requirements on the impl of `OkWrap` for `Blah` = note: this error originates in the attribute macro `pyo3::pyfunction` (in Nightly builds, run with -Z macro-backtrace for more info) From c9d419bb67a0a0517e058bd0bca32a8e256fbd11 Mon Sep 17 00:00:00 2001 From: mejrs <> Date: Sat, 8 Oct 2022 18:16:36 +0200 Subject: [PATCH 4/8] Add newsfragment --- newsfragments/2664.changed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 newsfragments/2664.changed.md diff --git a/newsfragments/2664.changed.md b/newsfragments/2664.changed.md new file mode 100644 index 00000000000..7dd461d7fb5 --- /dev/null +++ b/newsfragments/2664.changed.md @@ -0,0 +1 @@ +PyO3's macros now emit a much nicer error message if function return values don't implement the required trait(s). \ No newline at end of file From a0ca6b386fd1f099786ae309581a7a74922e82dd Mon Sep 17 00:00:00 2001 From: mejrs <> Date: Sat, 8 Oct 2022 18:16:59 +0200 Subject: [PATCH 5/8] Only run some tests with some configurations --- tests/test_compile_error.rs | 12 ++++++++++-- tests/ui/invalid_result_conversion.stderr | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/test_compile_error.rs b/tests/test_compile_error.rs index edd5164f19f..f1a6a7de578 100644 --- a/tests/test_compile_error.rs +++ b/tests/test_compile_error.rs @@ -105,7 +105,11 @@ fn _test_compile_errors() { #[rustversion::since(1.62)] fn tests_rust_1_62(t: &trybuild::TestCases) { t.compile_fail("tests/ui/invalid_pymethod_receiver.rs"); - t.compile_fail("tests/ui/missing_intopy.rs"); + // Avoid `"and X others" from mismatching + // by only running this for some configurations + if cfg!(all(target_os = "linux", not(feature = "full"))) { + t.compile_fail("tests/ui/missing_intopy.rs"); + } } #[rustversion::before(1.62)] @@ -113,7 +117,11 @@ fn _test_compile_errors() { #[rustversion::since(1.63)] fn tests_rust_1_63(t: &trybuild::TestCases) { - t.compile_fail("tests/ui/invalid_result_conversion.rs"); + // Avoid `"and X others" from mismatching + // by only running this for some configurations + if cfg!(all(target_os = "linux", not(feature = "full"))) { + t.compile_fail("tests/ui/invalid_result_conversion.rs"); + } t.compile_fail("tests/ui/not_send.rs"); t.compile_fail("tests/ui/not_send2.rs"); t.compile_fail("tests/ui/not_send3.rs"); diff --git a/tests/ui/invalid_result_conversion.stderr b/tests/ui/invalid_result_conversion.stderr index 2f99be0ff9a..a22455aeb4f 100644 --- a/tests/ui/invalid_result_conversion.stderr +++ b/tests/ui/invalid_result_conversion.stderr @@ -13,6 +13,6 @@ error[E0277]: the trait bound `PyErr: From` is not satisfied > > > - and 76 others + and 77 others = note: required because of the requirements on the impl of `Into` for `MyError` = note: this error originates in the attribute macro `pyfunction` (in Nightly builds, run with -Z macro-backtrace for more info) From 391a65f365c27adf2707d0c9e10d0dd661f8b03c Mon Sep 17 00:00:00 2001 From: mejrs <> Date: Sat, 8 Oct 2022 18:42:42 +0200 Subject: [PATCH 6/8] Run some tests only sometimes --- tests/test_compile_error.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/test_compile_error.rs b/tests/test_compile_error.rs index f1a6a7de578..8645d5c7d3c 100644 --- a/tests/test_compile_error.rs +++ b/tests/test_compile_error.rs @@ -107,7 +107,11 @@ fn _test_compile_errors() { t.compile_fail("tests/ui/invalid_pymethod_receiver.rs"); // Avoid `"and X others" from mismatching // by only running this for some configurations - if cfg!(all(target_os = "linux", not(feature = "full"))) { + if cfg!(all( + target_os = "linux", + feature = "full", + not(feature = "abi3") + )) { t.compile_fail("tests/ui/missing_intopy.rs"); } } @@ -119,7 +123,11 @@ fn _test_compile_errors() { fn tests_rust_1_63(t: &trybuild::TestCases) { // Avoid `"and X others" from mismatching // by only running this for some configurations - if cfg!(all(target_os = "linux", not(feature = "full"))) { + if cfg!(all( + target_os = "linux", + feature = "full", + not(feature = "abi3") + )) { t.compile_fail("tests/ui/invalid_result_conversion.rs"); } t.compile_fail("tests/ui/not_send.rs"); From ef343f413b5aa09d95bb4b9fe0d88f4eaf27d358 Mon Sep 17 00:00:00 2001 From: mejrs <> Date: Sat, 8 Oct 2022 18:49:40 +0200 Subject: [PATCH 7/8] Update impl count --- tests/ui/invalid_result_conversion.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/invalid_result_conversion.stderr b/tests/ui/invalid_result_conversion.stderr index a22455aeb4f..2f99be0ff9a 100644 --- a/tests/ui/invalid_result_conversion.stderr +++ b/tests/ui/invalid_result_conversion.stderr @@ -13,6 +13,6 @@ error[E0277]: the trait bound `PyErr: From` is not satisfied > > > - and 77 others + and 76 others = note: required because of the requirements on the impl of `Into` for `MyError` = note: this error originates in the attribute macro `pyfunction` (in Nightly builds, run with -Z macro-backtrace for more info) From cfab15e2ff94bf76da2fe79ccafb190a56b16a9e Mon Sep 17 00:00:00 2001 From: mejrs <> Date: Sat, 8 Oct 2022 23:14:30 +0200 Subject: [PATCH 8/8] Use new trybuild --- Cargo.toml | 3 ++- tests/test_compile_error.rs | 20 ++------------------ tests/ui/invalid_result_conversion.stderr | 2 +- tests/ui/missing_intopy.stderr | 2 +- 4 files changed, 6 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f77de952453..a8c89c45121 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,7 +44,8 @@ serde = { version = "1.0", optional = true } assert_approx_eq = "1.1.0" chrono = { version = "0.4" } criterion = "0.3.5" -trybuild = "1.0.49" +# Required for "and $N others" normalization +trybuild = ">=1.0.70" rustversion = "1.0" # 1.0.0 requires Rust 1.50 proptest = { version = "0.10.1", default-features = false, features = ["std"] } diff --git a/tests/test_compile_error.rs b/tests/test_compile_error.rs index 8645d5c7d3c..edd5164f19f 100644 --- a/tests/test_compile_error.rs +++ b/tests/test_compile_error.rs @@ -105,15 +105,7 @@ fn _test_compile_errors() { #[rustversion::since(1.62)] fn tests_rust_1_62(t: &trybuild::TestCases) { t.compile_fail("tests/ui/invalid_pymethod_receiver.rs"); - // Avoid `"and X others" from mismatching - // by only running this for some configurations - if cfg!(all( - target_os = "linux", - feature = "full", - not(feature = "abi3") - )) { - t.compile_fail("tests/ui/missing_intopy.rs"); - } + t.compile_fail("tests/ui/missing_intopy.rs"); } #[rustversion::before(1.62)] @@ -121,15 +113,7 @@ fn _test_compile_errors() { #[rustversion::since(1.63)] fn tests_rust_1_63(t: &trybuild::TestCases) { - // Avoid `"and X others" from mismatching - // by only running this for some configurations - if cfg!(all( - target_os = "linux", - feature = "full", - not(feature = "abi3") - )) { - t.compile_fail("tests/ui/invalid_result_conversion.rs"); - } + t.compile_fail("tests/ui/invalid_result_conversion.rs"); t.compile_fail("tests/ui/not_send.rs"); t.compile_fail("tests/ui/not_send2.rs"); t.compile_fail("tests/ui/not_send3.rs"); diff --git a/tests/ui/invalid_result_conversion.stderr b/tests/ui/invalid_result_conversion.stderr index 2f99be0ff9a..30dce88c106 100644 --- a/tests/ui/invalid_result_conversion.stderr +++ b/tests/ui/invalid_result_conversion.stderr @@ -13,6 +13,6 @@ error[E0277]: the trait bound `PyErr: From` is not satisfied > > > - and 76 others + and $N others = note: required because of the requirements on the impl of `Into` for `MyError` = note: this error originates in the attribute macro `pyfunction` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/missing_intopy.stderr b/tests/ui/missing_intopy.stderr index fc09d471332..4f2fe3db8b0 100644 --- a/tests/ui/missing_intopy.stderr +++ b/tests/ui/missing_intopy.stderr @@ -13,6 +13,6 @@ error[E0277]: the trait bound `Blah: IntoPy>` is not satisfied <&'a [u8] as IntoPy>> <&'a str as IntoPy>> <&'a str as IntoPy>> - and 172 others + and $N others = note: required because of the requirements on the impl of `OkWrap` for `Blah` = note: this error originates in the attribute macro `pyo3::pyfunction` (in Nightly builds, run with -Z macro-backtrace for more info)