diff --git a/Cargo.toml b/Cargo.toml index 6383bab158d..732e066c7dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,9 +36,6 @@ rustversion = "1.0" default = ["macros"] macros = ["ctor", "indoc", "inventory", "paste", "pyo3cls", "unindent"] -# Supports arrays of arbitrary size -const-generics = [] - # Optimizes PyObject to Vec conversion and so on. nightly = [] diff --git a/src/lib.rs b/src/lib.rs index 5bd29ae0169..10f3e768f8e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,3 @@ -#![cfg_attr(feature = "const-generics", feature(min_const_generics))] -#![cfg_attr(feature = "nightly", allow(incomplete_features))] #![cfg_attr(feature = "nightly", feature(specialization))] #![allow(clippy::missing_safety_doc)] // FIXME (#698) diff --git a/src/types/list.rs b/src/types/list.rs index a23940936b6..406d4d82aca 100644 --- a/src/types/list.rs +++ b/src/types/list.rs @@ -178,7 +178,6 @@ where } } -#[cfg(feature = "const-generics")] impl IntoPy for [T; N] where T: ToPyObject, @@ -188,28 +187,6 @@ where } } -#[cfg(not(feature = "const-generics"))] -macro_rules! array_impls { - ($($N:expr),+) => { - $( - impl IntoPy for [T; $N] - where - T: ToPyObject - { - fn into_py(self, py: Python) -> PyObject { - self.as_ref().to_object(py) - } - } - )+ - } -} - -#[cfg(not(feature = "const-generics"))] -array_impls!( - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, - 26, 27, 28, 29, 30, 31, 32 -); - impl ToPyObject for Vec where T: ToPyObject, diff --git a/src/types/mod.rs b/src/types/mod.rs index 72f2b782515..baa483dc20b 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -236,13 +236,11 @@ mod string; mod tuple; mod typeobject; -#[cfg(feature = "const-generics")] struct ArrayGuard { dst: *mut T, initialized: usize, } -#[cfg(feature = "const-generics")] impl Drop for ArrayGuard { fn drop(&mut self) { debug_assert!(self.initialized <= N); @@ -253,7 +251,6 @@ impl Drop for ArrayGuard { } } -#[cfg(feature = "const-generics")] fn try_create_array(mut cb: F) -> Result<[T; N], E> where F: FnMut(usize) -> Result, diff --git a/src/types/sequence.rs b/src/types/sequence.rs index f4dc1d78062..dc62fc28db0 100644 --- a/src/types/sequence.rs +++ b/src/types/sequence.rs @@ -257,7 +257,6 @@ impl PySequence { } } -#[cfg(feature = "const-generics")] impl<'a, T, const N: usize> FromPyObject<'a> for [T; N] where T: FromPyObject<'a>, @@ -273,7 +272,6 @@ where } } -#[cfg(all(feature = "const-generics", feature = "nightly"))] impl<'source, T, const N: usize> FromPyObject<'source> for [T; N] where for<'a> T: FromPyObject<'a> + crate::buffer::Element, @@ -291,59 +289,6 @@ where } } -#[cfg(not(feature = "const-generics"))] -macro_rules! array_impls { - ($($N:expr),+) => { - $( - impl<'a, T> FromPyObject<'a> for [T; $N] - where - T: Copy + Default + FromPyObject<'a>, - { - #[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(feature = "nightly")] - default fn extract(obj: &'a PyAny) -> PyResult { - let mut array = [T::default(); $N]; - extract_sequence_into_slice(obj, &mut array)?; - Ok(array) - } - } - - #[cfg(feature = "nightly")] - impl<'source, T> FromPyObject<'source> for [T; $N] - where - 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) = 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); - } - buf.release(obj.py()); - } - // fall back to sequence protocol - extract_sequence_into_slice(obj, &mut array)?; - Ok(array) - } - } - )+ - } -} - -#[cfg(not(feature = "const-generics"))] -array_impls!( - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, - 26, 27, 28, 29, 30, 31, 32 -); - impl<'a, T> FromPyObject<'a> for Vec where T: FromPyObject<'a>, @@ -379,7 +324,6 @@ where } } -#[cfg(feature = "const-generics")] fn create_array_from_obj<'s, T, const N: usize>(obj: &'s PyAny) -> PyResult<[T; N]> where T: FromPyObject<'s>, @@ -406,23 +350,6 @@ where Ok(v) } -#[cfg(not(feature = "const-generics"))] -fn extract_sequence_into_slice<'s, T>(obj: &'s PyAny, slice: &mut [T]) -> PyResult<()> -where - T: FromPyObject<'s>, -{ - let seq = ::try_from(obj)?; - if seq.len()? as usize != slice.len() { - return Err(exceptions::PyBufferError::py_err( - "Slice length does not match buffer length.", - )); - } - for (value, item) in slice.iter_mut().zip(seq.iter()?) { - *value = item?.extract::()?; - } - Ok(()) -} - impl<'v> PyTryFrom<'v> for PySequence { fn try_from>(value: V) -> Result<&'v PySequence, PyDowncastError<'v>> { let value = value.into();