Skip to content

Commit

Permalink
Use located_at instead of fully allow clippy::absolute_paths
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Jan 6, 2025
1 parent 2fb3d56 commit 95ba2f4
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 20 deletions.
18 changes: 7 additions & 11 deletions pin-project-internal/src/pinned_drop.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -47,13 +47,7 @@ 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.attrs.push(parse_quote!(#[allow(unused_qualifications)])); // https://github.com/rust-lang/rust/issues/122519
input.into_token_stream()
}
}
Expand Down Expand Up @@ -191,7 +185,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
};

Expand All @@ -204,7 +198,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();
Expand Down Expand Up @@ -238,7 +231,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);
};
Expand Down
5 changes: 2 additions & 3 deletions tests/expand/pinned_drop/enum.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,10 @@ const _: () = {
}
};
#[doc(hidden)]
#[allow(unused_qualifications, clippy::unknown_clippy_lints, clippy::absolute_paths)]
#[allow(unused_qualifications)]
impl<T, U> ::pin_project::__private::PinnedDrop for Enum<T, U> {
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<T, U>(__self: Pin<&mut Enum<T, U>>) {
fn __drop_inner() {}
let _ = __self;
Expand Down
5 changes: 2 additions & 3 deletions tests/expand/pinned_drop/struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,10 @@ const _: () = {
}
};
#[doc(hidden)]
#[allow(unused_qualifications, clippy::unknown_clippy_lints, clippy::absolute_paths)]
#[allow(unused_qualifications)]
impl<T, U> ::pin_project::__private::PinnedDrop for Struct<T, U> {
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<T, U>(__self: Pin<&mut Struct<T, U>>) {
fn __drop_inner() {}
let _ = __self;
Expand Down
5 changes: 2 additions & 3 deletions tests/expand/pinned_drop/tuple_struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,10 @@ const _: () = {
}
};
#[doc(hidden)]
#[allow(unused_qualifications, clippy::unknown_clippy_lints, clippy::absolute_paths)]
#[allow(unused_qualifications)]
impl<T, U> ::pin_project::__private::PinnedDrop for TupleStruct<T, U> {
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<T, U>(__self: Pin<&mut TupleStruct<T, U>>) {
fn __drop_inner() {}
let _ = __self;
Expand Down
3 changes: 3 additions & 0 deletions tests/include/basic-safe-part.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ pub struct PinnedDropStruct<T, U> {

#[::pin_project::pinned_drop]
impl<T, U> PinnedDrop for PinnedDropStruct<T, U> {
#[allow(clippy::absolute_paths)]
fn drop(self: ::pin_project::__private::Pin<&mut Self>) {}
}

Expand All @@ -91,6 +92,7 @@ pub struct PinnedDropTupleStruct<T, U>(#[pin] pub T, pub U);

#[::pin_project::pinned_drop]
impl<T, U> PinnedDrop for PinnedDropTupleStruct<T, U> {
#[allow(clippy::absolute_paths)]
fn drop(self: ::pin_project::__private::Pin<&mut Self>) {}
}

Expand Down Expand Up @@ -118,6 +120,7 @@ pub enum PinnedDropEnum<T: ::pin_project::__private::Unpin, U> {
}

#[::pin_project::pinned_drop]
#[allow(clippy::absolute_paths)]
impl<T: ::pin_project::__private::Unpin, U> PinnedDrop for PinnedDropEnum<T, U> {
fn drop(self: ::pin_project::__private::Pin<&mut Self>) {}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/pinned_drop/conditional-drop-impl.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ error[E0277]: `T` cannot be unpinned
note: required for `PinnedDropImpl<T>` to implement `PinnedDrop`
--> tests/ui/pinned_drop/conditional-drop-impl.rs:25:16
|
24 | #[pinned_drop]
| -------------- in this procedural macro expansion
25 | impl<T: Unpin> PinnedDrop for PinnedDropImpl<T> {
| ----- ^^^^^^^^^^ ^^^^^^^^^^^^^^^^^
| |
| 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<T: std::marker::Unpin> {
Expand Down

0 comments on commit 95ba2f4

Please sign in to comment.