From f82ca328fb42bb80998a2951e768d22e9a7a041c Mon Sep 17 00:00:00 2001 From: Lily Foote Date: Thu, 21 Nov 2024 21:55:15 +0000 Subject: [PATCH] Fix #4723: ambiguous associated item in #[pyclass] This uses the fix described in https://github.com/rust-lang/rust/issues/57644 Also apply fix to `#[derive(IntoPyObject)]`. --- newsfragments/4725.fixed.md | 1 + pyo3-macros-backend/src/intopyobject.rs | 7 +++++-- pyo3-macros-backend/src/pyclass.rs | 14 ++++++++++---- 3 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 newsfragments/4725.fixed.md diff --git a/newsfragments/4725.fixed.md b/newsfragments/4725.fixed.md new file mode 100644 index 00000000000..9ee069c5eb4 --- /dev/null +++ b/newsfragments/4725.fixed.md @@ -0,0 +1 @@ +Fix `ambiguous_associated_items` lint error in `#[pyclass]` and `#[derive(IntoPyObject)]` macros. diff --git a/pyo3-macros-backend/src/intopyobject.rs b/pyo3-macros-backend/src/intopyobject.rs index 4a46c07418f..a60a5486cb8 100644 --- a/pyo3-macros-backend/src/intopyobject.rs +++ b/pyo3-macros-backend/src/intopyobject.rs @@ -512,7 +512,7 @@ impl<'a> Enum<'a> { IntoPyObjectImpl { types: IntoPyObjectTypes::Opaque { target: quote!(#pyo3_path::types::PyAny), - output: quote!(#pyo3_path::Bound<'py, Self::Target>), + output: quote!(#pyo3_path::Bound<'py, >::Target>), error: quote!(#pyo3_path::PyErr), }, body: quote! { @@ -617,7 +617,10 @@ pub fn build_derive_into_pyobject(tokens: &DeriveInput) -> Resu type Output = #output; type Error = #error; - fn into_pyobject(self, py: #pyo3_path::Python<#lt_param>) -> ::std::result::Result { + fn into_pyobject(self, py: #pyo3_path::Python<#lt_param>) -> ::std::result::Result< + ::Output, + ::Error, + > { #body } } diff --git a/pyo3-macros-backend/src/pyclass.rs b/pyo3-macros-backend/src/pyclass.rs index 87d02c6f878..93596611f18 100644 --- a/pyo3-macros-backend/src/pyclass.rs +++ b/pyo3-macros-backend/src/pyclass.rs @@ -1072,10 +1072,13 @@ fn impl_complex_enum( quote! { impl<'py> #pyo3_path::conversion::IntoPyObject<'py> for #cls { type Target = Self; - type Output = #pyo3_path::Bound<'py, Self::Target>; + type Output = #pyo3_path::Bound<'py, >::Target>; type Error = #pyo3_path::PyErr; - fn into_pyobject(self, py: #pyo3_path::Python<'py>) -> ::std::result::Result { + fn into_pyobject(self, py: #pyo3_path::Python<'py>) -> ::std::result::Result< + ::Output, + ::Error, + > { match self { #(#match_arms)* } @@ -2161,10 +2164,13 @@ impl<'a> PyClassImplsBuilder<'a> { impl<'py> #pyo3_path::conversion::IntoPyObject<'py> for #cls { type Target = Self; - type Output = #pyo3_path::Bound<'py, Self::Target>; + type Output = #pyo3_path::Bound<'py, >::Target>; type Error = #pyo3_path::PyErr; - fn into_pyobject(self, py: #pyo3_path::Python<'py>) -> ::std::result::Result { + fn into_pyobject(self, py: #pyo3_path::Python<'py>) -> ::std::result::Result< + ::Output, + ::Error, + > { #pyo3_path::Bound::new(py, self) } }