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 {
Some((head, rest)) => {
let rest = max_n(rest);
quote! {
[#head, #rest][(#head < #rest) as usize]
[#head, #rest][(#head < #rest) as ::core::primitive::usize]
}
}
None => quote! { 0u64 },
......@@ -103,8 +103,8 @@ fn spread_layout_struct_derive(s: &synstructure::Structure) -> TokenStream2 {
s.gen_impl(quote! {
gen impl ::ink_storage::traits::SpreadLayout for @Self {
#[allow(unused_comparisons)]
const FOOTPRINT: u64 = #footprint_body;
const REQUIRES_DEEP_CLEAN_UP: bool = #requires_deep_clean_up_body;
const FOOTPRINT: ::core::primitive::u64 = #footprint_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 {
#pull_body
......@@ -154,7 +154,7 @@ fn spread_layout_enum_derive(s: &synstructure::Structure) -> TokenStream2 {
});
quote! {
#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 }
)*
......@@ -169,12 +169,12 @@ fn spread_layout_enum_derive(s: &synstructure::Structure) -> TokenStream2 {
s.gen_impl(quote! {
gen impl ::ink_storage::traits::SpreadLayout for @Self {
#[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 {
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
_ => unreachable!("encountered invalid enum discriminant"),
}
......
......@@ -22,9 +22,9 @@ fn field_layout<'a>(
let ident = match field.ident.as_ref() {
Some(ident) => {
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;
quote! {
......
......@@ -32,9 +32,9 @@ fn unit_struct_works() {
const _: () = {
impl ::ink_storage::traits::SpreadLayout for UnitStruct {
#[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 {
UnitStruct
......@@ -71,7 +71,7 @@ fn struct_works() {
const _: () = {
impl ::ink_storage::traits::SpreadLayout for NamedFields {
#[allow(unused_comparisons)]
const FOOTPRINT: u64 = [
const FOOTPRINT: ::core::primitive::u64 = [
(((0u64 + <i32 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
+ <[u8; 32] as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
+ <Box<i32> as ::ink_storage::traits::SpreadLayout>::FOOTPRINT),
......@@ -80,10 +80,10 @@ fn struct_works() {
+ <i32 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
+ <[u8; 32] 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 || (
(
(
......@@ -181,7 +181,7 @@ fn enum_works() {
const _: () = {
impl ::ink_storage::traits::SpreadLayout for MixedEnum {
#[allow(unused_comparisons)]
const FOOTPRINT : u64 = 1 + [
const FOOTPRINT : ::core::primitive::u64 = 1 + [
0u64 ,
[
(
......@@ -211,7 +211,7 @@ fn enum_works() {
+ <(bool, i32) as ::ink_storage::traits::SpreadLayout>::FOOTPRINT
)
< 0u64
) as usize
) as ::core::primitive::usize
]
][
(
......@@ -241,9 +241,9 @@ fn enum_works() {
+ <(bool, i32) as ::ink_storage::traits::SpreadLayout>::FOOTPRINT
)
< 0u64
) as usize
) as ::core::primitive::usize
]
) as usize
) as ::core::primitive::usize
]
][
(
......@@ -274,7 +274,7 @@ fn enum_works() {
+ <(bool, i32) as ::ink_storage::traits::SpreadLayout>::FOOTPRINT
)
< 0u64
) as usize
) as ::core::primitive::usize
]
][
(
......@@ -304,14 +304,14 @@ fn enum_works() {
+ <(bool, i32) as ::ink_storage::traits::SpreadLayout>::FOOTPRINT
)
< 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)
|| (
......@@ -332,7 +332,7 @@ fn enum_works() {
);
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,
1u8 => MixedEnum::B(
......@@ -350,7 +350,7 @@ fn enum_works() {
match self {
MixedEnum::A => {
{
<u8 as ::ink_storage::traits::SpreadLayout>::push_spread(
<::core::primitive::u8 as ::ink_storage::traits::SpreadLayout>::push_spread(
&0u8,
__key_ptr
);
......@@ -358,7 +358,7 @@ fn enum_works() {
}
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,
__key_ptr
);
......@@ -381,7 +381,7 @@ fn enum_works() {
b: __binding_1,
} => {
{
<u8 as ::ink_storage::traits::SpreadLayout>::push_spread(
<::core::primitive::u8 as ::ink_storage::traits::SpreadLayout>::push_spread(
&2u8, __key_ptr
);
}
......@@ -459,16 +459,16 @@ fn generic_struct_works() {
T2: ::ink_storage::traits::SpreadLayout
{
#[allow(unused_comparisons)]
const FOOTPRINT: u64 = [
const FOOTPRINT: ::core::primitive::u64 = [
((0u64 + <T1 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
+ <(T1, T2) as ::ink_storage::traits::SpreadLayout>::FOOTPRINT),
0u64
][(((0u64 + <T1 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
......@@ -555,7 +555,7 @@ fn generic_enum_works() {
T2: ::ink_storage::traits::SpreadLayout
{
#[allow(unused_comparisons)]
const FOOTPRINT: u64 = 1 + [
const FOOTPRINT: ::core::primitive::u64 = 1 + [
((0u64 + <T1 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
+ <T2 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT),
[
......@@ -565,7 +565,7 @@ fn generic_enum_works() {
][(((0u64
+ <T1 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)
+ <T2 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
< [
......@@ -575,10 +575,10 @@ fn generic_enum_works() {
][(((0u64
+ <T1 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 || (
(
......@@ -598,7 +598,7 @@ fn generic_enum_works() {
);
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(
<T1 as ::ink_storage::traits::SpreadLayout>::pull_spread(__key_ptr),
......@@ -616,7 +616,7 @@ fn generic_enum_works() {
match self {
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(
......@@ -636,7 +636,7 @@ fn generic_enum_works() {
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(
......
......@@ -47,15 +47,15 @@ fn tuple_struct_works() {
::ink_metadata::layout::Layout::Struct(
::ink_metadata::layout::StructLayout::new(vec![
::ink_metadata::layout::FieldLayout::new(
None,
::core::option::Option::None,
<bool as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
),
::ink_metadata::layout::FieldLayout::new(
None,
::core::option::Option::None,
<u32 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
),
::ink_metadata::layout::FieldLayout::new(
None,
::core::option::Option::None,
<i64 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
),
])
......@@ -84,15 +84,15 @@ fn named_fields_struct_works() {
::ink_metadata::layout::Layout::Struct(
::ink_metadata::layout::StructLayout::new(vec![
::ink_metadata::layout::FieldLayout::new(
Some("a"),
::core::option::Option::Some("a"),
<bool as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
),
::ink_metadata::layout::FieldLayout::new(
Some("b"),
::core::option::Option::Some("b"),
<u32 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
),
::ink_metadata::layout::FieldLayout::new(
Some("c"),
::core::option::Option::Some("c"),
<i64 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
),
])
......@@ -191,15 +191,15 @@ fn mixed_enum_works() {
::ink_metadata::layout::Discriminant::from(1usize),
::ink_metadata::layout::StructLayout::new(vec![
::ink_metadata::layout::FieldLayout::new(
None,
::core::option::Option::None,
<bool as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
),
::ink_metadata::layout::FieldLayout::new(
None,
::core::option::Option::None,
<u32 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
),
::ink_metadata::layout::FieldLayout::new(
None,
::core::option::Option::None,
<i64 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
),
]),
......@@ -212,15 +212,15 @@ fn mixed_enum_works() {
::ink_metadata::layout::Discriminant::from(2usize),
::ink_metadata::layout::StructLayout::new(vec![
::ink_metadata::layout::FieldLayout::new(
Some("a"),
::core::option::Option::Some("a"),
<bool as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
),
::ink_metadata::layout::FieldLayout::new(
Some("b"),
::core::option::Option::Some("b"),
<u32 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
),
::ink_metadata::layout::FieldLayout::new(
Some("c"),
::core::option::Option::Some("c"),
<i64 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
),
]),
......
Markdown is supported
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