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

Disambiguate calls to NetworkBehaviour::inject_event #1543

Merged

Conversation

thomaseizinger
Copy link
Contributor

There is a gnarly edge-case with the custom-derive where rustc cannot disambiguate the call if:

  • The NetworkBehaviourEventProcess trait is imported
  • We nest NetworkBehaviours that use the custom-derive

Without this patch, the test errors with:

error[E0034]: multiple applicable items in scope
   --> misc/core-derive/tests/test.rs:219:14
    |
219 |     #[derive(NetworkBehaviour)]
    |              ^^^^^^^^^^^^^^^^ multiple `inject_event` found
    |
note: candidate #1 is defined in an impl of the trait `libp2p_swarm::behaviour::NetworkBehaviourEventProcess` for the type `nested_derives_with_import::Foo`
   --> misc/core-derive/tests/test.rs:225:9
    |
225 |         fn inject_event(&mut self, _: libp2p::ping::PingEvent) {
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: candidate #2 is defined in an impl of the trait `libp2p_swarm::behaviour::NetworkBehaviour` for the type `nested_derives_with_import::Foo`
   --> misc/core-derive/tests/test.rs:213:14
    |
213 |     #[derive(NetworkBehaviour)]
    |              ^^^^^^^^^^^^^^^^
help: disambiguate the method call for candidate #1
    |
219 |     #[derive(libp2p_swarm::behaviour::NetworkBehaviourEventProcess::inject_event(&mut NetworkBehaviour, NetworkBehaviour, NetworkBehaviour, NetworkBehaviour))]
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: disambiguate the method call for candidate #2
    |
219 |     #[derive(libp2p_swarm::behaviour::NetworkBehaviour::inject_event(&mut NetworkBehaviour, NetworkBehaviour, NetworkBehaviour, NetworkBehaviour))]
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

@thomaseizinger thomaseizinger changed the title Disamiguate calls to NetworkBehaviour::inject_event Disambiguate calls to NetworkBehaviour::inject_event Apr 6, 2020
There is a gnarly edge-case with the custom-derive where rustc
cannot disambiguate the call if:

- The NetworkBehaviourEventProcess trait is imported
- We nest NetworkBehaviours that use the custom-derive
@thomaseizinger thomaseizinger force-pushed the nested-derived-network-behaviours branch from d0e5f26 to 2499dbd Compare April 6, 2020 06:38
Copy link
Member

@tomaka tomaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit

misc/core-derive/src/lib.rs Outdated Show resolved Hide resolved
@tomaka
Copy link
Member

tomaka commented Apr 9, 2020

I pushed a fix on your branch.

@tomaka tomaka merged commit 803eb10 into libp2p:master Apr 9, 2020
@thomaseizinger
Copy link
Contributor Author

Thanks! Sorry, I didn't realize the build was broken :s

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

Successfully merging this pull request may close these issues.

2 participants