diff --git a/prdoc/pr_4851.prdoc b/prdoc/pr_4851.prdoc index 8e96cc512320..f642126143a2 100644 --- a/prdoc/pr_4851.prdoc +++ b/prdoc/pr_4851.prdoc @@ -6,7 +6,7 @@ title: Add support for deprecation metadata in `RuntimeMetadataIr` entries. doc: - audience: Runtime Dev description: | - Adds `DeprecationStatus` enum to sp_metadata_ir. + Adds `DeprecationStatusIR` enum to sp_metadata_ir. Adds `deprecation_info` field to - `RuntimeApiMetadataIR` - `RuntimeApiMethodMetadataIR` diff --git a/substrate/frame/support/procedural/src/deprecation.rs b/substrate/frame/support/procedural/src/deprecation.rs index bef2d0aad1b6..86445d881af0 100644 --- a/substrate/frame/support/procedural/src/deprecation.rs +++ b/substrate/frame/support/procedural/src/deprecation.rs @@ -49,7 +49,7 @@ fn parse_deprecated_meta(path: &TokenStream, attr: &syn::Attribute) -> Result Result { // #[deprecated = "lit"] - let doc = quote! { #path::__private::metadata_ir::DeprecationStatus::Deprecated { note: #lit, since: None } }; + let doc = quote! { #path::__private::metadata_ir::DeprecationStatusIR::Deprecated { note: #lit, since: None } }; Ok(doc) }, Meta::Path(_) => { // #[deprecated] - Ok(quote! { #path::__private::metadata_ir::DeprecationStatus::DeprecatedWithoutNote }) + Ok(quote! { #path::__private::metadata_ir::DeprecationStatusIR::DeprecatedWithoutNote }) }, _ => Err(Error::new(attr.span(), "Invalid deprecation attribute")), } @@ -77,14 +77,15 @@ pub fn get_deprecation(path: &TokenStream, attrs: &[syn::Attribute]) -> Result( path: &TokenStream, - attrs: impl Iterator, + parent_attrs: &[syn::Attribute], + children_attrs: impl Iterator, ) -> Result { fn parse_deprecation( path: &TokenStream, @@ -97,15 +98,34 @@ pub fn get_deprecation_enum<'a>( .unwrap_or_else(|| Ok(None)) } - let children = attrs + let parent_deprecation = parse_deprecation(path, parent_attrs)?; + + let children = children_attrs .filter_map(|(key, attributes)| { - let key = key as u8; + let key = quote::quote! { #path::__private::codec::Compact(#key as u8) }; let deprecation_status = parse_deprecation(path, attributes).transpose(); deprecation_status.map(|item| item.map(|item| quote::quote! { (#key, #item) })) }) .collect::>>()?; - - Ok( - quote::quote! { #path::__private::scale_info::prelude::collections::BTreeMap::from([#( #children),*]) }, - ) + match (parent_deprecation, children.as_slice()) { + (None, []) => + Ok(quote::quote! { #path::__private::metadata_ir::DeprecationInfoIR::NotDeprecated }), + (None, _) => { + let children = quote::quote! { #path::__private::scale_info::prelude::collections::BTreeMap::from([#( #children),*]) }; + Ok( + quote::quote! { #path::__private::metadata_ir::DeprecationInfoIR::PartiallyDeprecated(#children) }, + ) + }, + (Some(depr), []) => Ok( + quote::quote! { #path::__private::metadata_ir::DeprecationInfoIR::FullyDeprecated(#depr) }, + ), + (Some(_), _) => { + let span = parent_attrs + .iter() + .find(|a| a.path().is_ident("deprecated")) + .map(|x| x.span()) + .expect("this can never fail, because we have found the deprecated attribute above; qed"); + Err(Error::new(span, "Invalid deprecation usage. Either deprecate variants/call indexes or the type as a whole")) + }, + } } diff --git a/substrate/frame/support/procedural/src/pallet/expand/call.rs b/substrate/frame/support/procedural/src/pallet/expand/call.rs index 1ca58873e423..46abbe3d1794 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/call.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/call.rs @@ -245,21 +245,21 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream { } }); - let deprecation_status = if let Some(call) = def.call.as_ref() { - crate::deprecation::get_deprecation("e::quote! {#frame_support}, &call.attrs) + let deprecation = if let Some(call) = def.call.as_ref() { + crate::deprecation::get_deprecation_enum( + "e::quote! {#frame_support}, + call.attrs.as_ref(), + methods.iter().map(|item| (item.call_index as u8, item.attrs.as_ref())), + ) } else { - Ok( - quote::quote! { #frame_support::__private::metadata_ir::DeprecationStatus::NotDeprecated }, + crate::deprecation::get_deprecation_enum( + "e::quote! {#frame_support}, + &[], + methods.iter().map(|item| (item.call_index as u8, item.attrs.as_ref())), ) } .unwrap_or_else(syn::Error::into_compile_error); - let indexes = crate::deprecation::get_deprecation_enum( - "e::quote! {#frame_support}, - methods.iter().map(|item| (item.call_index as u8, item.attrs.as_ref())), - ) - .unwrap_or_else(syn::Error::into_compile_error); - quote::quote_spanned!(span => #[doc(hidden)] mod warnings { @@ -462,8 +462,7 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream { pub fn call_functions() -> #frame_support::__private::metadata_ir::PalletCallMetadataIR { #frame_support::__private::metadata_ir::PalletCallMetadataIR { ty: #frame_support::__private::scale_info::meta_type::<#call_ident<#type_use_gen>>(), - deprecation_info: #deprecation_status, - deprecated_indexes: #indexes, + deprecation_info: #deprecation, } } } diff --git a/substrate/frame/support/procedural/src/pallet/expand/error.rs b/substrate/frame/support/procedural/src/pallet/expand/error.rs index d0e513588c5c..786ab5a7a947 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/error.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/error.rs @@ -102,12 +102,9 @@ pub fn expand_error(def: &mut Def) -> proc_macro2::TokenStream { let capture_docs = if cfg!(feature = "no-metadata-docs") { "never" } else { "always" }; - let deprecation_status = - crate::deprecation::get_deprecation("e::quote! {#frame_support}, &error.attrs) - .unwrap_or_else(syn::Error::into_compile_error); - - let variants = crate::deprecation::get_deprecation_enum( + let deprecation = crate::deprecation::get_deprecation_enum( "e::quote! {#frame_support}, + &error.attrs, error_item .variants .iter() @@ -208,8 +205,7 @@ pub fn expand_error(def: &mut Def) -> proc_macro2::TokenStream { pub fn error_metadata() -> #frame_support::__private::metadata_ir::PalletErrorMetadataIR { #frame_support::__private::metadata_ir::PalletErrorMetadataIR { ty: #frame_support::__private::scale_info::meta_type::<#error_ident<#type_use_gen>>(), - deprecation_info: #deprecation_status, - deprecated_variants: #variants + deprecation_info: #deprecation, } } } diff --git a/substrate/frame/support/procedural/src/pallet/expand/event.rs b/substrate/frame/support/procedural/src/pallet/expand/event.rs index 87d2440f964d..b72924856894 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/event.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/event.rs @@ -95,12 +95,9 @@ pub fn expand_event(def: &mut Def) -> proc_macro2::TokenStream { event_item.variants.push(variant); } - let deprecation_status = - crate::deprecation::get_deprecation("e::quote! {#frame_support}, &event.attrs) - .unwrap_or_else(syn::Error::into_compile_error); - - let variants = crate::deprecation::get_deprecation_enum( + let deprecation = crate::deprecation::get_deprecation_enum( "e::quote! {#frame_support}, + &event.attrs, event_item .variants .iter() @@ -190,8 +187,7 @@ pub fn expand_event(def: &mut Def) -> proc_macro2::TokenStream { pub fn event_metadata() -> #frame_support::__private::metadata_ir::PalletEventMetadataIR { #frame_support::__private::metadata_ir::PalletEventMetadataIR { ty: #frame_support::__private::scale_info::meta_type::(), - deprecation_info: #deprecation_status, - deprecated_variants: #variants + deprecation_info: #deprecation, } } } diff --git a/substrate/frame/support/procedural/src/pallet/expand/pallet_struct.rs b/substrate/frame/support/procedural/src/pallet/expand/pallet_struct.rs index def9dd090e1e..e43fc2950ef8 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/pallet_struct.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/pallet_struct.rs @@ -290,7 +290,7 @@ pub fn expand_pallet_struct(def: &mut Def) -> proc_macro2::TokenStream { impl<#type_use_gen> #pallet_ident<#type_use_gen> { #[allow(dead_code)] #[doc(hidden)] - pub fn deprecation_info() -> #frame_support::__private::metadata_ir::DeprecationStatus { + pub fn deprecation_info() -> #frame_support::__private::metadata_ir::DeprecationStatusIR { #deprecation_status } } diff --git a/substrate/frame/support/src/storage/types/counted_map.rs b/substrate/frame/support/src/storage/types/counted_map.rs index c3338e6cc66b..55ce3054cd45 100644 --- a/substrate/frame/support/src/storage/types/counted_map.rs +++ b/substrate/frame/support/src/storage/types/counted_map.rs @@ -509,7 +509,7 @@ where MaxValues: Get>, { fn build_metadata( - deprecation_status: sp_metadata_ir::DeprecationStatus, + deprecation_status: sp_metadata_ir::DeprecationStatusIR, docs: Vec<&'static str>, entries: &mut Vec, ) { @@ -1198,7 +1198,7 @@ mod test { fn test_metadata() { type A = CountedStorageMap; let mut entries = vec![]; - A::build_metadata(sp_metadata_ir::DeprecationStatus::NotDeprecated, vec![], &mut entries); + A::build_metadata(sp_metadata_ir::DeprecationStatusIR::NotDeprecated, vec![], &mut entries); assert_eq!( entries, vec![ @@ -1212,7 +1212,7 @@ mod test { }, default: 97u32.encode(), docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, }, StorageEntryMetadataIR { name: "counter_for_foo", @@ -1224,7 +1224,7 @@ mod test { } else { vec!["Counter for the related counted storage map"] }, - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, }, ] ); diff --git a/substrate/frame/support/src/storage/types/counted_nmap.rs b/substrate/frame/support/src/storage/types/counted_nmap.rs index 655afad41e09..41bce59a51d1 100644 --- a/substrate/frame/support/src/storage/types/counted_nmap.rs +++ b/substrate/frame/support/src/storage/types/counted_nmap.rs @@ -633,7 +633,7 @@ where MaxValues: Get>, { fn build_metadata( - deprecation_status: sp_metadata_ir::DeprecationStatus, + deprecation_status: sp_metadata_ir::DeprecationStatusIR, docs: Vec<&'static str>, entries: &mut Vec, ) { @@ -864,12 +864,12 @@ mod test { let mut entries = vec![]; A::build_metadata( - sp_metadata_ir::DeprecationStatus::NotDeprecated, + sp_metadata_ir::DeprecationStatusIR::NotDeprecated, vec![], &mut entries, ); AValueQueryWithAnOnEmpty::build_metadata( - sp_metadata_ir::DeprecationStatus::NotDeprecated, + sp_metadata_ir::DeprecationStatusIR::NotDeprecated, vec![], &mut entries, ); @@ -886,7 +886,7 @@ mod test { }, default: Option::::None.encode(), docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, }, StorageEntryMetadataIR { name: "Foo", @@ -898,7 +898,7 @@ mod test { } else { vec!["Counter for the related counted storage map"] }, - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, }, StorageEntryMetadataIR { name: "Foo", @@ -910,7 +910,7 @@ mod test { }, default: 98u32.encode(), docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, }, StorageEntryMetadataIR { name: "Foo", @@ -922,7 +922,7 @@ mod test { } else { vec!["Counter for the related counted storage map"] }, - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, }, ] ); @@ -1125,12 +1125,12 @@ mod test { let mut entries = vec![]; A::build_metadata( - sp_metadata_ir::DeprecationStatus::NotDeprecated, + sp_metadata_ir::DeprecationStatusIR::NotDeprecated, vec![], &mut entries, ); AValueQueryWithAnOnEmpty::build_metadata( - sp_metadata_ir::DeprecationStatus::NotDeprecated, + sp_metadata_ir::DeprecationStatusIR::NotDeprecated, vec![], &mut entries, ); @@ -1150,7 +1150,7 @@ mod test { }, default: Option::::None.encode(), docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, }, StorageEntryMetadataIR { name: "Foo", @@ -1162,7 +1162,7 @@ mod test { } else { vec!["Counter for the related counted storage map"] }, - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, }, StorageEntryMetadataIR { name: "Foo", @@ -1177,7 +1177,7 @@ mod test { }, default: 98u32.encode(), docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, }, StorageEntryMetadataIR { name: "Foo", @@ -1189,7 +1189,7 @@ mod test { } else { vec!["Counter for the related counted storage map"] }, - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, }, ] ); @@ -1423,12 +1423,12 @@ mod test { let mut entries = vec![]; A::build_metadata( - sp_metadata_ir::DeprecationStatus::NotDeprecated, + sp_metadata_ir::DeprecationStatusIR::NotDeprecated, vec![], &mut entries, ); AValueQueryWithAnOnEmpty::build_metadata( - sp_metadata_ir::DeprecationStatus::NotDeprecated, + sp_metadata_ir::DeprecationStatusIR::NotDeprecated, vec![], &mut entries, ); @@ -1449,7 +1449,7 @@ mod test { }, default: Option::::None.encode(), docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, }, StorageEntryMetadataIR { name: "Foo", @@ -1461,7 +1461,7 @@ mod test { } else { vec!["Counter for the related counted storage map"] }, - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, }, StorageEntryMetadataIR { name: "Foo", @@ -1477,7 +1477,7 @@ mod test { }, default: 98u32.encode(), docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, }, StorageEntryMetadataIR { name: "Foo", @@ -1489,7 +1489,7 @@ mod test { } else { vec!["Counter for the related counted storage map"] }, - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, }, ] ); diff --git a/substrate/frame/support/src/storage/types/double_map.rs b/substrate/frame/support/src/storage/types/double_map.rs index 4e4ee89cf88a..e7205b2d264f 100644 --- a/substrate/frame/support/src/storage/types/double_map.rs +++ b/substrate/frame/support/src/storage/types/double_map.rs @@ -733,7 +733,7 @@ where MaxValues: Get>, { fn build_metadata( - deprecation_status: sp_metadata_ir::DeprecationStatus, + deprecation_status: sp_metadata_ir::DeprecationStatusIR, docs: Vec<&'static str>, entries: &mut Vec, ) { @@ -991,12 +991,12 @@ mod test { let mut entries = vec![]; A::build_metadata( - sp_metadata_ir::DeprecationStatus::NotDeprecated, + sp_metadata_ir::DeprecationStatusIR::NotDeprecated, vec![], &mut entries, ); AValueQueryWithAnOnEmpty::build_metadata( - sp_metadata_ir::DeprecationStatus::NotDeprecated, + sp_metadata_ir::DeprecationStatusIR::NotDeprecated, vec![], &mut entries, ); @@ -1016,7 +1016,7 @@ mod test { }, default: Option::::None.encode(), docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated }, StorageEntryMetadataIR { name: "foo", @@ -1031,7 +1031,7 @@ mod test { }, default: 97u32.encode(), docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated } ] ); diff --git a/substrate/frame/support/src/storage/types/map.rs b/substrate/frame/support/src/storage/types/map.rs index 7fd6dbbe4283..a522b85acd0f 100644 --- a/substrate/frame/support/src/storage/types/map.rs +++ b/substrate/frame/support/src/storage/types/map.rs @@ -491,7 +491,7 @@ where MaxValues: Get>, { fn build_metadata( - deprecation_status: sp_metadata_ir::DeprecationStatus, + deprecation_status: sp_metadata_ir::DeprecationStatusIR, docs: Vec<&'static str>, entries: &mut Vec, ) { @@ -797,12 +797,12 @@ mod test { let mut entries = vec![]; A::build_metadata( - sp_metadata_ir::DeprecationStatus::NotDeprecated, + sp_metadata_ir::DeprecationStatusIR::NotDeprecated, vec![], &mut entries, ); AValueQueryWithAnOnEmpty::build_metadata( - sp_metadata_ir::DeprecationStatus::NotDeprecated, + sp_metadata_ir::DeprecationStatusIR::NotDeprecated, vec![], &mut entries, ); @@ -819,7 +819,7 @@ mod test { }, default: Option::::None.encode(), docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated }, StorageEntryMetadataIR { name: "foo", @@ -831,7 +831,7 @@ mod test { }, default: 97u32.encode(), docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated } ] ); diff --git a/substrate/frame/support/src/storage/types/mod.rs b/substrate/frame/support/src/storage/types/mod.rs index 60cf13206f46..610ed6d79972 100644 --- a/substrate/frame/support/src/storage/types/mod.rs +++ b/substrate/frame/support/src/storage/types/mod.rs @@ -142,7 +142,7 @@ where pub trait StorageEntryMetadataBuilder { /// Build into `entries` the storage metadata entries of a storage given some `docs`. fn build_metadata( - deprecation_status: sp_metadata_ir::DeprecationStatus, + deprecation_status: sp_metadata_ir::DeprecationStatusIR, doc: Vec<&'static str>, entries: &mut Vec, ); diff --git a/substrate/frame/support/src/storage/types/nmap.rs b/substrate/frame/support/src/storage/types/nmap.rs index 85fb3c3fbb79..a62c4c94ff72 100755 --- a/substrate/frame/support/src/storage/types/nmap.rs +++ b/substrate/frame/support/src/storage/types/nmap.rs @@ -584,7 +584,7 @@ where MaxValues: Get>, { fn build_metadata( - deprecation_status: sp_metadata_ir::DeprecationStatus, + deprecation_status: sp_metadata_ir::DeprecationStatusIR, docs: Vec<&'static str>, entries: &mut Vec, ) { @@ -825,12 +825,12 @@ mod test { let mut entries = vec![]; A::build_metadata( - sp_metadata_ir::DeprecationStatus::NotDeprecated, + sp_metadata_ir::DeprecationStatusIR::NotDeprecated, vec![], &mut entries, ); AValueQueryWithAnOnEmpty::build_metadata( - sp_metadata_ir::DeprecationStatus::NotDeprecated, + sp_metadata_ir::DeprecationStatusIR::NotDeprecated, vec![], &mut entries, ); @@ -847,7 +847,7 @@ mod test { }, default: Option::::None.encode(), docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, }, StorageEntryMetadataIR { name: "Foo", @@ -859,7 +859,7 @@ mod test { }, default: 98u32.encode(), docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, } ] ); @@ -1035,12 +1035,12 @@ mod test { let mut entries = vec![]; A::build_metadata( - sp_metadata_ir::DeprecationStatus::NotDeprecated, + sp_metadata_ir::DeprecationStatusIR::NotDeprecated, vec![], &mut entries, ); AValueQueryWithAnOnEmpty::build_metadata( - sp_metadata_ir::DeprecationStatus::NotDeprecated, + sp_metadata_ir::DeprecationStatusIR::NotDeprecated, vec![], &mut entries, ); @@ -1060,7 +1060,7 @@ mod test { }, default: Option::::None.encode(), docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, }, StorageEntryMetadataIR { name: "Foo", @@ -1075,7 +1075,7 @@ mod test { }, default: 98u32.encode(), docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, } ] ); @@ -1286,12 +1286,12 @@ mod test { let mut entries = vec![]; A::build_metadata( - sp_metadata_ir::DeprecationStatus::NotDeprecated, + sp_metadata_ir::DeprecationStatusIR::NotDeprecated, vec![], &mut entries, ); AValueQueryWithAnOnEmpty::build_metadata( - sp_metadata_ir::DeprecationStatus::NotDeprecated, + sp_metadata_ir::DeprecationStatusIR::NotDeprecated, vec![], &mut entries, ); @@ -1312,7 +1312,7 @@ mod test { }, default: Option::::None.encode(), docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, }, StorageEntryMetadataIR { name: "Foo", @@ -1328,7 +1328,7 @@ mod test { }, default: 98u32.encode(), docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, } ] ); diff --git a/substrate/frame/support/src/storage/types/value.rs b/substrate/frame/support/src/storage/types/value.rs index 18466d4f0f11..2711a4d43f63 100644 --- a/substrate/frame/support/src/storage/types/value.rs +++ b/substrate/frame/support/src/storage/types/value.rs @@ -278,7 +278,7 @@ where OnEmpty: crate::traits::Get + 'static, { fn build_metadata( - deprecation_status: sp_metadata_ir::DeprecationStatus, + deprecation_status: sp_metadata_ir::DeprecationStatusIR, docs: Vec<&'static str>, entries: &mut Vec, ) { @@ -421,12 +421,12 @@ mod test { let mut entries = vec![]; A::build_metadata( - sp_metadata_ir::DeprecationStatus::NotDeprecated, + sp_metadata_ir::DeprecationStatusIR::NotDeprecated, vec![], &mut entries, ); AValueQueryWithAnOnEmpty::build_metadata( - sp_metadata_ir::DeprecationStatus::NotDeprecated, + sp_metadata_ir::DeprecationStatusIR::NotDeprecated, vec![], &mut entries, ); @@ -439,7 +439,7 @@ mod test { ty: StorageEntryTypeIR::Plain(scale_info::meta_type::()), default: Option::::None.encode(), docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated }, StorageEntryMetadataIR { name: "foo", @@ -447,7 +447,7 @@ mod test { ty: StorageEntryTypeIR::Plain(scale_info::meta_type::()), default: 97u32.encode(), docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated } ] ); diff --git a/substrate/frame/support/src/tests/mod.rs b/substrate/frame/support/src/tests/mod.rs index 891d21944d8c..2a3c3113c105 100644 --- a/substrate/frame/support/src/tests/mod.rs +++ b/substrate/frame/support/src/tests/mod.rs @@ -600,7 +600,7 @@ fn expected_metadata() -> PalletStorageMetadataIR { }, default: vec![0, 0, 0, 0, 0, 0, 0, 0], docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::DeprecatedWithoutNote, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::DeprecatedWithoutNote, }, StorageEntryMetadataIR { name: "OptionLinkedMap", @@ -612,7 +612,7 @@ fn expected_metadata() -> PalletStorageMetadataIR { }, default: vec![0], docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::Deprecated { + deprecation_info: sp_metadata_ir::DeprecationStatusIR::Deprecated { note: "test", since: None, }, @@ -627,7 +627,7 @@ fn expected_metadata() -> PalletStorageMetadataIR { }, default: vec![0, 0, 0, 0], docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::Deprecated { + deprecation_info: sp_metadata_ir::DeprecationStatusIR::Deprecated { note: "test", since: Some("test"), }, @@ -642,7 +642,7 @@ fn expected_metadata() -> PalletStorageMetadataIR { }, default: vec![0], docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::Deprecated { + deprecation_info: sp_metadata_ir::DeprecationStatusIR::Deprecated { note: "test", since: None, }, @@ -657,7 +657,7 @@ fn expected_metadata() -> PalletStorageMetadataIR { }, default: vec![0, 0, 0, 0, 0, 0, 0, 0], docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, }, StorageEntryMetadataIR { name: "GenericDataDM", @@ -669,7 +669,7 @@ fn expected_metadata() -> PalletStorageMetadataIR { }, default: vec![0, 0, 0, 0], docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, }, StorageEntryMetadataIR { name: "GenericData2DM", @@ -681,7 +681,7 @@ fn expected_metadata() -> PalletStorageMetadataIR { }, default: vec![0], docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, }, StorageEntryMetadataIR { name: "AppendableDM", @@ -696,7 +696,7 @@ fn expected_metadata() -> PalletStorageMetadataIR { }, default: vec![0], docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, }, StorageEntryMetadataIR { name: "Total", @@ -704,7 +704,7 @@ fn expected_metadata() -> PalletStorageMetadataIR { ty: StorageEntryTypeIR::Plain(scale_info::meta_type::<(u32, u32)>()), default: vec![0, 0, 0, 0, 0, 0, 0, 0], docs: vec![" Some running total."], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, }, StorageEntryMetadataIR { name: "Numbers", @@ -716,7 +716,7 @@ fn expected_metadata() -> PalletStorageMetadataIR { }, default: vec![0], docs: vec![" Numbers to be added into the total."], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, }, ], } @@ -739,7 +739,7 @@ fn constant_metadata() { ty: scale_info::meta_type::<()>(), value: vec![], docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::Deprecated { + deprecation_info: sp_metadata_ir::DeprecationStatusIR::Deprecated { note: "this constant is deprecated", since: None } diff --git a/substrate/frame/support/test/tests/instance.rs b/substrate/frame/support/test/tests/instance.rs index ff9e93618548..7f8423a0127e 100644 --- a/substrate/frame/support/test/tests/instance.rs +++ b/substrate/frame/support/test/tests/instance.rs @@ -441,7 +441,7 @@ fn expected_metadata() -> PalletStorageMetadataIR { ty: StorageEntryTypeIR::Plain(scale_info::meta_type::()), default: vec![0, 0, 0, 0], docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, }, StorageEntryMetadataIR { name: "Map", @@ -453,7 +453,7 @@ fn expected_metadata() -> PalletStorageMetadataIR { }, default: [0u8; 8].to_vec(), docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, }, StorageEntryMetadataIR { name: "DoubleMap", @@ -465,7 +465,7 @@ fn expected_metadata() -> PalletStorageMetadataIR { }, default: [0u8; 8].to_vec(), docs: vec![], - deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, + deprecation_info: sp_metadata_ir::DeprecationStatusIR::NotDeprecated, }, ], } diff --git a/substrate/frame/support/test/tests/pallet.rs b/substrate/frame/support/test/tests/pallet.rs index 33e78bb1d3ce..29dde2bada5f 100644 --- a/substrate/frame/support/test/tests/pallet.rs +++ b/substrate/frame/support/test/tests/pallet.rs @@ -208,7 +208,6 @@ pub mod pallet { } #[pallet::call] - #[deprecated = "test"] impl Pallet where T::AccountId: From + From + SomeAssociation1, @@ -274,7 +273,6 @@ pub mod pallet { #[pallet::error] #[derive(PartialEq, Eq)] - #[deprecated = "test"] pub enum Error { /// error doc comment put in metadata InsufficientProposersBalance, @@ -298,7 +296,6 @@ pub mod pallet { /// event doc comment put in metadata Proposed(::AccountId), Spending(BalanceOf), - #[deprecated = "test"] Something(u32), SomethingElse(::_1), } @@ -2488,52 +2485,53 @@ fn test_error_feature_parsing() { #[test] fn pallet_metadata() { - use sp_metadata_ir::DeprecationStatus; + use sp_metadata_ir::{DeprecationInfoIR, DeprecationStatusIR}; let pallets = Runtime::metadata_ir().pallets; let example = pallets[0].clone(); let example2 = pallets[1].clone(); { // Example2 pallet is deprecated - let meta = example2; assert_eq!( - &DeprecationStatus::Deprecated { note: "test", since: None }, - &meta.deprecation_info + &DeprecationStatusIR::Deprecated { note: "test", since: None }, + &example2.deprecation_info ) } { // Example pallet calls is fully and partially deprecated let meta = &example.calls.unwrap(); assert_eq!( - DeprecationStatus::Deprecated { note: "test", since: None }, + DeprecationInfoIR::PartiallyDeprecated(BTreeMap::from([( + codec::Compact(0), + DeprecationStatusIR::Deprecated { note: "test", since: None } + )])), meta.deprecation_info - ); - assert_eq!( - BTreeMap::from([(0, DeprecationStatus::Deprecated { note: "test", since: None })]), - meta.deprecated_indexes ) } { // Example pallet errors are partially and fully deprecated let meta = &example.error.unwrap(); assert_eq!( - DeprecationStatus::Deprecated { note: "test", since: None }, + DeprecationInfoIR::PartiallyDeprecated(BTreeMap::from([( + codec::Compact(2), + DeprecationStatusIR::Deprecated { note: "test", since: None } + )])), meta.deprecation_info - ); - assert_eq!( - BTreeMap::from([(2, DeprecationStatus::Deprecated { note: "test", since: None })]), - meta.deprecated_variants ) } { // Example pallet events are partially and fully deprecated let meta = example.event.unwrap(); assert_eq!( - DeprecationStatus::Deprecated { note: "test", since: None }, + DeprecationInfoIR::FullyDeprecated(DeprecationStatusIR::Deprecated { + note: "test", + since: None + }), meta.deprecation_info ); - assert_eq!( - BTreeMap::from([(2, DeprecationStatus::Deprecated { note: "test", since: None })]), - meta.deprecated_variants - ) + } + { + // Example2 pallet events are not deprecated + let meta = example2.event.unwrap(); + assert_eq!(DeprecationInfoIR::NotDeprecated, meta.deprecation_info); } } diff --git a/substrate/frame/support/test/tests/runtime_metadata.rs b/substrate/frame/support/test/tests/runtime_metadata.rs index d87fa586210c..81377210eb43 100644 --- a/substrate/frame/support/test/tests/runtime_metadata.rs +++ b/substrate/frame/support/test/tests/runtime_metadata.rs @@ -19,7 +19,7 @@ use frame_support::{derive_impl, traits::ConstU32}; use scale_info::{form::MetaForm, meta_type}; use sp_metadata_ir::{ - DeprecationStatus, RuntimeApiMetadataIR, RuntimeApiMethodMetadataIR, + DeprecationStatusIR, RuntimeApiMetadataIR, RuntimeApiMethodMetadataIR, RuntimeApiMethodParamMetadataIR, }; use sp_runtime::traits::Block as BlockT; @@ -134,7 +134,7 @@ fn runtime_metadata() { }], output: meta_type::<()>(), docs: vec![], - deprecation_info: DeprecationStatus::NotDeprecated, + deprecation_info: DeprecationStatusIR::NotDeprecated, }, RuntimeApiMethodMetadataIR { name: "something_with_block", @@ -144,7 +144,7 @@ fn runtime_metadata() { }], output: meta_type::(), docs: maybe_docs(vec![" something_with_block."]), - deprecation_info: DeprecationStatus::NotDeprecated, + deprecation_info: DeprecationStatusIR::NotDeprecated, }, RuntimeApiMethodMetadataIR { name: "function_with_two_args", @@ -160,7 +160,7 @@ fn runtime_metadata() { ], output: meta_type::<()>(), docs: vec![], - deprecation_info: DeprecationStatus::Deprecated { + deprecation_info: DeprecationStatusIR::Deprecated { note: "example", since: None, } @@ -170,7 +170,7 @@ fn runtime_metadata() { inputs: vec![], output: meta_type::<()>(), docs: vec![], - deprecation_info: DeprecationStatus::Deprecated { + deprecation_info: DeprecationStatusIR::Deprecated { note: "example", since: Some("example"), } @@ -183,7 +183,7 @@ fn runtime_metadata() { }], output: meta_type::<()>(), docs: vec![], - deprecation_info: DeprecationStatus::Deprecated { + deprecation_info: DeprecationStatusIR::Deprecated { note: "example", since: None, } @@ -194,7 +194,7 @@ fn runtime_metadata() { "", " Documentation on multiline.", ]), - deprecation_info: DeprecationStatus::DeprecatedWithoutNote, + deprecation_info: DeprecationStatusIR::DeprecatedWithoutNote, }, RuntimeApiMetadataIR { @@ -205,7 +205,7 @@ fn runtime_metadata() { inputs: vec![], output: meta_type::(), docs: maybe_docs(vec![" Returns the version of the runtime."]), - deprecation_info: DeprecationStatus::NotDeprecated, + deprecation_info: DeprecationStatusIR::NotDeprecated, }, RuntimeApiMethodMetadataIR { name: "execute_block", @@ -215,7 +215,7 @@ fn runtime_metadata() { }], output: meta_type::<()>(), docs: maybe_docs(vec![" Execute the given block."]), - deprecation_info: DeprecationStatus::NotDeprecated, + deprecation_info: DeprecationStatusIR::NotDeprecated, }, RuntimeApiMethodMetadataIR { @@ -226,13 +226,13 @@ fn runtime_metadata() { }], output: meta_type::(), docs: maybe_docs(vec![" Initialize a block with the given header and return the runtime executive mode."]), - deprecation_info: DeprecationStatus::NotDeprecated, + deprecation_info: DeprecationStatusIR::NotDeprecated, }, ], docs: maybe_docs(vec![ " The `Core` runtime api that every Substrate runtime needs to implement.", ]), - deprecation_info: DeprecationStatus::NotDeprecated, + deprecation_info: DeprecationStatusIR::NotDeprecated, }, ]; diff --git a/substrate/primitives/api/proc-macro/src/utils.rs b/substrate/primitives/api/proc-macro/src/utils.rs index a11e8fd72b14..7982c1e56e91 100644 --- a/substrate/primitives/api/proc-macro/src/utils.rs +++ b/substrate/primitives/api/proc-macro/src/utils.rs @@ -313,7 +313,7 @@ fn parse_deprecated_meta(crate_: &TokenStream, attr: &syn::Attribute) -> Result< } else { quote! { None } }; - let doc = quote! { #crate_::metadata_ir::DeprecationStatus::Deprecated { note: #note, since: #since }}; + let doc = quote! { #crate_::metadata_ir::DeprecationStatusIR::Deprecated { note: #note, since: #since }}; Ok(doc) }, ) @@ -323,12 +323,12 @@ fn parse_deprecated_meta(crate_: &TokenStream, attr: &syn::Attribute) -> Result< .. }) => { // #[deprecated = "lit"] - let doc = quote! { #crate_::metadata_ir::DeprecationStatus::Deprecated { note: #lit, since: None } }; + let doc = quote! { #crate_::metadata_ir::DeprecationStatusIR::Deprecated { note: #lit, since: None } }; Ok(doc) }, Meta::Path(_) => { // #[deprecated] - Ok(quote! { #crate_::metadata_ir::DeprecationStatus::DeprecatedWithoutNote }) + Ok(quote! { #crate_::metadata_ir::DeprecationStatusIR::DeprecatedWithoutNote }) }, _ => Err(Error::new(attr.span(), "Invalid deprecation attribute")), } @@ -340,7 +340,7 @@ pub fn get_deprecation(crate_: &TokenStream, attrs: &[syn::Attribute]) -> Result .iter() .find(|a| a.path().is_ident("deprecated")) .map(|a| parse_deprecated_meta(&crate_, a)) - .unwrap_or_else(|| Ok(quote! {#crate_::metadata_ir::DeprecationStatus::NotDeprecated})) + .unwrap_or_else(|| Ok(quote! {#crate_::metadata_ir::DeprecationStatusIR::NotDeprecated})) } #[cfg(test)] @@ -404,23 +404,23 @@ mod tests { parse_quote!(#[deprecated(note = #FIRST, since = #SECOND, extra = "Test")]); assert_eq!( get_deprecation("e! { crate }, &[simple]).unwrap().to_string(), - quote! { crate::metadata_ir::DeprecationStatus::DeprecatedWithoutNote }.to_string() + quote! { crate::metadata_ir::DeprecationStatusIR::DeprecatedWithoutNote }.to_string() ); assert_eq!( get_deprecation("e! { crate }, &[simple_path]).unwrap().to_string(), - quote! { crate::metadata_ir::DeprecationStatus::Deprecated { note: #FIRST, since: None } }.to_string() + quote! { crate::metadata_ir::DeprecationStatusIR::Deprecated { note: #FIRST, since: None } }.to_string() ); assert_eq!( get_deprecation("e! { crate }, &[meta_list]).unwrap().to_string(), - quote! { crate::metadata_ir::DeprecationStatus::Deprecated { note: #FIRST, since: None } }.to_string() + quote! { crate::metadata_ir::DeprecationStatusIR::Deprecated { note: #FIRST, since: None } }.to_string() ); assert_eq!( get_deprecation("e! { crate }, &[meta_list_with_since]).unwrap().to_string(), - quote! { crate::metadata_ir::DeprecationStatus::Deprecated { note: #FIRST, since: Some(#SECOND) }}.to_string() + quote! { crate::metadata_ir::DeprecationStatusIR::Deprecated { note: #FIRST, since: Some(#SECOND) }}.to_string() ); assert_eq!( get_deprecation("e! { crate }, &[extra_fields]).unwrap().to_string(), - quote! { crate::metadata_ir::DeprecationStatus::Deprecated { note: #FIRST, since: Some(#SECOND) }}.to_string() + quote! { crate::metadata_ir::DeprecationStatusIR::Deprecated { note: #FIRST, since: Some(#SECOND) }}.to_string() ); } } diff --git a/substrate/primitives/metadata-ir/src/types.rs b/substrate/primitives/metadata-ir/src/types.rs index 38d8ea278ec8..cb335e765ac8 100644 --- a/substrate/primitives/metadata-ir/src/types.rs +++ b/substrate/primitives/metadata-ir/src/types.rs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use codec::Encode; +use codec::{Compact, Encode}; use scale_info::{ form::{Form, MetaForm, PortableForm}, prelude::{collections::BTreeMap, vec::Vec}, @@ -53,7 +53,7 @@ pub struct RuntimeApiMetadataIR { /// Trait documentation. pub docs: Vec, /// Deprecation info - pub deprecation_info: DeprecationStatus, + pub deprecation_info: DeprecationStatusIR, } impl IntoPortable for RuntimeApiMetadataIR { @@ -81,7 +81,7 @@ pub struct RuntimeApiMethodMetadataIR { /// Method documentation. pub docs: Vec, /// Deprecation info - pub deprecation_info: DeprecationStatus, + pub deprecation_info: DeprecationStatusIR, } impl IntoPortable for RuntimeApiMethodMetadataIR { @@ -139,7 +139,7 @@ pub struct PalletMetadataIR { /// Pallet documentation. pub docs: Vec, /// Deprecation info - pub deprecation_info: DeprecationStatus, + pub deprecation_info: DeprecationStatusIR, } impl IntoPortable for PalletMetadataIR { @@ -255,7 +255,7 @@ pub struct StorageEntryMetadataIR { /// Storage entry documentation. pub docs: Vec, /// Deprecation info - pub deprecation_info: DeprecationStatus, + pub deprecation_info: DeprecationStatusIR, } impl IntoPortable for StorageEntryMetadataIR { @@ -343,10 +343,8 @@ impl IntoPortable for StorageEntryTypeIR { pub struct PalletCallMetadataIR { /// The corresponding enum type for the pallet call. pub ty: T::Type, - /// Deprecation status of the pallet call itself - pub deprecation_info: DeprecationStatus, - /// Deprecation status of the call indexes - pub deprecated_indexes: BTreeMap>, + /// Deprecation status of the pallet call + pub deprecation_info: DeprecationInfoIR, } impl IntoPortable for PalletCallMetadataIR { @@ -355,15 +353,6 @@ impl IntoPortable for PalletCallMetadataIR { fn into_portable(self, registry: &mut Registry) -> Self::Output { PalletCallMetadataIR { ty: registry.register_type(&self.ty), - deprecated_indexes: self - .deprecated_indexes - .into_iter() - .map(|(k, v)| { - let key = k; - let value = v.into_portable(registry); - (key, value) - }) - .collect(), deprecation_info: self.deprecation_info.into_portable(registry), } } @@ -374,10 +363,8 @@ impl IntoPortable for PalletCallMetadataIR { pub struct PalletEventMetadataIR { /// The Event type. pub ty: T::Type, - /// Deprecation status of the event itself - pub deprecation_info: DeprecationStatus, - /// Deprecation status of the variants - pub deprecated_variants: BTreeMap>, + /// Deprecation info of the event + pub deprecation_info: DeprecationInfoIR, } impl IntoPortable for PalletEventMetadataIR { @@ -386,14 +373,6 @@ impl IntoPortable for PalletEventMetadataIR { fn into_portable(self, registry: &mut Registry) -> Self::Output { PalletEventMetadataIR { ty: registry.register_type(&self.ty), - deprecated_variants: self - .deprecated_variants - .into_iter() - .map(|(k, v)| { - let value = v.into_portable(registry); - (k, value) - }) - .collect(), deprecation_info: self.deprecation_info.into_portable(registry), } } @@ -411,7 +390,7 @@ pub struct PalletConstantMetadataIR { /// Documentation of the constant. pub docs: Vec, /// Deprecation info - pub deprecation_info: DeprecationStatus, + pub deprecation_info: DeprecationStatusIR, } impl IntoPortable for PalletConstantMetadataIR { @@ -433,10 +412,8 @@ impl IntoPortable for PalletConstantMetadataIR { pub struct PalletErrorMetadataIR { /// The error type information. pub ty: T::Type, - /// Deprecation status of the error itself - pub deprecation_info: DeprecationStatus, - /// Deprecation status of the variants - pub deprecated_variants: BTreeMap>, + /// Deprecation info + pub deprecation_info: DeprecationInfoIR, } impl IntoPortable for PalletErrorMetadataIR { @@ -445,14 +422,6 @@ impl IntoPortable for PalletErrorMetadataIR { fn into_portable(self, registry: &mut Registry) -> Self::Output { PalletErrorMetadataIR { ty: registry.register_type(&self.ty), - deprecated_variants: self - .deprecated_variants - .into_iter() - .map(|(k, v)| { - let value = v.into_portable(registry); - (k, value) - }) - .collect(), deprecation_info: self.deprecation_info.into_portable(registry), } } @@ -497,7 +466,7 @@ impl IntoPortable for OuterEnumsIR { /// Deprecation status for an entry inside MetadataIR #[derive(Clone, PartialEq, Eq, Encode, Debug)] -pub enum DeprecationStatus { +pub enum DeprecationStatusIR { /// Entry is not deprecated NotDeprecated, /// Deprecated without a note. @@ -510,18 +479,47 @@ pub enum DeprecationStatus { since: Option, }, } -impl IntoPortable for DeprecationStatus { - type Output = DeprecationStatus; +impl IntoPortable for DeprecationStatusIR { + type Output = DeprecationStatusIR; fn into_portable(self, registry: &mut Registry) -> Self::Output { match self { Self::Deprecated { note, since } => { let note = note.into_portable(registry); let since = since.map(|x| x.into_portable(registry)); - DeprecationStatus::Deprecated { note, since } + DeprecationStatusIR::Deprecated { note, since } + }, + Self::DeprecatedWithoutNote => DeprecationStatusIR::DeprecatedWithoutNote, + Self::NotDeprecated => DeprecationStatusIR::NotDeprecated, + } + } +} +/// Deprecation info for an enums/errors/calls. +/// Denotes full/partial deprecation of the type +#[derive(Clone, PartialEq, Eq, Encode, Debug)] +pub enum DeprecationInfoIR { + /// Type is not deprecated + NotDeprecated, + /// Entry is fully deprecated. + FullyDeprecated(DeprecationStatusIR), + /// Entry is partially deprecated. + /// For Errors and Events this means that only some of the variants are deprecated + /// For Calls only certain call indexes are deprecated + PartiallyDeprecated(BTreeMap, DeprecationStatusIR>), +} +impl IntoPortable for DeprecationInfoIR { + type Output = DeprecationInfoIR; + + fn into_portable(self, registry: &mut Registry) -> Self::Output { + match self { + Self::PartiallyDeprecated(entries) => { + let entries = + entries.into_iter().map(|(k, entry)| (k, entry.into_portable(registry))); + DeprecationInfoIR::PartiallyDeprecated(entries.collect()) }, - Self::DeprecatedWithoutNote => DeprecationStatus::DeprecatedWithoutNote, - Self::NotDeprecated => DeprecationStatus::NotDeprecated, + Self::FullyDeprecated(deprecation) => + DeprecationInfoIR::FullyDeprecated(deprecation.into_portable(registry)), + Self::NotDeprecated => DeprecationInfoIR::NotDeprecated, } } }