Skip to content

Commit

Permalink
lint: Make latest rust version happy
Browse files Browse the repository at this point in the history
Unfortunately this required introducing a suppression of a warning:
`#[allow(non_local_definitions)]` since the `Serialize` derive-macro
declares a non-local implementation of `Block` that (probably) doesn't
work together with `#[readonly::make]`, as the `Serialize` adds a
function that `readonly::make` doesn't allow other modules to be shown.
At least, that's my understanding. Either that, or the `readonly::make`
macro defines a local scope for the `Block` data structure that doesn't
work with the scope of the derive-macro.

Full error message:

warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
   --> src/models/blockchain/block/mod.rs:124:24
    |
122 | #[readonly::make]
    | ----------------- `ReadOnlyBlock` is not local
123 | #[allow(non_local_definitions)] // needed for [Deserialize] macro from serde
124 | #[derive(Clone, Debug, Serialize, Deserialize, BFieldCodec, GetSize)]
    |                        ^--------
    |                        |
    |                        `Serialize` is not local
    |                        move the `impl` block outside of this constant `_` and up 2 bodies
    |
    = note: the derive macro `Serialize` defines the non-local `impl`, and may need to be changed
    = note: the derive macro `Serialize` may come from an old version of the `serde_derive` crate, try updating your dependency with `cargo update -p serde_derive`
    = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
    = note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration for the purpose of this lint
    = note: `#[warn(non_local_definitions)]` on by default
    = note: this warning originates in the derive macro `Serialize` (in Nightly builds, run with -Z macro-backtrace for more info)
  • Loading branch information
Sword-Smith committed Oct 18, 2024
1 parent 3bd63de commit 7b472ed
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/models/blockchain/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ pub enum BlockProof {
/// // mutate an internal field.
/// block.kernel.header.nonce = nonce;
/// ```

// ## About the private `digest` field:
//
// The `digest` field represents the `Block` hash. It is an optimization so
Expand Down Expand Up @@ -118,8 +117,9 @@ pub enum BlockProof {
// exist no impls for `OnceLock<_>` so derive fails.
//
// A unit test-suite exists in module tests::digest_encapsulation.
#[readonly::make]
#[allow(non_local_definitions)] // needed for [Deserialize] macro from serde
#[derive(Clone, Debug, Serialize, Deserialize, BFieldCodec, GetSize)]
#[readonly::make]
pub struct Block {
/// Everything but the proof
pub kernel: BlockKernel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,6 @@ impl BasicSnippet for TransactionKernelMastHash {
mod tests {
use std::collections::HashMap;

use crate::models::blockchain::shared::Hash;
use crate::models::blockchain::transaction::transaction_kernel::transaction_kernel_tests::pseudorandom_transaction_kernel;
use crate::prelude::twenty_first;
use num_traits::One;
use rand::rngs::StdRng;
use rand::Rng;
Expand All @@ -226,7 +223,10 @@ mod tests {
use twenty_first::util_types::algebraic_hasher::Domain;

use super::*;
use crate::models::blockchain::shared::Hash;
use crate::models::blockchain::transaction::transaction_kernel::transaction_kernel_tests::pseudorandom_transaction_kernel;
use crate::models::proof_abstractions::mast_hash::MastHash;
use crate::prelude::twenty_first;

impl TransactionKernelMastHash {
pub(crate) fn input_state_with_kernel_in_memory(
Expand Down
2 changes: 1 addition & 1 deletion src/models/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2346,7 +2346,7 @@ mod global_state_tests {
"Exactly {expected_num_blocks_at_tip_height} blocks at height must be known"
);
assert_eq!(
expected_parent.hash(),
expected_parent_digest,
global_state
.chain
.archival_state()
Expand Down

0 comments on commit 7b472ed

Please sign in to comment.