Skip to content

fix(swarm-derive): allow unreachable_code on uninhabited ToSwarm fields - #6602

Open
Saraswat123 wants to merge 1 commit into
libp2p:masterfrom
Saraswat123:unreachable-code-uninhabited-toswarm-6600
Open

fix(swarm-derive): allow unreachable_code on uninhabited ToSwarm fields#6602
Saraswat123 wants to merge 1 commit into
libp2p:masterfrom
Saraswat123:unreachable-code-uninhabited-toswarm-6600

Conversation

@Saraswat123

@Saraswat123 Saraswat123 commented Sep 4, 2026

Copy link
Copy Markdown

When a NetworkBehaviour field has a To Swarm type that's uninhabited like dummy Behaviour, whose ToSwarm = Infallible, the derive macro still generates a match arm for it in poll(). That arm can never actually run but it has to exist so the macro compiles when other fields do have real To Swarm types. Newer nightly compilers flag that dead arm as unreachable code, which fails the build for anyone compiling with D warnings.

The fix: "I Wrapped just that one generated call in #[allow(unreachable_code)]. This is the same fix the issue reporter suggested themselves nothing else in the generated code changes."

Testing, I Added a test combining a real behaviour (ping, inhabited ToSwarm) with dummy.Behaviour (uninhabited ToSwarm) through the derive macro, to prove the mixed case still compiles. Full swarm,derive test suite- 20/20 pass. cargo fmt, clippyp libp2p,swarm,derive, and clippy -p libp2p,swarm features macros all clean.

@Saraswat123 Saraswat123 changed the title Fixing swarm derive allow unreachable code on uninhabited to Swarm fields. fix(swarm-derive): allow unreachable_code on uninhabited ToSwarm fields Sep 4, 2026
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.

1 participant