-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NOT READY: Attribute macros
phantom
implementation (#1375)
derive_tools : first implementation of derive_phantom
- Loading branch information
1 parent
6a1ee3c
commit 5f8ea59
Showing
12 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
module/core/derive_tools/tests/inc/phantom/only_test/struct_named.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#[ test ] | ||
fn phantom() | ||
{ | ||
let _ = StructNamed::< bool >{ a : "boo".into(), b : 3, _phantom: Default::default() }; | ||
} |
5 changes: 5 additions & 0 deletions
5
module/core/derive_tools/tests/inc/phantom/only_test/struct_tuple.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#[ test ] | ||
fn phantom() | ||
{ | ||
let _ = StructTuple::< bool >( "boo".into(), 3, Default::default() ); | ||
} |
11 changes: 11 additions & 0 deletions
11
module/core/derive_tools/tests/inc/phantom/struct_named.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use super::*; | ||
|
||
#[ allow( dead_code ) ] | ||
#[ the_module::phantom ] | ||
struct StructNamed< T > | ||
{ | ||
a : String, | ||
b : i32, | ||
} | ||
|
||
include!( "./only_test/struct_named.rs" ); |
12 changes: 12 additions & 0 deletions
12
module/core/derive_tools/tests/inc/phantom/struct_named_manual.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use super::*; | ||
|
||
#[ allow( dead_code ) ] | ||
#[ the_module::phantom ] | ||
struct StructTuple< T >( String, i32 ); | ||
|
||
include!( "./only_test/struct_tuple.rs" ); |
7 changes: 7 additions & 0 deletions
7
module/core/derive_tools/tests/inc/phantom/struct_tuple_manual.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use super::*; | ||
use macro_tools:: | ||
{ | ||
attr, | ||
diag, | ||
Result, | ||
phantom::add_to_item, | ||
quote::ToTokens, | ||
syn::ItemStruct, | ||
}; | ||
|
||
pub fn phantom( 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 ) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters