alloy-rs / alloy

Transports, Middleware, and Networks for the Alloy project
https://alloy.rs
Apache License 2.0
614 stars 222 forks source link

[Bug] alloy-json-abi wrong version is selected causing serde to fail in compile-time. #1546

Closed dgrr closed 2 hours ago

dgrr commented 3 hours ago

Component

serde

What version of Alloy are you on?

alloy main branch

Operating System

macOS (Apple Silicon)

Describe the bug

Hello,

I've noticed an issue in some of my repos in which I use alloy. I suspect that the error is related to cargo selecting a different version of alloy. I was not able to reproduce the error in my repos, but I managed to reproduced by cloning alloy and running cargo check. The output is the following:

➜  alloy git:(main) cargo check
    Checking alloy-json-rpc v0.5.2 (/private/tmp/alloy/crates/json-rpc)
    Checking alloy-consensus v0.5.2 (/private/tmp/alloy/crates/consensus)
    Checking hyper v1.5.0
    Checking aws-runtime v1.4.3
    Checking alloy-json-abi v0.8.9
    Checking alloy-rpc-types-mev v0.5.2 (/private/tmp/alloy/crates/rpc-types-mev)
    Checking alloy-rpc-types-anvil v0.5.2 (/private/tmp/alloy/crates/rpc-types-anvil)
    Checking alloy-rpc-types-debug v0.5.2 (/private/tmp/alloy/crates/rpc-types-debug)
    Checking alloy-eip5792 v0.5.2 (/private/tmp/alloy/crates/eip5792)
error[E0424]: expected value, found module `self`
  --> /Users/dario/.cargo/registry/src/index.crates.io-6f17d22bba15001f/alloy-json-abi-0.8.9/src/item.rs:70:42
   |
19 |             #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
   |                                                         --------- this function has a `self` parameter, but a macro invocation can only access identifiers it receives from parameters
...
70 |         #[serde(default, flatten, with = "serde_state_mutability_compat")]
   |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `self` value is a keyword only available in methods with a `self` parameter

error[E0425]: cannot find value `__s` in this scope
  --> /Users/dario/.cargo/registry/src/index.crates.io-6f17d22bba15001f/alloy-json-abi-0.8.9/src/item.rs:70:42
   |
70 |         #[serde(default, flatten, with = "serde_state_mutability_compat")]
   |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0424]: expected value, found module `self`
  --> /Users/dario/.cargo/registry/src/index.crates.io-6f17d22bba15001f/alloy-json-abi-0.8.9/src/item.rs:78:42
   |
19 |             #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
   |                                                         --------- this function has a `self` parameter, but a macro invocation can only access identifiers it receives from parameters
...
78 |         #[serde(default, flatten, with = "serde_state_mutability_compat")]
   |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `self` value is a keyword only available in methods with a `self` parameter

error[E0425]: cannot find value `__s` in this scope
  --> /Users/dario/.cargo/registry/src/index.crates.io-6f17d22bba15001f/alloy-json-abi-0.8.9/src/item.rs:78:42
   |
78 |         #[serde(default, flatten, with = "serde_state_mutability_compat")]
   |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0424]: expected value, found module `self`
  --> /Users/dario/.cargo/registry/src/index.crates.io-6f17d22bba15001f/alloy-json-abi-0.8.9/src/item.rs:86:42
   |
19 |             #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
   |                                                         --------- this function has a `self` parameter, but a macro invocation can only access identifiers it receives from parameters
...
86 |         #[serde(default, flatten, with = "serde_state_mutability_compat")]
   |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `self` value is a keyword only available in methods with a `self` parameter

error[E0425]: cannot find value `__s` in this scope
  --> /Users/dario/.cargo/registry/src/index.crates.io-6f17d22bba15001f/alloy-json-abi-0.8.9/src/item.rs:86:42
   |
86 |         #[serde(default, flatten, with = "serde_state_mutability_compat")]
   |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0424]: expected value, found module `self`
   --> /Users/dario/.cargo/registry/src/index.crates.io-6f17d22bba15001f/alloy-json-abi-0.8.9/src/item.rs:100:42
    |
19  |             #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
    |                                                         --------- this function has a `self` parameter, but a macro invocation can only access identifiers it receives from parameters
...
100 |         #[serde(default, flatten, with = "serde_state_mutability_compat")]
    |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `self` value is a keyword only available in methods with a `self` parameter

error[E0425]: cannot find value `__s` in this scope
   --> /Users/dario/.cargo/registry/src/index.crates.io-6f17d22bba15001f/alloy-json-abi-0.8.9/src/item.rs:100:42
    |
100 |         #[serde(default, flatten, with = "serde_state_mutability_compat")]
    |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value `__deserializer` in this scope
  --> /Users/dario/.cargo/registry/src/index.crates.io-6f17d22bba15001f/alloy-json-abi-0.8.9/src/item.rs:93:36
   |
93 |         #[serde(deserialize_with = "validate_identifier")]
   |                                    ^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value `__deserializer` in this scope
   --> /Users/dario/.cargo/registry/src/index.crates.io-6f17d22bba15001f/alloy-json-abi-0.8.9/src/item.rs:107:36
    |
107 |         #[serde(deserialize_with = "validate_identifier")]
    |                                    ^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value `__deserializer` in this scope
   --> /Users/dario/.cargo/registry/src/index.crates.io-6f17d22bba15001f/alloy-json-abi-0.8.9/src/item.rs:120:36
    |
120 |         #[serde(deserialize_with = "validate_identifier")]
    |                                    ^^^^^^^^^^^^^^^^^^^^^ not found in this scope

    Checking alloy-transport v0.5.2 (/private/tmp/alloy/crates/transport)
Some errors have detailed explanations: E0424, E0425.
For more information about an error, try `rustc --explain E0424`.
error: could not compile `alloy-json-abi` (lib) due to 11 previous errors
warning: build failed, waiting for other jobs to finish...
ivanrg99 commented 3 hours ago

Same issue if you create an empty project with cargo new sample_project, then cargo add alloy --features full and cargo check after.

Also happens on Ubuntu x64

laibe commented 3 hours ago

can confirm, same issues on macOS as described by @dgrr

rustup --version
rustup 1.27.1 (54dd3d00f 2024-04-24)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.80.0 (051478957 2024-07-21)`
prestwich commented 3 hours ago

cargo update && cargo check will now produce this for every project i've tried

> $ rustup --version
rustup 1.27.1 (54dd3d00f 2024-04-24)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.82.0 (f6e511eec 2024-10-15)
prestwich commented 2 hours ago

this appears to be a breaking change in serde, possibly accidental

It can be resolved as follows

cargo update -p serde --precise 1.0.210 && cargo update -p serde_derive --precise 1.0.210 && cargo c
DaniPopes commented 2 hours ago

Duplicate of https://github.com/alloy-rs/core/issues/778. See https://github.com/alloy-rs/core/issues/778#issuecomment-2428939631.