Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ trybuild = { version = "1.0", features = ["diff"] }
macrotest = "1.0"
# needed for macrotest, have to enable verbatim feature to be able to format `&raw` expressions.
prettyplease = { version = "0.2", features = ["verbatim"] }
test_dummy_only = { path = "./test_dummy_only" }

[lints.rust]
non_ascii_idents = "deny"
Expand Down
16 changes: 13 additions & 3 deletions internal/src/pin_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ fn generate_unpin_impl(
.cloned()
.collect::<Vec<_>>();
for field in &mut pinned_fields {
field.attrs.retain(|a| !a.path().is_ident("pin"));
field.attrs.retain(keep_attr);
}
quote! {
// This struct will be used for the unpin analysis. It is needed, because only structurally
Expand Down Expand Up @@ -267,7 +267,7 @@ fn generate_projections(
..
}| {
let mut attrs = attrs.clone();
attrs.retain(|a| !a.path().is_ident("pin"));
attrs.retain(keep_attr);
let mut no_doc_attrs = attrs.clone();
no_doc_attrs.retain(|a| !a.path().is_ident("doc"));
let ident = ident
Expand Down Expand Up @@ -348,6 +348,16 @@ fn generate_projections(
}
}

fn keep_attr(attr: &syn::Attribute) -> bool {
let path = attr.path();

if path.is_ident("pin") {
return false;
}

path.is_ident("doc") || path.is_ident("cfg")
}

fn generate_the_pin_data(
ItemStruct {
generics,
Expand Down Expand Up @@ -376,7 +386,7 @@ fn generate_the_pin_data(
pinned: bool,
) -> TokenStream {
let mut attrs = attrs.clone();
attrs.retain(|a| !a.path().is_ident("pin"));
attrs.retain(keep_attr);
let ident = ident
.as_ref()
.expect("only structs with named fields are supported");
Expand Down
7 changes: 7 additions & 0 deletions test_dummy_only/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions test_dummy_only/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "test_dummy_only"
version = "0.0.1"
edition = "2021"

authors = ["y86-dev"]
license = "MIT OR Apache-2.0"
description = "Proc macro only for test reproduction."

publish = false

[lib]
proc-macro = true
4 changes: 4 additions & 0 deletions test_dummy_only/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[proc_macro_derive(Dummy, attributes(dummy_attr))]
pub fn derive_device(_: proc_macro::TokenStream) -> proc_macro::TokenStream {
proc_macro::TokenStream::new()
}
23 changes: 23 additions & 0 deletions tests/extra_attrs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))]

use pin_init::*;
use test_dummy_only::Dummy;

#[pin_data]
#[derive(Dummy)]
struct Pointless {
#[pin]
#[dummy_attr]
#[cfg(test)]
member: i8,
#[pin]
#[dummy_attr]
#[cfg(not(test))]
member: u8,
}

#[test]
fn multiple_attributes() {
stack_pin_init!(let p = init!(Pointless { member: 0 }));
println!("{}", p.member);
}
Loading