Skip to content

Commit

Permalink
Merge #250
Browse files Browse the repository at this point in the history
250: Preserve the span of self argument r=taiki-e a=taiki-e

Refs: dtolnay/async-trait#105

`#[pinned_drop]` attribute also has same issue.

Co-authored-by: Taiki Endo <[email protected]>
  • Loading branch information
bors[bot] and taiki-e authored Jun 8, 2020
2 parents 6c28e64 + bd7ad83 commit 3572be7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pin-project-internal/src/pinned_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,18 @@ fn expand_item(item: &mut ItemImpl) {

// `fn drop(mut self: Pin<&mut Self>)` -> `unsafe fn drop(self: Pin<&mut Self>)`
method.sig.unsafety = Some(token::Unsafe::default());
let mut self_token = None;
if let FnArg::Typed(arg) = &mut method.sig.inputs[0] {
if let Pat::Ident(ident) = &mut *arg.pat {
ident.mutability = None;
self_token = Some(&ident.ident);
}
}
debug_assert!(self_token.is_some());

method.block.stmts = syn::parse_quote! {
#[allow(clippy::needless_pass_by_value)] // This lint does not warn the receiver.
#drop_inner
__drop_inner(self);
__drop_inner(#self_token);
};
}
22 changes: 22 additions & 0 deletions tests/pinned_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,25 @@ fn self_inside_macro() {
}
}
}

#[test]
fn inside_macro() {
use pin_project::{pin_project, pinned_drop};
use std::pin::Pin;

#[pin_project(PinnedDrop)]
struct Struct(());

macro_rules! mac {
($expr:expr) => {
#[pinned_drop]
impl PinnedDrop for Struct {
fn drop(self: Pin<&mut Self>) {
$expr;
}
}
};
}

mac!(1);
}

0 comments on commit 3572be7

Please sign in to comment.