-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
READY: Attribute macros phantom
implementation
#1375
Changes from 5 commits
c3667ea
08342ad
aef100c
2dc8b98
be87175
59c53c9
bd599f6
bb5d681
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#[ test ] | ||
fn phantom_data() | ||
{ | ||
let _ = StructNamed::< bool >{ a : "boo".into(), b : 3, _phantom: Default::default() }; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#[ test ] | ||
fn phantom_data() | ||
{ | ||
let _ = StructTuple::< bool >( "boo".into(), 3, Default::default() ); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use super::*; | ||
|
||
#[ allow( dead_code ) ] | ||
#[ the_module::phantom_data ] | ||
struct StructNamed<T> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. codestyle |
||
{ | ||
a : String, | ||
b : i32, | ||
} | ||
|
||
include!("./only_test/struct_named.rs"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. codestyle |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use super::*; | ||
use std::marker::PhantomData; | ||
|
||
#[ allow( dead_code ) ] | ||
struct StructNamed<T> | ||
{ | ||
a : String, | ||
b : i32, | ||
_phantom : PhantomData<T>, | ||
} | ||
|
||
include!("./only_test/struct_named.rs"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use super::*; | ||
|
||
#[ allow( dead_code ) ] | ||
#[ the_module::phantom_data ] | ||
struct StructTuple< T >( String, i32 ); | ||
|
||
include!( "./only_test/struct_tuple.rs" ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use std::marker::PhantomData; | ||
use super::*; | ||
|
||
#[ allow( dead_code ) ] | ||
struct StructTuple< T >( String, i32, PhantomData< T > ); | ||
|
||
include!( "./only_test/struct_tuple.rs" ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use super::*; | ||
use macro_tools::{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. code style |
||
attr, | ||
diag, | ||
Result, | ||
phantom::add_to_item, | ||
quote::ToTokens, | ||
syn::ItemStruct, | ||
}; | ||
|
||
pub fn phantom_data( input : proc_macro::TokenStream ) -> Result<proc_macro2::TokenStream> | ||
{ | ||
let original_input = input.clone(); | ||
let parsed = syn::parse::< ItemStruct >( input )?; | ||
let has_debug = attr::has_debug( parsed.attrs.iter() )?; | ||
let item_name = &parsed.ident; | ||
|
||
let result = add_to_item( &parsed ).to_token_stream(); | ||
|
||
if has_debug | ||
{ | ||
let about = format!( "derive : PhantomData\nstructure : {item_name}" ); | ||
diag::report_print( about, &original_input, &result ); | ||
} | ||
|
||
Ok( result ) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code style