-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new top-level attribute `scale_info(bounds(T: SomeTrait + OtherTr…
…ait))` (#88) * Add new top-level attribute `scale_info(bounds(T: SomeTrait + OtherTrait))` * Fmt * cleanup * Run pass tests as wildcard * Add ui pass test for fixing custom bounds overflow * Fmt * Move custom bounds test to ui test * Satisfy clippy * Fix UI test Co-authored-by: Andrew Jones <[email protected]>
- Loading branch information
Showing
6 changed files
with
157 additions
and
46 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
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,25 @@ | ||
use scale_info::TypeInfo; | ||
use core::marker::PhantomData; | ||
|
||
#[allow(unused)] | ||
#[derive(TypeInfo)] | ||
#[scale_info(bounds(T: Default + TypeInfo + 'static, N: TypeInfo + 'static))] | ||
struct Hey<T, N> { | ||
ciao: Greet<T>, | ||
ho: N, | ||
} | ||
|
||
#[derive(TypeInfo)] | ||
#[scale_info(bounds(T: TypeInfo + 'static))] | ||
struct Greet<T> { | ||
marker: PhantomData<T>, | ||
} | ||
|
||
#[derive(TypeInfo, Default)] | ||
struct SomeType; | ||
|
||
fn assert_type_info<T: TypeInfo + 'static>() {} | ||
|
||
fn main() { | ||
assert_type_info::<Hey<SomeType, u16>>(); | ||
} |
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,22 @@ | ||
use scale_info::TypeInfo; | ||
|
||
#[allow(unused)] | ||
#[derive(TypeInfo)] | ||
// Without this we get `overflow evaluating the requirement `Vec<B<()>>: TypeInfo``. | ||
// The custom bounds replace the auto generated bounds. | ||
#[scale_info(bounds(T: TypeInfo + 'static))] | ||
struct A<T> { | ||
a: Vec<B<T>>, | ||
b: Vec<B<()>>, | ||
marker: core::marker::PhantomData<T>, | ||
} | ||
|
||
#[allow(unused)] | ||
#[derive(TypeInfo)] | ||
struct B<T>(A<T>); | ||
|
||
fn assert_type_info<T: TypeInfo + 'static>() {} | ||
|
||
fn main() { | ||
assert_type_info::<A<bool>>(); | ||
} |