silence non-local-definitions nightly lint (#3901)

* silence non-local-definitions nightly lint

* add newsfragment

* add FIXMEs for `non_local_definitions`

* also allow `non_local_definitions` in doctests
This commit is contained in:
David Hewitt 2024-02-26 20:28:04 +00:00 committed by GitHub
parent 404161c969
commit 8e2219b0d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 46 additions and 12 deletions

View File

@ -0,0 +1 @@
Fix `non_local_definitions` lint warning triggered by many PyO3 macros.

View File

@ -604,6 +604,8 @@ pub fn build_derive_from_pyobject(tokens: &DeriveInput) -> Result<TokenStream> {
let ident = &tokens.ident;
Ok(quote!(
// FIXME https://github.com/PyO3/pyo3/issues/3903
#[allow(unknown_lints, non_local_definitions)]
const _: () = {
use #krate as _pyo3;
use _pyo3::prelude::PyAnyMethods;

View File

@ -211,6 +211,8 @@ pub fn pymodule_function_impl(mut function: syn::ItemFn) -> Result<TokenStream>
// this avoids complications around the fact that the generated module has a different scope
// (and `super` doesn't always refer to the outer scope, e.g. if the `#[pymodule] is
// inside a function body)
// FIXME https://github.com/PyO3/pyo3/issues/3903
#[allow(unknown_lints, non_local_definitions)]
const _: () = {
use #krate::impl_::pymodule as impl_;

View File

@ -362,6 +362,8 @@ fn impl_class(
.impl_all()?;
Ok(quote! {
// FIXME https://github.com/PyO3/pyo3/issues/3903
#[allow(unknown_lints, non_local_definitions)]
const _: () = {
use #krate as _pyo3;
@ -783,6 +785,8 @@ fn impl_simple_enum(
.impl_all()?;
Ok(quote! {
// FIXME https://github.com/PyO3/pyo3/issues/3903
#[allow(unknown_lints, non_local_definitions)]
const _: () = {
use #krate as _pyo3;
@ -917,6 +921,8 @@ fn impl_complex_enum(
}
Ok(quote! {
// FIXME https://github.com/PyO3/pyo3/issues/3903
#[allow(unknown_lints, non_local_definitions)]
const _: () = {
use #krate as _pyo3;

View File

@ -281,8 +281,11 @@ pub fn impl_wrap_pyfunction(
// this avoids complications around the fact that the generated module has a different scope
// (and `super` doesn't always refer to the outer scope, e.g. if the `#[pyfunction] is
// inside a function body)
// FIXME https://github.com/PyO3/pyo3/issues/3903
#[allow(unknown_lints, non_local_definitions)]
const _: () = {
use #krate as _pyo3;
impl #name::MakeDef {
const DEF: #krate::impl_::pyfunction::PyMethodDef = #methoddef;
}

View File

@ -168,6 +168,8 @@ pub fn impl_methods(
};
Ok(quote! {
// FIXME https://github.com/PyO3/pyo3/issues/3903
#[allow(unknown_lints, non_local_definitions)]
const _: () = {
use #krate as _pyo3;

View File

@ -1241,6 +1241,18 @@ impl SlotFragmentDef {
)?;
let ret_ty = ret_ty.ffi_type();
Ok(quote! {
impl #cls {
unsafe fn #wrapper_ident(
py: _pyo3::Python,
_raw_slf: *mut _pyo3::ffi::PyObject,
#(#arg_idents: #arg_types),*
) -> _pyo3::PyResult<#ret_ty> {
let _slf = _raw_slf;
#( #holders )*
#body
}
}
impl _pyo3::impl_::pyclass::#fragment_trait<#cls> for _pyo3::impl_::pyclass::PyClassImplCollector<#cls> {
#[inline]
@ -1250,17 +1262,6 @@ impl SlotFragmentDef {
_raw_slf: *mut _pyo3::ffi::PyObject,
#(#arg_idents: #arg_types),*
) -> _pyo3::PyResult<#ret_ty> {
impl #cls {
unsafe fn #wrapper_ident(
py: _pyo3::Python,
_raw_slf: *mut _pyo3::ffi::PyObject,
#(#arg_idents: #arg_types),*
) -> _pyo3::PyResult<#ret_ty> {
let _slf = _raw_slf;
#( #holders )*
#body
}
}
#cls::#wrapper_ident(py, _raw_slf, #(#arg_idents),*)
}
}

View File

@ -19,6 +19,8 @@ use std::os::raw::c_char;
#[macro_export]
macro_rules! impl_exception_boilerplate {
($name: ident) => {
// FIXME https://github.com/PyO3/pyo3/issues/3903
#[allow(unknown_lints, non_local_definitions)]
impl ::std::convert::From<&$name> for $crate::PyErr {
#[inline]
fn from(err: &$name) -> $crate::PyErr {

View File

@ -10,7 +10,14 @@
rust_2021_prelude_collisions,
warnings
),
allow(unused_variables, unused_assignments, unused_extern_crates)
allow(
unused_variables,
unused_assignments,
unused_extern_crates,
// FIXME https://github.com/rust-lang/rust/issues/121621#issuecomment-1965156376
unknown_lints,
non_local_definitions,
)
)))]
//! Rust bindings to the Python interpreter.

View File

@ -188,6 +188,8 @@ macro_rules! pyobject_native_type_named (
}
}
// FIXME https://github.com/PyO3/pyo3/issues/3903
#[allow(unknown_lints, non_local_definitions)]
impl<$($generics,)*> $crate::IntoPy<$crate::Py<$name>> for &'_ $name {
#[inline]
fn into_py(self, py: $crate::Python<'_>) -> $crate::Py<$name> {
@ -195,6 +197,8 @@ macro_rules! pyobject_native_type_named (
}
}
// FIXME https://github.com/PyO3/pyo3/issues/3903
#[allow(unknown_lints, non_local_definitions)]
impl<$($generics,)*> ::std::convert::From<&'_ $name> for $crate::Py<$name> {
#[inline]
fn from(other: &$name) -> Self {
@ -203,6 +207,8 @@ macro_rules! pyobject_native_type_named (
}
}
// FIXME https://github.com/PyO3/pyo3/issues/3903
#[allow(unknown_lints, non_local_definitions)]
impl<'a, $($generics,)*> ::std::convert::From<&'a $name> for &'a $crate::PyAny {
fn from(ob: &'a $name) -> Self {
unsafe{&*(ob as *const $name as *const $crate::PyAny)}
@ -252,6 +258,8 @@ macro_rules! pyobject_native_type_info(
#[macro_export]
macro_rules! pyobject_native_type_extract {
($name:ty $(;$generics:ident)*) => {
// FIXME https://github.com/PyO3/pyo3/issues/3903
#[allow(unknown_lints, non_local_definitions)]
impl<'py, $($generics,)*> $crate::FromPyObject<'py> for &'py $name {
#[inline]
fn extract_bound(obj: &$crate::Bound<'py, $crate::PyAny>) -> $crate::PyResult<Self> {