Skip to content

Commit 64784b9

Browse files
committed
working
1 parent a079954 commit 64784b9

File tree

6 files changed

+23
-44
lines changed

6 files changed

+23
-44
lines changed

pallets/commitments/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub mod types;
1010
pub mod weights;
1111

1212
pub use pallet::*;
13-
use subtensor_macros::freeze_struct_ignore_ra;
13+
use subtensor_macros::freeze_struct;
1414
pub use types::*;
1515
pub use weights::WeightInfo;
1616

@@ -210,7 +210,7 @@ use {
210210
},
211211
};
212212

213-
#[freeze_struct_ignore_ra("6a00398e14a8a984")]
213+
#[freeze_struct("6a00398e14a8a984")]
214214
#[derive(Encode, Decode, Clone, Eq, PartialEq, TypeInfo)]
215215
pub struct CommitmentsSignedExtension<T: Config + Send + Sync + TypeInfo>(pub PhantomData<T>);
216216

pallets/commitments/src/types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use sp_runtime::{
2929
RuntimeDebug,
3030
};
3131
use sp_std::{fmt::Debug, iter::once, prelude::*};
32-
use subtensor_macros::freeze_struct_ignore_ra;
32+
use subtensor_macros::freeze_struct;
3333

3434
/// Either underlying data blob if it is at most 32 bytes, or a hash of it. If the data is greater
3535
/// than 32-bytes then it will be truncated when encoding.
@@ -284,12 +284,12 @@ impl Default for Data {
284284
}
285285
}
286286

287-
#[freeze_struct_ignore_ra("1053e03f8a8f6a67")]
287+
#[freeze_struct("25c84048dcc90813")]
288288
#[derive(
289289
CloneNoBound, Encode, Decode, Eq, MaxEncodedLen, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo,
290290
)]
291291
#[codec(mel_bound())]
292-
#[cfg_attr(test, derive(frame_support::DefaultNoBound))]
292+
#[derive(frame_support::DefaultNoBound)]
293293
#[scale_info(skip_type_params(FieldLimit))]
294294
pub struct CommitmentInfo<FieldLimit: Get<u32>> {
295295
pub fields: BoundedVec<Data, FieldLimit>,

pallets/registry/src/types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use sp_runtime::{
3030
RuntimeDebug,
3131
};
3232
use sp_std::{fmt::Debug, iter::once, ops::Add, prelude::*};
33-
use subtensor_macros::freeze_struct_ignore_ra;
33+
use subtensor_macros::freeze_struct;
3434

3535
/// Either underlying data blob if it is at most 32 bytes, or a hash of it. If the data is greater
3636
/// than 32-bytes then it will be truncated when encoding.
@@ -279,12 +279,12 @@ impl TypeInfo for IdentityFields {
279279
///
280280
/// NOTE: This should be stored at the end of the storage item to facilitate the addition of extra
281281
/// fields in a backwards compatible way through a specialized `Decode` impl.
282-
#[freeze_struct_ignore_ra("fa02e2abde778fc4")]
282+
#[freeze_struct("70b183c8753429f1")]
283283
#[derive(
284284
CloneNoBound, Encode, Decode, Eq, MaxEncodedLen, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo,
285285
)]
286286
#[codec(mel_bound())]
287-
#[cfg_attr(test, derive(frame_support::DefaultNoBound))]
287+
#[derive(frame_support::DefaultNoBound)]
288288
#[scale_info(skip_type_params(FieldLimit))]
289289
pub struct IdentityInfo<FieldLimit: Get<u32>> {
290290
/// Additional fields of the identity that are not catered for with the struct's explicit

support/macros/build.rs

Lines changed: 0 additions & 9 deletions
This file was deleted.

support/macros/src/lib.rs

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,19 @@ use visitor::*;
99
/// Freezes the layout of a struct to the current hash of its fields, ensuring that future
1010
/// changes require updating the hash.
1111
///
12-
/// If you ever get in a loop where rust analyzer insists that the hash is wrong each time you
13-
/// update, but `cargo check` is passing, you should use [`freeze_struct_ignore_ra`] instead.
12+
/// ```
13+
/// use subtensor_macros::freeze_struct;
14+
///
15+
/// #[freeze_struct("13f75e4ea46b4e80")]
16+
/// #[derive(Copy, Clone, PartialEq, Eq)]
17+
/// pub struct MyStruct {
18+
/// pub a: u32,
19+
/// pub b: u64,
20+
/// }
21+
/// ```
1422
#[proc_macro_attribute]
1523
pub fn freeze_struct(attr: TokenStream, tokens: TokenStream) -> TokenStream {
16-
match freeze_struct_impl(attr, tokens, false) {
17-
Ok(item_struct) => item_struct.to_token_stream().into(),
18-
Err(err) => err.to_compile_error().into(),
19-
}
20-
}
21-
22-
/// More permissive version of [`freeze_struct`] that ignores the hash check when running in
23-
/// rust-analyzer since in some rare situations rust-analyzer will generate an incorrect hash code
24-
#[proc_macro_attribute]
25-
pub fn freeze_struct_ignore_ra(attr: TokenStream, tokens: TokenStream) -> TokenStream {
26-
match freeze_struct_impl(attr, tokens, true) {
24+
match freeze_struct_impl(attr, tokens) {
2725
Ok(item_struct) => item_struct.to_token_stream().into(),
2826
Err(err) => err.to_compile_error().into(),
2927
}
@@ -32,7 +30,6 @@ pub fn freeze_struct_ignore_ra(attr: TokenStream, tokens: TokenStream) -> TokenS
3230
fn freeze_struct_impl(
3331
attr: impl Into<TokenStream2>,
3432
tokens: impl Into<TokenStream2>,
35-
ignore_ra: bool,
3633
) -> Result<ItemStruct> {
3734
let attr = attr.into();
3835
let tokens = tokens.into();
@@ -49,16 +46,13 @@ fn freeze_struct_impl(
4946
expected hashcode: `#[freeze_struct(\"{calculated_hash_hex}\")]`"),
5047
));
5148
}
52-
let hash_lit = parse2::<LitStr>(attr)?;
53-
let provided_hash_hex = hash_lit.value().to_lowercase();
49+
50+
let parsed_attr = parse2::<LitStr>(attr)?;
51+
let provided_hash_hex = parsed_attr.value().to_lowercase();
5452

5553
let mut visitor = CleanDocComments::new();
5654
visit_item_struct_mut(&mut visitor, &mut item_clone);
5755

58-
if ignore_ra && is_rust_analyzer() {
59-
return Ok(item);
60-
}
61-
6256
if provided_hash_hex != calculated_hash_hex {
6357
return Err(Error::new_spanned(item,
6458
format!(
@@ -72,8 +66,3 @@ fn freeze_struct_impl(
7266
}
7367
Ok(item)
7468
}
75-
76-
/// Returns true if the current build is being run by rust-analyzer.
77-
fn is_rust_analyzer() -> bool {
78-
std::env!("RUSTC_WRAPPER").contains("rust-analyzer")
79-
}

support/macros/src/visitor.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use ahash::RandomState;
22
use std::hash::{BuildHasher, Hash, Hasher};
3-
use syn::{self, parse_quote, visit_mut::VisitMut};
3+
use syn::{parse_quote, visit_mut::VisitMut};
44

55
pub struct CleanDocComments;
66

@@ -12,7 +12,6 @@ impl CleanDocComments {
1212

1313
impl VisitMut for CleanDocComments {
1414
fn visit_attribute_mut(&mut self, attr: &mut syn::Attribute) {
15-
// Check if the attribute is a doc comment and remove it if it is
1615
if attr.path().is_ident("doc") {
1716
*attr = parse_quote!(#[doc = ""]);
1817
}

0 commit comments

Comments
 (0)