Skip to content

Commit

Permalink
no-bound derives: Use absolute path for core (#1763)
Browse files Browse the repository at this point in the history
Closes: #1718
  • Loading branch information
bkchr committed Oct 1, 2023
1 parent 2ed66a0 commit c54ea64
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 17 deletions.
6 changes: 3 additions & 3 deletions substrate/frame/support/procedural/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,8 @@ pub fn derive_runtime_debug_no_bound(input: TokenStream) -> TokenStream {

quote::quote!(
const _: () = {
impl #impl_generics core::fmt::Debug for #name #ty_generics #where_clause {
fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
impl #impl_generics ::core::fmt::Debug for #name #ty_generics #where_clause {
fn fmt(&self, fmt: &mut ::core::fmt::Formatter) -> core::fmt::Result {
fmt.write_str("<wasm:stripped>")
}
}
Expand Down Expand Up @@ -473,7 +473,7 @@ pub fn derive_eq_no_bound(input: TokenStream) -> TokenStream {

quote::quote_spanned!(name.span() =>
const _: () = {
impl #impl_generics core::cmp::Eq for #name #ty_generics #where_clause {}
impl #impl_generics ::core::cmp::Eq for #name #ty_generics #where_clause {}
};
)
.into()
Expand Down
12 changes: 6 additions & 6 deletions substrate/frame/support/procedural/src/no_bound/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn derive_clone_no_bound(input: proc_macro::TokenStream) -> proc_macro::Toke
syn::Fields::Named(named) => {
let fields = named.named.iter().map(|i| &i.ident).map(|i| {
quote::quote_spanned!(i.span() =>
#i: core::clone::Clone::clone(&self.#i)
#i: ::core::clone::Clone::clone(&self.#i)
)
});

Expand All @@ -42,7 +42,7 @@ pub fn derive_clone_no_bound(input: proc_macro::TokenStream) -> proc_macro::Toke
let fields =
unnamed.unnamed.iter().enumerate().map(|(i, _)| syn::Index::from(i)).map(|i| {
quote::quote_spanned!(i.span() =>
core::clone::Clone::clone(&self.#i)
::core::clone::Clone::clone(&self.#i)
)
});

Expand All @@ -59,8 +59,8 @@ pub fn derive_clone_no_bound(input: proc_macro::TokenStream) -> proc_macro::Toke
syn::Fields::Named(named) => {
let captured = named.named.iter().map(|i| &i.ident);
let cloned = captured.clone().map(|i| {
quote::quote_spanned!(i.span() =>
#i: core::clone::Clone::clone(#i)
::quote::quote_spanned!(i.span() =>
#i: ::core::clone::Clone::clone(#i)
)
});
quote::quote!(
Expand All @@ -75,7 +75,7 @@ pub fn derive_clone_no_bound(input: proc_macro::TokenStream) -> proc_macro::Toke
.map(|(i, f)| syn::Ident::new(&format!("_{}", i), f.span()));
let cloned = captured.clone().map(|i| {
quote::quote_spanned!(i.span() =>
core::clone::Clone::clone(#i)
::core::clone::Clone::clone(#i)
)
});
quote::quote!(
Expand All @@ -98,7 +98,7 @@ pub fn derive_clone_no_bound(input: proc_macro::TokenStream) -> proc_macro::Toke

quote::quote!(
const _: () = {
impl #impl_generics core::clone::Clone for #name #ty_generics #where_clause {
impl #impl_generics ::core::clone::Clone for #name #ty_generics #where_clause {
fn clone(&self) -> Self {
#impl_
}
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/support/procedural/src/no_bound/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ pub fn derive_debug_no_bound(input: proc_macro::TokenStream) -> proc_macro::Toke

quote::quote!(
const _: () = {
impl #impl_generics core::fmt::Debug for #input_ident #ty_generics #where_clause {
fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
impl #impl_generics ::core::fmt::Debug for #input_ident #ty_generics #where_clause {
fn fmt(&self, fmt: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
#impl_
}
}
Expand Down
10 changes: 5 additions & 5 deletions substrate/frame/support/procedural/src/no_bound/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn derive_default_no_bound(input: proc_macro::TokenStream) -> proc_macro::To
Fields::Named(named) => {
let fields = named.named.iter().map(|field| &field.ident).map(|ident| {
quote_spanned! {ident.span() =>
#ident: core::default::Default::default()
#ident: ::core::default::Default::default()
}
});

Expand All @@ -41,7 +41,7 @@ pub fn derive_default_no_bound(input: proc_macro::TokenStream) -> proc_macro::To
Fields::Unnamed(unnamed) => {
let fields = unnamed.unnamed.iter().map(|field| {
quote_spanned! {field.span()=>
core::default::Default::default()
::core::default::Default::default()
}
});

Expand Down Expand Up @@ -105,7 +105,7 @@ pub fn derive_default_no_bound(input: proc_macro::TokenStream) -> proc_macro::To
let fields =
named.named.iter().map(|field| &field.ident).map(|ident| {
quote_spanned! {ident.span()=>
#ident: core::default::Default::default()
#ident: ::core::default::Default::default()
}
});

Expand All @@ -114,7 +114,7 @@ pub fn derive_default_no_bound(input: proc_macro::TokenStream) -> proc_macro::To
Fields::Unnamed(unnamed) => {
let fields = unnamed.unnamed.iter().map(|field| {
quote_spanned! {field.span()=>
core::default::Default::default()
::core::default::Default::default()
}
});

Expand Down Expand Up @@ -149,7 +149,7 @@ pub fn derive_default_no_bound(input: proc_macro::TokenStream) -> proc_macro::To

quote!(
const _: () = {
impl #impl_generics core::default::Default for #name #ty_generics #where_clause {
impl #impl_generics ::core::default::Default for #name #ty_generics #where_clause {
fn default() -> Self {
#impl_
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub fn derive_partial_eq_no_bound(input: proc_macro::TokenStream) -> proc_macro:

quote::quote!(
const _: () = {
impl #impl_generics core::cmp::PartialEq for #name #ty_generics #where_clause {
impl #impl_generics ::core::cmp::PartialEq for #name #ty_generics #where_clause {
fn eq(&self, other: &Self) -> bool {
#impl_
}
Expand Down
14 changes: 14 additions & 0 deletions substrate/frame/support/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,3 +647,17 @@ fn check_storage_parameter_type_works() {
assert_eq!(300, StorageParameter::get());
})
}

#[test]
fn derive_partial_eq_no_bound_core_mod() {
mod core {}

#[derive(
crate::PartialEqNoBound,
crate::CloneNoBound,
crate::DebugNoBound,
crate::DefaultNoBound,
crate::EqNoBound,
)]
struct Test;
}

0 comments on commit c54ea64

Please sign in to comment.