mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 21:37:56 +00:00
update DefaultNoBound derive macro (#12723)
fix derive for empty enums Update derive & ui tests clean up Apply suggestions from code review Co-authored-by: Bastian Köcher <git@kchr.de> rename variable formatting & clippy formatting Co-authored-by: parity-processbot <>
This commit is contained in:
@@ -110,10 +110,33 @@ fn test_struct_unnamed() {
|
||||
assert!(b != a_1);
|
||||
}
|
||||
|
||||
#[derive(DebugNoBound, CloneNoBound, EqNoBound, PartialEqNoBound, DefaultNoBound)]
|
||||
struct StructNoGenerics {
|
||||
field1: u32,
|
||||
field2: u64,
|
||||
}
|
||||
|
||||
#[derive(DebugNoBound, CloneNoBound, EqNoBound, PartialEqNoBound, DefaultNoBound)]
|
||||
enum EnumNoGenerics {
|
||||
#[default]
|
||||
VariantUnnamed(u32, u64),
|
||||
VariantNamed {
|
||||
a: u32,
|
||||
b: u64,
|
||||
},
|
||||
VariantUnit,
|
||||
}
|
||||
|
||||
#[derive(DebugNoBound, CloneNoBound, EqNoBound, PartialEqNoBound, DefaultNoBound)]
|
||||
enum Enum<T: Config, U, V> {
|
||||
#[default]
|
||||
VariantUnnamed(u32, u64, T::C, core::marker::PhantomData<(U, V)>),
|
||||
VariantNamed { a: u32, b: u64, c: T::C, phantom: core::marker::PhantomData<(U, V)> },
|
||||
VariantNamed {
|
||||
a: u32,
|
||||
b: u64,
|
||||
c: T::C,
|
||||
phantom: core::marker::PhantomData<(U, V)>,
|
||||
},
|
||||
VariantUnit,
|
||||
VariantUnit2,
|
||||
}
|
||||
@@ -121,7 +144,12 @@ enum Enum<T: Config, U, V> {
|
||||
// enum that will have a named default.
|
||||
#[derive(DebugNoBound, CloneNoBound, EqNoBound, PartialEqNoBound, DefaultNoBound)]
|
||||
enum Enum2<T: Config> {
|
||||
VariantNamed { a: u32, b: u64, c: T::C },
|
||||
#[default]
|
||||
VariantNamed {
|
||||
a: u32,
|
||||
b: u64,
|
||||
c: T::C,
|
||||
},
|
||||
VariantUnnamed(u32, u64, T::C),
|
||||
VariantUnit,
|
||||
VariantUnit2,
|
||||
@@ -130,8 +158,13 @@ enum Enum2<T: Config> {
|
||||
// enum that will have a unit default.
|
||||
#[derive(DebugNoBound, CloneNoBound, EqNoBound, PartialEqNoBound, DefaultNoBound)]
|
||||
enum Enum3<T: Config> {
|
||||
#[default]
|
||||
VariantUnit,
|
||||
VariantNamed { a: u32, b: u64, c: T::C },
|
||||
VariantNamed {
|
||||
a: u32,
|
||||
b: u64,
|
||||
c: T::C,
|
||||
},
|
||||
VariantUnnamed(u32, u64, T::C),
|
||||
VariantUnit2,
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
#[derive(frame_support::DefaultNoBound)]
|
||||
enum Empty {}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: cannot derive Default for an empty enum
|
||||
--> tests/derive_no_bound_ui/default_empty_enum.rs:2:6
|
||||
|
|
||||
2 | enum Empty {}
|
||||
| ^^^^^
|
||||
@@ -0,0 +1,11 @@
|
||||
trait Config {
|
||||
type C;
|
||||
}
|
||||
|
||||
#[derive(frame_support::DefaultNoBound)]
|
||||
enum Foo<T: Config> {
|
||||
Bar(T::C),
|
||||
Baz,
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: no default declared, make a variant default by placing `#[default]` above it
|
||||
--> tests/derive_no_bound_ui/default_no_attribute.rs:6:6
|
||||
|
|
||||
6 | enum Foo<T: Config> {
|
||||
| ^^^
|
||||
@@ -0,0 +1,13 @@
|
||||
trait Config {
|
||||
type C;
|
||||
}
|
||||
|
||||
#[derive(frame_support::DefaultNoBound)]
|
||||
enum Foo<T: Config> {
|
||||
#[default]
|
||||
Bar(T::C),
|
||||
#[default]
|
||||
Baz,
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
error: multiple declared defaults
|
||||
--> tests/derive_no_bound_ui/default_too_many_attributes.rs:5:10
|
||||
|
|
||||
5 | #[derive(frame_support::DefaultNoBound)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this error originates in the derive macro `frame_support::DefaultNoBound` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: first default
|
||||
--> tests/derive_no_bound_ui/default_too_many_attributes.rs:7:2
|
||||
|
|
||||
7 | / #[default]
|
||||
8 | | Bar(T::C),
|
||||
| |_____________^
|
||||
|
||||
error: additional default
|
||||
--> tests/derive_no_bound_ui/default_too_many_attributes.rs:9:2
|
||||
|
|
||||
9 | / #[default]
|
||||
10 | | Baz,
|
||||
| |_______^
|
||||
@@ -0,0 +1,7 @@
|
||||
#[derive(frame_support::DefaultNoBound)]
|
||||
union Foo {
|
||||
field1: u32,
|
||||
field2: (),
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: Union type not supported by `derive(DefaultNoBound)`
|
||||
--> tests/derive_no_bound_ui/default_union.rs:2:1
|
||||
|
|
||||
2 | union Foo {
|
||||
| ^^^^^
|
||||
Reference in New Issue
Block a user