From 740a2e02357869498e840c14797971930da00e1e Mon Sep 17 00:00:00 2001 From: Max Inden Date: Wed, 19 Aug 2020 17:44:41 +0200 Subject: [PATCH] protocols/kad/src/kbuckets: Explicitly convert u8 to usize (#1716) Compiling libp2p-kad for `--target wasm32-unknown-unknown` fails with the cryptic error message `cannot infer type for type `usize``. Explicitly converting to `usize` solves the issue. Co-authored-by: Andronik Ordian --- protocols/kad/CHANGELOG.md | 5 +++++ protocols/kad/Cargo.toml | 2 +- protocols/kad/src/kbucket.rs | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index 4284ca5bf6d..9504673b972 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -1,3 +1,8 @@ +# 0.22.1 [2020-08-19] + +- Explicitly convert from u8 to usize in `BucketIndex::range` to prevent type + inference issues ([PR 1716](https://github.com/libp2p/rust-libp2p/pull/1716)). + # 0.22.0 [2020-08-18] - Store addresses in provider records. diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index fb5d47ed950..eb60d59089f 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-kad" edition = "2018" description = "Kademlia protocol for libp2p" -version = "0.22.0" +version = "0.22.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/protocols/kad/src/kbucket.rs b/protocols/kad/src/kbucket.rs index 3de74fad6bf..6ab7e27af6a 100644 --- a/protocols/kad/src/kbucket.rs +++ b/protocols/kad/src/kbucket.rs @@ -120,7 +120,7 @@ impl BucketIndex { /// included in the bucket for this index. fn range(&self) -> (Distance, Distance) { let min = Distance(U256::pow(U256::from(2), U256::from(self.0))); - if self.0 == u8::MAX.into() { + if self.0 == usize::from(u8::MAX) { (min, Distance(U256::MAX)) } else { let max = Distance(U256::pow(U256::from(2), U256::from(self.0 + 1)) - 1);