diff --git a/src/conversion.rs b/src/conversion.rs index 8ec196f8..b07fef42 100644 --- a/src/conversion.rs +++ b/src/conversion.rs @@ -94,16 +94,6 @@ pub trait ToBorrowedObject: ToPyObject { /// May be more efficient than `to_object` because it does not need /// to touch any reference counts when the input object already is a Python object. fn with_borrowed_ptr(&self, py: Python, f: F) -> R - where - F: FnOnce(*mut ffi::PyObject) -> R; -} - -#[cfg(feature = "nightly")] -impl ToBorrowedObject for T -where - T: ToPyObject, -{ - default fn with_borrowed_ptr(&self, py: Python, f: F) -> R where F: FnOnce(*mut ffi::PyObject) -> R, { @@ -116,12 +106,12 @@ where } } -#[cfg(not(feature = "nightly"))] impl ToBorrowedObject for T where T: ToPyObject, { - fn with_borrowed_ptr(&self, py: Python, f: F) -> R + #[cfg(feature = "nightly")] + default fn with_borrowed_ptr(&self, py: Python, f: F) -> R where F: FnOnce(*mut ffi::PyObject) -> R, { diff --git a/src/types/sequence.rs b/src/types/sequence.rs index b8aedb3c..97dd819e 100644 --- a/src/types/sequence.rs +++ b/src/types/sequence.rs @@ -1,7 +1,5 @@ // Copyright (c) 2017-present PyO3 Project and Contributors -#[cfg(feature = "nightly")] -use crate::buffer; use crate::err::{self, PyDowncastError, PyErr, PyResult}; use crate::exceptions; use crate::ffi::{self, Py_ssize_t}; @@ -262,24 +260,19 @@ impl PySequence { macro_rules! array_impls { ($($N:expr),+) => { $( - #[cfg(feature = "nightly")] impl<'a, T> FromPyObject<'a> for [T; $N] where T: Copy + Default + FromPyObject<'a>, { - default fn extract(obj: &'a PyAny) -> PyResult { + #[cfg(not(feature = "nightly"))] + fn extract(obj: &'a PyAny) -> PyResult { let mut array = [T::default(); $N]; extract_sequence_into_slice(obj, &mut array)?; Ok(array) } - } - #[cfg(not(feature = "nightly"))] - impl<'a, T> FromPyObject<'a> for [T; $N] - where - T: Copy + Default + FromPyObject<'a>, - { - fn extract(obj: &'a PyAny) -> PyResult { + #[cfg(feature = "nightly")] + default fn extract(obj: &'a PyAny) -> PyResult { let mut array = [T::default(); $N]; extract_sequence_into_slice(obj, &mut array)?; Ok(array) @@ -289,12 +282,12 @@ macro_rules! array_impls { #[cfg(feature = "nightly")] impl<'source, T> FromPyObject<'source> for [T; $N] where - for<'a> T: Copy + Default + FromPyObject<'a> + buffer::Element, + for<'a> T: Default + FromPyObject<'a> + crate::buffer::Element, { fn extract(obj: &'source PyAny) -> PyResult { let mut array = [T::default(); $N]; // first try buffer protocol - if let Ok(buf) = buffer::PyBuffer::get(obj) { + if let Ok(buf) = crate::buffer::PyBuffer::get(obj) { if buf.dimensions() == 1 && buf.copy_to_slice(obj.py(), &mut array).is_ok() { buf.release(obj.py()); return Ok(array); @@ -315,21 +308,15 @@ array_impls!( 26, 27, 28, 29, 30, 31, 32 ); -#[cfg(not(feature = "nightly"))] impl<'a, T> FromPyObject<'a> for Vec where T: FromPyObject<'a>, { + #[cfg(not(feature = "nightly"))] fn extract(obj: &'a PyAny) -> PyResult { extract_sequence(obj) } -} - -#[cfg(feature = "nightly")] -impl<'a, T> FromPyObject<'a> for Vec -where - T: FromPyObject<'a>, -{ + #[cfg(feature = "nightly")] default fn extract(obj: &'a PyAny) -> PyResult { extract_sequence(obj) } @@ -338,11 +325,11 @@ where #[cfg(feature = "nightly")] impl<'source, T> FromPyObject<'source> for Vec where - for<'a> T: FromPyObject<'a> + buffer::Element + Copy, + for<'a> T: FromPyObject<'a> + crate::buffer::Element, { fn extract(obj: &'source PyAny) -> PyResult { // first try buffer protocol - if let Ok(buf) = buffer::PyBuffer::get(obj) { + if let Ok(buf) = crate::buffer::PyBuffer::get(obj) { if buf.dimensions() == 1 { if let Ok(v) = buf.to_vec(obj.py()) { buf.release(obj.py()); diff --git a/tests/test_compile_error.rs b/tests/test_compile_error.rs index 465922b5..f9a18eda 100644 --- a/tests/test_compile_error.rs +++ b/tests/test_compile_error.rs @@ -1,22 +1,20 @@ +#[rustversion::stable] #[test] fn test_compile_errors() { let t = trybuild::TestCases::new(); - testcase_common(&t); - testcase_latest_stable(&t); + t.compile_fail("tests/ui/invalid_macro_args.rs"); + t.compile_fail("tests/ui/invalid_property_args.rs"); + t.compile_fail("tests/ui/invalid_pyclass_args.rs"); + t.compile_fail("tests/ui/missing_clone.rs"); + t.compile_fail("tests/ui/reject_generics.rs"); + t.compile_fail("tests/ui/wrong_aspyref_lifetimes.rs"); + + skip_min_stable(&t); - fn testcase_common(t: &trybuild::TestCases) { - t.compile_fail("tests/ui/invalid_macro_args.rs"); - t.compile_fail("tests/ui/invalid_property_args.rs"); - t.compile_fail("tests/ui/invalid_pyclass_args.rs"); - t.compile_fail("tests/ui/missing_clone.rs"); - t.compile_fail("tests/ui/reject_generics.rs"); - t.compile_fail("tests/ui/wrong_aspyref_lifetimes.rs"); - t.compile_fail("tests/ui/invalid_pymethod_names.rs"); - } #[rustversion::since(1.43)] - fn testcase_latest_stable(t: &trybuild::TestCases) { + fn skip_min_stable(t: &trybuild::TestCases) { t.compile_fail("tests/ui/static_ref.rs"); } #[rustversion::before(1.43)] - fn testcase_latest_stable(_t: &trybuild::TestCases) {} + fn skip_min_stable(_t: &trybuild::TestCases) {} }