-
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.
READY: Extend
phantom
macros (#1381)
get completed phantom derive
- Loading branch information
1 parent
fded466
commit d5c2499
Showing
42 changed files
with
467 additions
and
17 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
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,8 @@ | ||
use std::fmt::Debug; | ||
use super::*; | ||
|
||
#[ allow( dead_code ) ] | ||
#[ the_module::phantom ] | ||
struct BoundsInlined< T: ToString, U: Debug > {} | ||
|
||
include!( "./only_test/bounds_inlined.rs" ); |
13 changes: 13 additions & 0 deletions
13
module/core/derive_tools/tests/inc/phantom/bounds_inlined_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,13 @@ | ||
use std:: | ||
{ | ||
fmt::Debug, | ||
marker::PhantomData, | ||
}; | ||
|
||
#[ allow( dead_code ) ] | ||
struct BoundsInlined< T: ToString, U: Debug > | ||
{ | ||
_phantom: PhantomData< ( T, U ) >, | ||
} | ||
|
||
include!( "./only_test/bounds_inlined.rs" ); |
11 changes: 11 additions & 0 deletions
11
module/core/derive_tools/tests/inc/phantom/bounds_mixed.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 std::fmt::Debug; | ||
use super::*; | ||
|
||
#[ allow( dead_code ) ] | ||
#[ the_module::phantom ] | ||
struct BoundsMixed< T: ToString, U > | ||
where | ||
U: Debug, | ||
{} | ||
|
||
include!( "./only_test/bounds_mixed.rs" ); |
15 changes: 15 additions & 0 deletions
15
module/core/derive_tools/tests/inc/phantom/bounds_mixed_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,15 @@ | ||
use std:: | ||
{ | ||
fmt::Debug, | ||
marker::PhantomData, | ||
}; | ||
|
||
#[ allow( dead_code ) ] | ||
struct BoundsMixed< T: ToString, U > | ||
where | ||
U: Debug, | ||
{ | ||
_phantom: PhantomData< ( T, U ) >, | ||
} | ||
|
||
include!( "./only_test/bounds_mixed.rs" ); |
12 changes: 12 additions & 0 deletions
12
module/core/derive_tools/tests/inc/phantom/bounds_where.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 std::fmt::Debug; | ||
use super::*; | ||
|
||
#[ allow( dead_code ) ] | ||
#[ the_module::phantom ] | ||
struct BoundsWhere< T, U > | ||
where | ||
T: ToString, | ||
U: Debug, | ||
{} | ||
|
||
include!( "./only_test/bounds_where.rs" ); |
16 changes: 16 additions & 0 deletions
16
module/core/derive_tools/tests/inc/phantom/bounds_where_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,16 @@ | ||
use std:: | ||
{ | ||
fmt::Debug, | ||
marker::PhantomData, | ||
}; | ||
|
||
#[ allow( dead_code ) ] | ||
struct BoundsWhere< T, U > | ||
where | ||
T: ToString, | ||
U: Debug, | ||
{ | ||
_phantom: PhantomData< ( T, U ) > | ||
} | ||
|
||
include!( "./only_test/bounds_where.rs" ); |
13 changes: 13 additions & 0 deletions
13
module/core/derive_tools/tests/inc/phantom/compiletime/enum.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,13 @@ | ||
use derive_tools_meta::phantom; | ||
|
||
#[ phantom ] | ||
enum Enum< T > | ||
{ | ||
A, | ||
B, | ||
C( T ), | ||
} | ||
|
||
fn main() | ||
{ | ||
} |
5 changes: 5 additions & 0 deletions
5
module/core/derive_tools/tests/inc/phantom/compiletime/enum.stderr
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 @@ | ||
error: expected `struct` | ||
--> tests/inc/phantom/compiletime/enum.rs:4:1 | ||
| | ||
4 | enum Enum< T > | ||
| ^^^^ |
18 changes: 18 additions & 0 deletions
18
module/core/derive_tools/tests/inc/phantom/compiletime/invariant_type.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,18 @@ | ||
use derive_tools_meta::phantom; | ||
|
||
#[ phantom ] | ||
struct InvariantType< T > | ||
{ | ||
a: T, | ||
} | ||
|
||
fn assert_invariant< 'a >( x: InvariantType< *mut &'static str > ) -> InvariantType< *mut &'a str > | ||
{ | ||
x | ||
} | ||
|
||
fn main() | ||
{ | ||
let x: InvariantType< *mut &'static str > = InvariantType { a: &mut "boo", _phantom: Default::default() }; | ||
let _: InvariantType< *mut &str > = assert_invariant( x ); | ||
} |
12 changes: 12 additions & 0 deletions
12
module/core/derive_tools/tests/inc/phantom/compiletime/invariant_type.stderr
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 @@ | ||
error: lifetime may not live long enough | ||
--> tests/inc/phantom/compiletime/invariant_type.rs:11:3 | ||
| | ||
9 | fn assert_invariant< 'a >( x: InvariantType< *mut &'static str > ) -> InvariantType< *mut &'a str > | ||
| -- lifetime `'a` defined here | ||
10 | { | ||
11 | x | ||
| ^ returning this value requires that `'a` must outlive `'static` | ||
| | ||
= note: requirement occurs because of a mutable pointer to `&str` | ||
= note: mutable pointers are invariant over their type parameter | ||
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance |
10 changes: 10 additions & 0 deletions
10
module/core/derive_tools/tests/inc/phantom/contravariant_type.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,10 @@ | ||
use super::*; | ||
|
||
#[ allow( dead_code ) ] | ||
#[ the_module::phantom ] | ||
struct ContravariantType< T > | ||
{ | ||
a: T, | ||
} | ||
|
||
include!( "./only_test/contravariant_type.rs" ); |
10 changes: 10 additions & 0 deletions
10
module/core/derive_tools/tests/inc/phantom/contravariant_type_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,10 @@ | ||
use std::marker::PhantomData; | ||
|
||
#[ allow( dead_code ) ] | ||
struct ContravariantType< T > | ||
{ | ||
a: T, | ||
_phantom: PhantomData< T >, | ||
} | ||
|
||
include!( "./only_test/contravariant_type.rs" ); |
10 changes: 10 additions & 0 deletions
10
module/core/derive_tools/tests/inc/phantom/covariant_type.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,10 @@ | ||
use super::*; | ||
|
||
#[ allow( dead_code ) ] | ||
#[ the_module::phantom ] | ||
struct CovariantType< T > | ||
{ | ||
a: T, | ||
} | ||
|
||
include!( "./only_test/covariant_type.rs" ); |
10 changes: 10 additions & 0 deletions
10
module/core/derive_tools/tests/inc/phantom/covariant_type_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,10 @@ | ||
use std::marker::PhantomData; | ||
|
||
#[ allow( dead_code ) ] | ||
struct CovariantType< T > | ||
{ | ||
a: T, | ||
_phantom: PhantomData< T >, | ||
} | ||
|
||
include!( "./only_test/covariant_type.rs" ); |
15 changes: 15 additions & 0 deletions
15
module/core/derive_tools/tests/inc/phantom/name_collisions.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,15 @@ | ||
use super::*; | ||
|
||
pub mod std {} | ||
pub mod core {} | ||
pub mod marker {} | ||
|
||
#[ allow( dead_code ) ] | ||
#[ the_module::phantom ] | ||
struct NameCollisions< T > | ||
{ | ||
a : String, | ||
b : i32, | ||
} | ||
|
||
include!( "./only_test/name_collisions.rs" ); |
5 changes: 5 additions & 0 deletions
5
module/core/derive_tools/tests/inc/phantom/only_test/bounds_inlined.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 _ = BoundsInlined::< String, i32 > { _phantom: Default::default() }; | ||
} |
5 changes: 5 additions & 0 deletions
5
module/core/derive_tools/tests/inc/phantom/only_test/bounds_mixed.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 _ = BoundsMixed::< String, i32 > { _phantom: Default::default() }; | ||
} |
5 changes: 5 additions & 0 deletions
5
module/core/derive_tools/tests/inc/phantom/only_test/bounds_where.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 _ = BoundsWhere::< String, i32 > { _phantom: Default::default() }; | ||
} |
18 changes: 18 additions & 0 deletions
18
module/core/derive_tools/tests/inc/phantom/only_test/contravariant_type.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,18 @@ | ||
fn assert_contravariant( x: ContravariantType< &dyn Fn( &'static str ) -> String > ) -> String | ||
{ | ||
( x.a )( "test" ) | ||
} | ||
|
||
#[test] | ||
fn contravariant() | ||
{ | ||
let x_fn: &dyn for< 'a > Fn( &'a str ) -> String = &| s: &str | | ||
{ | ||
format!( "x_fn: {s}" ) | ||
}; | ||
|
||
let x: ContravariantType< &dyn for< 'a > Fn( &'a str ) -> String > = ContravariantType { a: x_fn, _phantom: Default::default() }; | ||
let value = assert_contravariant(x); | ||
|
||
assert_eq!( value, String::from( "x_fn: test" ) ); | ||
} |
12 changes: 12 additions & 0 deletions
12
module/core/derive_tools/tests/inc/phantom/only_test/covariant_type.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 @@ | ||
fn assert_covariant< 'a >( x: CovariantType< &'static str > ) -> CovariantType< &'a str > | ||
{ | ||
x | ||
} | ||
|
||
#[ test ] | ||
fn covariant() | ||
{ | ||
let x: CovariantType< &'static str > = CovariantType { a: "boo", _phantom: Default::default(), }; | ||
let y: CovariantType< &str > = assert_covariant( x ); | ||
assert_eq!( y.a, "boo" ); | ||
} |
5 changes: 5 additions & 0 deletions
5
module/core/derive_tools/tests/inc/phantom/only_test/name_collisions.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 _ = NameCollisions::< bool > { a : "boo".into(), b : 3, _phantom: Default::default() }; | ||
} |
9 changes: 9 additions & 0 deletions
9
module/core/derive_tools/tests/inc/phantom/only_test/send_sync_type.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,9 @@ | ||
fn assert_send_sync< T: Send + Sync >( _x: SendSyncType< T > ) | ||
{} | ||
|
||
#[ test ] | ||
fn phantom() | ||
{ | ||
let x: SendSyncType::< bool > = SendSyncType { a: true, _phantom: Default::default() }; | ||
assert_send_sync( x ); | ||
} |
2 changes: 1 addition & 1 deletion
2
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#[ test ] | ||
fn phantom() | ||
{ | ||
let _ = StructNamed::< bool >{ a : "boo".into(), b : 3, _phantom: Default::default() }; | ||
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_named_empty.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 _ = StructNamedEmpty::< bool > { _phantom: Default::default() }; | ||
} |
5 changes: 5 additions & 0 deletions
5
module/core/derive_tools/tests/inc/phantom/only_test/struct_tuple_empty.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 _ = StructTupleEmpty::< bool >( Default::default() ); | ||
} |
5 changes: 5 additions & 0 deletions
5
module/core/derive_tools/tests/inc/phantom/only_test/struct_unit_to_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 _ = StructUnit::< bool >( Default::default() ); | ||
} |
Oops, something went wrong.