Unverified Commit 9bab4838 authored by Robin Freyler's avatar Robin Freyler Committed by GitHub
Browse files

Improve SpreadLayout and StorageLayout derive macro hygiene (#926)

* miscellaneous improvements to macro hygiene in derive macros

* fix storage_derive UI tests
parent c9a97bbe
Pipeline #158181 passed with stages
in 31 minutes and 17 seconds
...@@ -31,7 +31,7 @@ fn max_n(args: &[TokenStream2]) -> TokenStream2 { ...@@ -31,7 +31,7 @@ fn max_n(args: &[TokenStream2]) -> TokenStream2 {
Some((head, rest)) => { Some((head, rest)) => {
let rest = max_n(rest); let rest = max_n(rest);
quote! { quote! {
[#head, #rest][(#head < #rest) as usize] [#head, #rest][(#head < #rest) as ::core::primitive::usize]
} }
} }
None => quote! { 0u64 }, None => quote! { 0u64 },
...@@ -103,8 +103,8 @@ fn spread_layout_struct_derive(s: &synstructure::Structure) -> TokenStream2 { ...@@ -103,8 +103,8 @@ fn spread_layout_struct_derive(s: &synstructure::Structure) -> TokenStream2 {
s.gen_impl(quote! { s.gen_impl(quote! {
gen impl ::ink_storage::traits::SpreadLayout for @Self { gen impl ::ink_storage::traits::SpreadLayout for @Self {
#[allow(unused_comparisons)] #[allow(unused_comparisons)]
const FOOTPRINT: u64 = #footprint_body; const FOOTPRINT: ::core::primitive::u64 = #footprint_body;
const REQUIRES_DEEP_CLEAN_UP: bool = #requires_deep_clean_up_body; const REQUIRES_DEEP_CLEAN_UP: ::core::primitive::bool = #requires_deep_clean_up_body;
fn pull_spread(__key_ptr: &mut ::ink_storage::traits::KeyPtr) -> Self { fn pull_spread(__key_ptr: &mut ::ink_storage::traits::KeyPtr) -> Self {
#pull_body #pull_body
...@@ -154,7 +154,7 @@ fn spread_layout_enum_derive(s: &synstructure::Structure) -> TokenStream2 { ...@@ -154,7 +154,7 @@ fn spread_layout_enum_derive(s: &synstructure::Structure) -> TokenStream2 {
}); });
quote! { quote! {
#pat => { #pat => {
{ <u8 as ::ink_storage::traits::SpreadLayout>::push_spread(&#index, __key_ptr); } { <::core::primitive::u8 as ::ink_storage::traits::SpreadLayout>::push_spread(&#index, __key_ptr); }
#( #(
{ #fields } { #fields }
)* )*
...@@ -169,12 +169,12 @@ fn spread_layout_enum_derive(s: &synstructure::Structure) -> TokenStream2 { ...@@ -169,12 +169,12 @@ fn spread_layout_enum_derive(s: &synstructure::Structure) -> TokenStream2 {
s.gen_impl(quote! { s.gen_impl(quote! {
gen impl ::ink_storage::traits::SpreadLayout for @Self { gen impl ::ink_storage::traits::SpreadLayout for @Self {
#[allow(unused_comparisons)] #[allow(unused_comparisons)]
const FOOTPRINT: u64 = 1 + #footprint_body; const FOOTPRINT: ::core::primitive::u64 = 1 + #footprint_body;
const REQUIRES_DEEP_CLEAN_UP: bool = #requires_deep_clean_up_body; const REQUIRES_DEEP_CLEAN_UP: ::core::primitive::bool = #requires_deep_clean_up_body;
fn pull_spread(__key_ptr: &mut ::ink_storage::traits::KeyPtr) -> Self { fn pull_spread(__key_ptr: &mut ::ink_storage::traits::KeyPtr) -> Self {
match <u8 as ::ink_storage::traits::SpreadLayout>::pull_spread(__key_ptr) { match <::core::primitive::u8 as ::ink_storage::traits::SpreadLayout>::pull_spread(__key_ptr) {
#pull_body #pull_body
_ => unreachable!("encountered invalid enum discriminant"), _ => unreachable!("encountered invalid enum discriminant"),
} }
......
...@@ -22,9 +22,9 @@ fn field_layout<'a>( ...@@ -22,9 +22,9 @@ fn field_layout<'a>(
let ident = match field.ident.as_ref() { let ident = match field.ident.as_ref() {
Some(ident) => { Some(ident) => {
let ident_str = ident.to_string(); let ident_str = ident.to_string();
quote! { Some(#ident_str) } quote! { ::core::option::Option::Some(#ident_str) }
} }
None => quote! { None }, None => quote! { ::core::option::Option::None },
}; };
let ty = &field.ty; let ty = &field.ty;
quote! { quote! {
......
...@@ -32,9 +32,9 @@ fn unit_struct_works() { ...@@ -32,9 +32,9 @@ fn unit_struct_works() {
const _: () = { const _: () = {
impl ::ink_storage::traits::SpreadLayout for UnitStruct { impl ::ink_storage::traits::SpreadLayout for UnitStruct {
#[allow(unused_comparisons)] #[allow(unused_comparisons)]
const FOOTPRINT: u64 = [0u64, 0u64][(0u64 < 0u64) as usize]; const FOOTPRINT: ::core::primitive::u64 = [0u64, 0u64][(0u64 < 0u64) as ::core::primitive::usize];
const REQUIRES_DEEP_CLEAN_UP : bool = (false || false ); const REQUIRES_DEEP_CLEAN_UP : ::core::primitive::bool = (false || false );
fn pull_spread(__key_ptr: &mut ::ink_storage::traits::KeyPtr) -> Self { fn pull_spread(__key_ptr: &mut ::ink_storage::traits::KeyPtr) -> Self {
UnitStruct UnitStruct
...@@ -71,7 +71,7 @@ fn struct_works() { ...@@ -71,7 +71,7 @@ fn struct_works() {
const _: () = { const _: () = {
impl ::ink_storage::traits::SpreadLayout for NamedFields { impl ::ink_storage::traits::SpreadLayout for NamedFields {
#[allow(unused_comparisons)] #[allow(unused_comparisons)]
const FOOTPRINT: u64 = [ const FOOTPRINT: ::core::primitive::u64 = [
(((0u64 + <i32 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT) (((0u64 + <i32 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
+ <[u8; 32] as ::ink_storage::traits::SpreadLayout>::FOOTPRINT) + <[u8; 32] as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
+ <Box<i32> as ::ink_storage::traits::SpreadLayout>::FOOTPRINT), + <Box<i32> as ::ink_storage::traits::SpreadLayout>::FOOTPRINT),
...@@ -80,10 +80,10 @@ fn struct_works() { ...@@ -80,10 +80,10 @@ fn struct_works() {
+ <i32 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT) + <i32 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
+ <[u8; 32] as ::ink_storage::traits::SpreadLayout>::FOOTPRINT) + <[u8; 32] as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
+ <Box<i32> as ::ink_storage::traits::SpreadLayout>::FOOTPRINT) + <Box<i32> as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
< 0u64) as usize < 0u64) as ::core::primitive::usize
]; ];
const REQUIRES_DEEP_CLEAN_UP : bool = ( const REQUIRES_DEEP_CLEAN_UP : ::core::primitive::bool = (
false || ( false || (
( (
( (
...@@ -181,7 +181,7 @@ fn enum_works() { ...@@ -181,7 +181,7 @@ fn enum_works() {
const _: () = { const _: () = {
impl ::ink_storage::traits::SpreadLayout for MixedEnum { impl ::ink_storage::traits::SpreadLayout for MixedEnum {
#[allow(unused_comparisons)] #[allow(unused_comparisons)]
const FOOTPRINT : u64 = 1 + [ const FOOTPRINT : ::core::primitive::u64 = 1 + [
0u64 , 0u64 ,
[ [
( (
...@@ -211,7 +211,7 @@ fn enum_works() { ...@@ -211,7 +211,7 @@ fn enum_works() {
+ <(bool, i32) as ::ink_storage::traits::SpreadLayout>::FOOTPRINT + <(bool, i32) as ::ink_storage::traits::SpreadLayout>::FOOTPRINT
) )
< 0u64 < 0u64
) as usize ) as ::core::primitive::usize
] ]
][ ][
( (
...@@ -241,9 +241,9 @@ fn enum_works() { ...@@ -241,9 +241,9 @@ fn enum_works() {
+ <(bool, i32) as ::ink_storage::traits::SpreadLayout>::FOOTPRINT + <(bool, i32) as ::ink_storage::traits::SpreadLayout>::FOOTPRINT
) )
< 0u64 < 0u64
) as usize ) as ::core::primitive::usize
] ]
) as usize ) as ::core::primitive::usize
] ]
][ ][
( (
...@@ -274,7 +274,7 @@ fn enum_works() { ...@@ -274,7 +274,7 @@ fn enum_works() {
+ <(bool, i32) as ::ink_storage::traits::SpreadLayout>::FOOTPRINT + <(bool, i32) as ::ink_storage::traits::SpreadLayout>::FOOTPRINT
) )
< 0u64 < 0u64
) as usize ) as ::core::primitive::usize
] ]
][ ][
( (
...@@ -304,14 +304,14 @@ fn enum_works() { ...@@ -304,14 +304,14 @@ fn enum_works() {
+ <(bool, i32) as ::ink_storage::traits::SpreadLayout>::FOOTPRINT + <(bool, i32) as ::ink_storage::traits::SpreadLayout>::FOOTPRINT
) )
< 0u64 < 0u64
) as usize ) as ::core::primitive::usize
] ]
) as usize ) as ::core::primitive::usize
] ]
) as usize ) as ::core::primitive::usize
]; ];
const REQUIRES_DEEP_CLEAN_UP : bool = ( const REQUIRES_DEEP_CLEAN_UP : ::core::primitive::bool = (
( (
(false || false) (false || false)
|| ( || (
...@@ -332,7 +332,7 @@ fn enum_works() { ...@@ -332,7 +332,7 @@ fn enum_works() {
); );
fn pull_spread(__key_ptr: &mut ::ink_storage::traits::KeyPtr) -> Self { fn pull_spread(__key_ptr: &mut ::ink_storage::traits::KeyPtr) -> Self {
match <u8 as ::ink_storage::traits::SpreadLayout>::pull_spread(__key_ptr) match <::core::primitive::u8 as ::ink_storage::traits::SpreadLayout>::pull_spread(__key_ptr)
{ {
0u8 => MixedEnum::A, 0u8 => MixedEnum::A,
1u8 => MixedEnum::B( 1u8 => MixedEnum::B(
...@@ -350,7 +350,7 @@ fn enum_works() { ...@@ -350,7 +350,7 @@ fn enum_works() {
match self { match self {
MixedEnum::A => { MixedEnum::A => {
{ {
<u8 as ::ink_storage::traits::SpreadLayout>::push_spread( <::core::primitive::u8 as ::ink_storage::traits::SpreadLayout>::push_spread(
&0u8, &0u8,
__key_ptr __key_ptr
); );
...@@ -358,7 +358,7 @@ fn enum_works() { ...@@ -358,7 +358,7 @@ fn enum_works() {
} }
MixedEnum::B(__binding_0, __binding_1,) => { MixedEnum::B(__binding_0, __binding_1,) => {
{ {
<u8 as ::ink_storage::traits::SpreadLayout>::push_spread( <::core::primitive::u8 as ::ink_storage::traits::SpreadLayout>::push_spread(
&1u8, &1u8,
__key_ptr __key_ptr
); );
...@@ -381,7 +381,7 @@ fn enum_works() { ...@@ -381,7 +381,7 @@ fn enum_works() {
b: __binding_1, b: __binding_1,
} => { } => {
{ {
<u8 as ::ink_storage::traits::SpreadLayout>::push_spread( <::core::primitive::u8 as ::ink_storage::traits::SpreadLayout>::push_spread(
&2u8, __key_ptr &2u8, __key_ptr
); );
} }
...@@ -459,16 +459,16 @@ fn generic_struct_works() { ...@@ -459,16 +459,16 @@ fn generic_struct_works() {
T2: ::ink_storage::traits::SpreadLayout T2: ::ink_storage::traits::SpreadLayout
{ {
#[allow(unused_comparisons)] #[allow(unused_comparisons)]
const FOOTPRINT: u64 = [ const FOOTPRINT: ::core::primitive::u64 = [
((0u64 + <T1 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT) ((0u64 + <T1 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
+ <(T1, T2) as ::ink_storage::traits::SpreadLayout>::FOOTPRINT), + <(T1, T2) as ::ink_storage::traits::SpreadLayout>::FOOTPRINT),
0u64 0u64
][(((0u64 + <T1 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT) ][(((0u64 + <T1 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
+ <(T1, T2) as ::ink_storage::traits::SpreadLayout>::FOOTPRINT) + <(T1, T2) as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
< 0u64) as usize < 0u64) as ::core::primitive::usize
]; ];
const REQUIRES_DEEP_CLEAN_UP : bool = ( const REQUIRES_DEEP_CLEAN_UP : ::core::primitive::bool = (
false || ( false || (
( (
false false
...@@ -555,7 +555,7 @@ fn generic_enum_works() { ...@@ -555,7 +555,7 @@ fn generic_enum_works() {
T2: ::ink_storage::traits::SpreadLayout T2: ::ink_storage::traits::SpreadLayout
{ {
#[allow(unused_comparisons)] #[allow(unused_comparisons)]
const FOOTPRINT: u64 = 1 + [ const FOOTPRINT: ::core::primitive::u64 = 1 + [
((0u64 + <T1 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT) ((0u64 + <T1 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
+ <T2 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT), + <T2 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT),
[ [
...@@ -565,7 +565,7 @@ fn generic_enum_works() { ...@@ -565,7 +565,7 @@ fn generic_enum_works() {
][(((0u64 ][(((0u64
+ <T1 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT) + <T1 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
+ <T2 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT) + <T2 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
< 0u64) as usize] < 0u64) as ::core::primitive::usize]
][(((0u64 + <T1 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT) ][(((0u64 + <T1 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
+ <T2 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT) + <T2 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
< [ < [
...@@ -575,10 +575,10 @@ fn generic_enum_works() { ...@@ -575,10 +575,10 @@ fn generic_enum_works() {
][(((0u64 ][(((0u64
+ <T1 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT) + <T1 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
+ <T2 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT) + <T2 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
< 0u64) as usize]) as usize < 0u64) as ::core::primitive::usize]) as ::core::primitive::usize
]; ];
const REQUIRES_DEEP_CLEAN_UP : bool = ( const REQUIRES_DEEP_CLEAN_UP : ::core::primitive::bool = (
( (
false || ( false || (
( (
...@@ -598,7 +598,7 @@ fn generic_enum_works() { ...@@ -598,7 +598,7 @@ fn generic_enum_works() {
); );
fn pull_spread(__key_ptr: &mut ::ink_storage::traits::KeyPtr) -> Self { fn pull_spread(__key_ptr: &mut ::ink_storage::traits::KeyPtr) -> Self {
match <u8 as ::ink_storage::traits::SpreadLayout>::pull_spread(__key_ptr) match <::core::primitive::u8 as ::ink_storage::traits::SpreadLayout>::pull_spread(__key_ptr)
{ {
0u8 => GenericEnum::Tuple( 0u8 => GenericEnum::Tuple(
<T1 as ::ink_storage::traits::SpreadLayout>::pull_spread(__key_ptr), <T1 as ::ink_storage::traits::SpreadLayout>::pull_spread(__key_ptr),
...@@ -616,7 +616,7 @@ fn generic_enum_works() { ...@@ -616,7 +616,7 @@ fn generic_enum_works() {
match self { match self {
GenericEnum::Tuple(__binding_0, __binding_1,) => { GenericEnum::Tuple(__binding_0, __binding_1,) => {
{ {
<u8 as ::ink_storage::traits::SpreadLayout>::push_spread(&0u8, __key_ptr); <::core::primitive::u8 as ::ink_storage::traits::SpreadLayout>::push_spread(&0u8, __key_ptr);
} }
{ {
::ink_storage::traits::SpreadLayout::push_spread( ::ink_storage::traits::SpreadLayout::push_spread(
...@@ -636,7 +636,7 @@ fn generic_enum_works() { ...@@ -636,7 +636,7 @@ fn generic_enum_works() {
b: __binding_1, b: __binding_1,
} => { } => {
{ {
<u8 as ::ink_storage::traits::SpreadLayout>::push_spread(&1u8, __key_ptr); <::core::primitive::u8 as ::ink_storage::traits::SpreadLayout>::push_spread(&1u8, __key_ptr);
} }
{ {
::ink_storage::traits::SpreadLayout::push_spread( ::ink_storage::traits::SpreadLayout::push_spread(
......
...@@ -47,15 +47,15 @@ fn tuple_struct_works() { ...@@ -47,15 +47,15 @@ fn tuple_struct_works() {
::ink_metadata::layout::Layout::Struct( ::ink_metadata::layout::Layout::Struct(
::ink_metadata::layout::StructLayout::new(vec![ ::ink_metadata::layout::StructLayout::new(vec![
::ink_metadata::layout::FieldLayout::new( ::ink_metadata::layout::FieldLayout::new(
None, ::core::option::Option::None,
<bool as ::ink_storage::traits::StorageLayout>::layout(__key_ptr), <bool as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
), ),
::ink_metadata::layout::FieldLayout::new( ::ink_metadata::layout::FieldLayout::new(
None, ::core::option::Option::None,
<u32 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr), <u32 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
), ),
::ink_metadata::layout::FieldLayout::new( ::ink_metadata::layout::FieldLayout::new(
None, ::core::option::Option::None,
<i64 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr), <i64 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
), ),
]) ])
...@@ -84,15 +84,15 @@ fn named_fields_struct_works() { ...@@ -84,15 +84,15 @@ fn named_fields_struct_works() {
::ink_metadata::layout::Layout::Struct( ::ink_metadata::layout::Layout::Struct(
::ink_metadata::layout::StructLayout::new(vec![ ::ink_metadata::layout::StructLayout::new(vec![
::ink_metadata::layout::FieldLayout::new( ::ink_metadata::layout::FieldLayout::new(
Some("a"), ::core::option::Option::Some("a"),
<bool as ::ink_storage::traits::StorageLayout>::layout(__key_ptr), <bool as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
), ),
::ink_metadata::layout::FieldLayout::new( ::ink_metadata::layout::FieldLayout::new(
Some("b"), ::core::option::Option::Some("b"),
<u32 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr), <u32 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
), ),
::ink_metadata::layout::FieldLayout::new( ::ink_metadata::layout::FieldLayout::new(
Some("c"), ::core::option::Option::Some("c"),
<i64 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr), <i64 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
), ),
]) ])
...@@ -191,15 +191,15 @@ fn mixed_enum_works() { ...@@ -191,15 +191,15 @@ fn mixed_enum_works() {
::ink_metadata::layout::Discriminant::from(1usize), ::ink_metadata::layout::Discriminant::from(1usize),
::ink_metadata::layout::StructLayout::new(vec![ ::ink_metadata::layout::StructLayout::new(vec![
::ink_metadata::layout::FieldLayout::new( ::ink_metadata::layout::FieldLayout::new(
None, ::core::option::Option::None,
<bool as ::ink_storage::traits::StorageLayout>::layout(__key_ptr), <bool as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
), ),
::ink_metadata::layout::FieldLayout::new( ::ink_metadata::layout::FieldLayout::new(
None, ::core::option::Option::None,
<u32 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr), <u32 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
), ),
::ink_metadata::layout::FieldLayout::new( ::ink_metadata::layout::FieldLayout::new(
None, ::core::option::Option::None,
<i64 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr), <i64 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
), ),
]), ]),
...@@ -212,15 +212,15 @@ fn mixed_enum_works() { ...@@ -212,15 +212,15 @@ fn mixed_enum_works() {
::ink_metadata::layout::Discriminant::from(2usize), ::ink_metadata::layout::Discriminant::from(2usize),
::ink_metadata::layout::StructLayout::new(vec![ ::ink_metadata::layout::StructLayout::new(vec![
::ink_metadata::layout::FieldLayout::new( ::ink_metadata::layout::FieldLayout::new(
Some("a"), ::core::option::Option::Some("a"),
<bool as ::ink_storage::traits::StorageLayout>::layout(__key_ptr), <bool as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
), ),
::ink_metadata::layout::FieldLayout::new( ::ink_metadata::layout::FieldLayout::new(
Some("b"), ::core::option::Option::Some("b"),
<u32 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr), <u32 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
), ),
::ink_metadata::layout::FieldLayout::new( ::ink_metadata::layout::FieldLayout::new(
Some("c"), ::core::option::Option::Some("c"),
<i64 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr), <i64 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
), ),
]), ]),
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment