Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in derive macro NetworkBehaviour #5833

Closed
Slava2001 opened this issue Jan 28, 2025 · 1 comment · Fixed by #5839
Closed

Error in derive macro NetworkBehaviour #5833

Slava2001 opened this issue Jan 28, 2025 · 1 comment · Fixed by #5839

Comments

@Slava2001
Copy link
Contributor

Summary

The code below does not compile:

use error_stack::Result;
use libp2p::{gossipsub, swarm::NetworkBehaviour};

#[derive(NetworkBehaviour)]
struct MyBehaviour {
    gossipsub: gossipsub::Behaviour,
}

fn main() {
    println!("Hello, world!");
}

This happens because use error_stack::Result; redefines Result and the code generated by the macro #[derive(NetworkBehaviour)] becomes invalid.

Expected behavior

The code should compile.

Actual behavior

The code does not compile.

Relevant log output

error[E0308]: mismatched types
 --> src\main.rs:4:10
  |
4 | #[derive(NetworkBehaviour)]
  |          ^^^^^^^^^^^^^^^^
  |          |
  |          expected `Result<(), ...>`, found `Result<(), Error>`
  |          expected `Result<(), error_stack::Report<std::fmt::Error>>` because of return type
  |
  = note: expected enum `Result<_, error_stack::Report<std::fmt::Error>>`
             found enum `Result<_, std::fmt::Error>`

Possible Solution

Replace the Result in the ./swarm-derive/src/lib.rs file with std::result::Result.

Version

master, commit: 3ce976d8b7f7e2e636cc09844f81a88ee33d780a

Would you like to work on fixing this bug?

Yes

@elenaf9
Copy link
Contributor

elenaf9 commented Jan 28, 2025

Replace the Result in the ./swarm-derive/src/lib.rs file with std::result::Result.

Sounds good, a PR would be appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants