diff --git a/pin-project-internal/src/pinned_drop.rs b/pin-project-internal/src/pinned_drop.rs index f6473ebe..e8452023 100644 --- a/pin-project-internal/src/pinned_drop.rs +++ b/pin-project-internal/src/pinned_drop.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 OR MIT -use proc_macro2::TokenStream; +use proc_macro2::{Span, TokenStream}; use quote::{format_ident, quote, ToTokens}; use syn::{ parse_quote, spanned::Spanned, token::Colon, visit_mut::VisitMut, Error, FnArg, @@ -47,13 +47,6 @@ pub(crate) fn attribute(args: &TokenStream, mut input: ItemImpl) -> TokenStream } tokens } else { - input.attrs.push(parse_quote!(#[allow( - unused_qualifications, // https://github.com/rust-lang/rust/issues/122519 - // This lint warns of `clippy::*` generated by external macros. - // We allow this lint for compatibility with older compilers. - clippy::unknown_clippy_lints, - clippy::absolute_paths - )])); input.into_token_stream() } } @@ -191,7 +184,7 @@ fn expand_impl(item: &mut ItemImpl) { item.attrs.push(parse_quote!(#[doc(hidden)])); let path = &mut item.trait_.as_mut().expect("unexpected inherent impl").1; - *path = parse_quote_spanned! { path.span() => + *path = parse_quote_spanned! { Span::call_site().located_at(path.span()) => ::pin_project::__private::PinnedDrop }; @@ -204,7 +197,6 @@ fn expand_impl(item: &mut ItemImpl) { let ident = format_ident!("__drop_inner"); // Add a dummy `__drop_inner` function to prevent users call outer `__drop_inner`. drop_inner.block.stmts.insert(0, parse_quote!(fn #ident() {})); - drop_inner.attrs.push(parse_quote!(#[allow(clippy::single_call_fn)])); drop_inner.sig.ident = ident; drop_inner.sig.generics = item.generics.clone(); let receiver = drop_inner.sig.receiver().expect("drop() should have a receiver").clone(); @@ -238,7 +230,10 @@ fn expand_impl(item: &mut ItemImpl) { }; method.block.stmts = parse_quote! { - #[allow(clippy::needless_pass_by_value)] // This lint does not warn the receiver. + #[allow( + clippy::needless_pass_by_value, // This lint does not warn the receiver. + clippy::single_call_fn + )] #drop_inner __drop_inner(#self_token); }; diff --git a/tests/expand/pinned_drop/enum.expanded.rs b/tests/expand/pinned_drop/enum.expanded.rs index 045cbc8a..2e7ba5f5 100644 --- a/tests/expand/pinned_drop/enum.expanded.rs +++ b/tests/expand/pinned_drop/enum.expanded.rs @@ -169,11 +169,9 @@ const _: () = { } }; #[doc(hidden)] -#[allow(unused_qualifications, clippy::unknown_clippy_lints, clippy::absolute_paths)] impl ::pin_project::__private::PinnedDrop for Enum { unsafe fn drop(self: Pin<&mut Self>) { - #[allow(clippy::needless_pass_by_value)] - #[allow(clippy::single_call_fn)] + #[allow(clippy::needless_pass_by_value, clippy::single_call_fn)] fn __drop_inner(__self: Pin<&mut Enum>) { fn __drop_inner() {} let _ = __self; diff --git a/tests/expand/pinned_drop/struct.expanded.rs b/tests/expand/pinned_drop/struct.expanded.rs index 0aad355c..08486664 100644 --- a/tests/expand/pinned_drop/struct.expanded.rs +++ b/tests/expand/pinned_drop/struct.expanded.rs @@ -114,11 +114,9 @@ const _: () = { } }; #[doc(hidden)] -#[allow(unused_qualifications, clippy::unknown_clippy_lints, clippy::absolute_paths)] impl ::pin_project::__private::PinnedDrop for Struct { unsafe fn drop(self: Pin<&mut Self>) { - #[allow(clippy::needless_pass_by_value)] - #[allow(clippy::single_call_fn)] + #[allow(clippy::needless_pass_by_value, clippy::single_call_fn)] fn __drop_inner(__self: Pin<&mut Struct>) { fn __drop_inner() {} let _ = __self; diff --git a/tests/expand/pinned_drop/tuple_struct.expanded.rs b/tests/expand/pinned_drop/tuple_struct.expanded.rs index 064569db..8a362ba0 100644 --- a/tests/expand/pinned_drop/tuple_struct.expanded.rs +++ b/tests/expand/pinned_drop/tuple_struct.expanded.rs @@ -108,11 +108,9 @@ const _: () = { } }; #[doc(hidden)] -#[allow(unused_qualifications, clippy::unknown_clippy_lints, clippy::absolute_paths)] impl ::pin_project::__private::PinnedDrop for TupleStruct { unsafe fn drop(self: Pin<&mut Self>) { - #[allow(clippy::needless_pass_by_value)] - #[allow(clippy::single_call_fn)] + #[allow(clippy::needless_pass_by_value, clippy::single_call_fn)] fn __drop_inner(__self: Pin<&mut TupleStruct>) { fn __drop_inner() {} let _ = __self; diff --git a/tests/include/basic-safe-part.rs b/tests/include/basic-safe-part.rs index 0c453572..7f216f6e 100644 --- a/tests/include/basic-safe-part.rs +++ b/tests/include/basic-safe-part.rs @@ -80,6 +80,7 @@ pub struct PinnedDropStruct { #[::pin_project::pinned_drop] impl PinnedDrop for PinnedDropStruct { + #[allow(clippy::absolute_paths)] fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} } @@ -91,6 +92,7 @@ pub struct PinnedDropTupleStruct(#[pin] pub T, pub U); #[::pin_project::pinned_drop] impl PinnedDrop for PinnedDropTupleStruct { + #[allow(clippy::absolute_paths)] fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} } @@ -118,6 +120,7 @@ pub enum PinnedDropEnum { } #[::pin_project::pinned_drop] +#[allow(clippy::absolute_paths)] impl PinnedDrop for PinnedDropEnum { fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} } diff --git a/tests/ui/pinned_drop/conditional-drop-impl.stderr b/tests/ui/pinned_drop/conditional-drop-impl.stderr index 79aed3c9..e265663c 100644 --- a/tests/ui/pinned_drop/conditional-drop-impl.stderr +++ b/tests/ui/pinned_drop/conditional-drop-impl.stderr @@ -21,10 +21,13 @@ error[E0277]: `T` cannot be unpinned note: required for `PinnedDropImpl` to implement `PinnedDrop` --> tests/ui/pinned_drop/conditional-drop-impl.rs:25:16 | +24 | #[pinned_drop] + | -------------- in this procedural macro expansion 25 | impl PinnedDrop for PinnedDropImpl { | ----- ^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ | | | unsatisfied trait bound introduced here + = note: this error originates in the attribute macro `pinned_drop` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider restricting type parameter `T` with trait `Unpin` | 19 | struct PinnedDropImpl {