Skip to content

Commit 0c34d9f

Browse files
authored
chore: deprecate void crate (#5676)
## Description <!-- Please write a summary of your changes and why you made them. This section will appear as the commit message after merging. Please craft it accordingly. For a quick primer on good commit messages, check out this blog post: https://cbea.ms/git-commit/ Please include any relevant issues in here, for example: Related https://github.com/libp2p/rust-libp2p/issues/ABCD. Fixes https://github.com/libp2p/rust-libp2p/issues/XYZ. --> The `void` crate provides a `Void` type that is conceptually equivalent to the [`never` type(!)](https://doc.rust-lang.org/std/primitive.never.html). This PR tries to remove `void` crate from the dependency tree by replacing `void::Void` with [`std::convert::Infallible`](https://doc.rust-lang.org/std/convert/enum.Infallible.html) that will eventually become an alias of the `never` type(!) > This enum has the same role as [the ! “never” type](https://doc.rust-lang.org/std/primitive.never.html), which is unstable in this version of Rust. When ! is stabilized, we plan to make Infallible a type alias to it: ## Notes & open questions <!-- Any notes, remarks or open questions you have to make about the PR which don't need to go into the final commit message. --> ## Change checklist <!-- Please add a Changelog entry in the appropriate crates and bump the crate versions if needed. See <https://github.com/libp2p/rust-libp2p/blob/master/docs/release.md#development-between-releases>--> - [x] I have performed a self-review of my own code - [ ] I have made corresponding changes to the documentation - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] A changelog entry has been made in the appropriate crates
1 parent 4192fc3 commit 0c34d9f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+168
-193
lines changed

Cargo.lock

-26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ smallvec = "1.13.2"
3131
thiserror = "1.0"
3232
tracing = { workspace = true }
3333
unsigned-varint = { workspace = true }
34-
void = "1"
3534

3635
[dev-dependencies]
3736
async-std = { version = "1.6.2", features = ["attributes"] }

core/src/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,13 @@ pub use upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo};
6666
#[derive(Debug, thiserror::Error)]
6767
#[error(transparent)]
6868
pub struct DecodeError(quick_protobuf::Error);
69+
70+
pub mod util {
71+
use std::convert::Infallible;
72+
73+
/// A safe version of [`std::intrinsics::unreachable`].
74+
#[inline(always)]
75+
pub fn unreachable(x: Infallible) -> ! {
76+
match x {}
77+
}
78+
}

core/src/upgrade/denied.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
use crate::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo};
2222
use futures::future;
23+
use std::convert::Infallible;
2324
use std::iter;
24-
use void::Void;
2525

2626
/// Dummy implementation of `UpgradeInfo`/`InboundUpgrade`/`OutboundUpgrade` that doesn't support
2727
/// any protocol.
@@ -38,8 +38,8 @@ impl UpgradeInfo for DeniedUpgrade {
3838
}
3939

4040
impl<C> InboundUpgrade<C> for DeniedUpgrade {
41-
type Output = Void;
42-
type Error = Void;
41+
type Output = Infallible;
42+
type Error = Infallible;
4343
type Future = future::Pending<Result<Self::Output, Self::Error>>;
4444

4545
fn upgrade_inbound(self, _: C, _: Self::Info) -> Self::Future {
@@ -48,8 +48,8 @@ impl<C> InboundUpgrade<C> for DeniedUpgrade {
4848
}
4949

5050
impl<C> OutboundUpgrade<C> for DeniedUpgrade {
51-
type Output = Void;
52-
type Error = Void;
51+
type Output = Infallible;
52+
type Error = Infallible;
5353
type Future = future::Pending<Result<Self::Output, Self::Error>>;
5454

5555
fn upgrade_outbound(self, _: C, _: Self::Info) -> Self::Future {

core/src/upgrade/pending.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
use crate::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo};
2323
use futures::future;
24+
use std::convert::Infallible;
2425
use std::iter;
25-
use void::Void;
2626

2727
/// Implementation of [`UpgradeInfo`], [`InboundUpgrade`] and [`OutboundUpgrade`] that always
2828
/// returns a pending upgrade.
@@ -53,8 +53,8 @@ impl<C, P> InboundUpgrade<C> for PendingUpgrade<P>
5353
where
5454
P: AsRef<str> + Clone,
5555
{
56-
type Output = Void;
57-
type Error = Void;
56+
type Output = Infallible;
57+
type Error = Infallible;
5858
type Future = future::Pending<Result<Self::Output, Self::Error>>;
5959

6060
fn upgrade_inbound(self, _: C, _: Self::Info) -> Self::Future {
@@ -66,8 +66,8 @@ impl<C, P> OutboundUpgrade<C> for PendingUpgrade<P>
6666
where
6767
P: AsRef<str> + Clone,
6868
{
69-
type Output = Void;
70-
type Error = Void;
69+
type Output = Infallible;
70+
type Error = Infallible;
7171
type Future = future::Pending<Result<Self::Output, Self::Error>>;
7272

7373
fn upgrade_outbound(self, _: C, _: Self::Info) -> Self::Future {

core/src/upgrade/ready.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
use crate::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo};
2323
use futures::future;
24+
use std::convert::Infallible;
2425
use std::iter;
25-
use void::Void;
2626

2727
/// Implementation of [`UpgradeInfo`], [`InboundUpgrade`] and [`OutboundUpgrade`] that directly yields the substream.
2828
#[derive(Debug, Copy, Clone)]
@@ -53,7 +53,7 @@ where
5353
P: AsRef<str> + Clone,
5454
{
5555
type Output = C;
56-
type Error = Void;
56+
type Error = Infallible;
5757
type Future = future::Ready<Result<Self::Output, Self::Error>>;
5858

5959
fn upgrade_inbound(self, stream: C, _: Self::Info) -> Self::Future {
@@ -66,7 +66,7 @@ where
6666
P: AsRef<str> + Clone,
6767
{
6868
type Output = C;
69-
type Error = Void;
69+
type Error = Infallible;
7070
type Future = future::Ready<Result<Self::Output, Self::Error>>;
7171

7272
fn upgrade_outbound(self, stream: C, _: Self::Info) -> Self::Future {

examples/file-sharing/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ futures = { workspace = true }
1616
libp2p = { path = "../../libp2p", features = [ "tokio", "cbor", "dns", "kad", "noise", "macros", "request-response", "tcp", "websocket", "yamux"] }
1717
tracing = { workspace = true }
1818
tracing-subscriber = { workspace = true, features = ["env-filter"] }
19-
void = "1.0.2"
2019

2120
[lints]
2221
workspace = true

identity/Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@ sec1 = { version = "0.7", default-features = false, optional = true }
2626
serde = { version = "1", optional = true, features = ["derive"] }
2727
sha2 = { version = "0.10.8", optional = true }
2828
thiserror = { version = "1.0", optional = true }
29-
void = { version = "1.0", optional = true }
3029
zeroize = { version = "1.8", optional = true }
3130

3231
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
3332
ring = { workspace = true, features = ["alloc", "std"], optional = true }
3433

3534
[features]
3635
secp256k1 = ["dep:libsecp256k1", "dep:asn1_der", "dep:sha2", "dep:hkdf", "dep:zeroize"]
37-
ecdsa = ["dep:p256", "dep:void", "dep:zeroize", "dep:sec1", "dep:sha2", "dep:hkdf"]
36+
ecdsa = ["dep:p256", "dep:zeroize", "dep:sec1", "dep:sha2", "dep:hkdf"]
3837
rsa = ["dep:ring", "dep:asn1_der", "dep:rand", "dep:zeroize"]
3938
ed25519 = ["dep:ed25519-dalek", "dep:zeroize", "dep:sha2", "dep:hkdf"]
4039
peerid = ["dep:multihash", "dep:bs58", "dep:thiserror", "dep:sha2", "dep:hkdf"]

identity/src/ecdsa.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use p256::{
3232
EncodedPoint,
3333
};
3434
use sec1::{DecodeEcPrivateKey, EncodeEcPrivateKey};
35-
use void::Void;
35+
use std::convert::Infallible;
3636
use zeroize::Zeroize;
3737

3838
/// An ECDSA keypair generated using `secp256r1` curve.
@@ -182,7 +182,10 @@ impl PublicKey {
182182
/// Try to decode a public key from a DER encoded byte buffer as defined by SEC1 standard.
183183
pub fn try_decode_der(k: &[u8]) -> Result<PublicKey, DecodingError> {
184184
let buf = Self::del_asn1_header(k).ok_or_else(|| {
185-
DecodingError::failed_to_parse::<Void, _>("ASN.1-encoded ecdsa p256 public key", None)
185+
DecodingError::failed_to_parse::<Infallible, _>(
186+
"ASN.1-encoded ecdsa p256 public key",
187+
None,
188+
)
186189
})?;
187190
Self::try_from_bytes(buf)
188191
}

misc/allow-block-list/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ categories = ["network-programming", "asynchronous"]
1313
libp2p-core = { workspace = true }
1414
libp2p-swarm = { workspace = true }
1515
libp2p-identity = { workspace = true, features = ["peerid"] }
16-
void = "1"
1716

1817
[dev-dependencies]
1918
async-std = { version = "1.12.0", features = ["attributes"] }

misc/allow-block-list/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ use libp2p_swarm::{
6969
THandlerInEvent, THandlerOutEvent, ToSwarm,
7070
};
7171
use std::collections::{HashSet, VecDeque};
72+
use std::convert::Infallible;
7273
use std::fmt;
7374
use std::task::{Context, Poll, Waker};
74-
use void::Void;
7575

7676
/// A [`NetworkBehaviour`] that can act as an allow or block list.
7777
#[derive(Default, Debug)]
@@ -222,7 +222,7 @@ where
222222
S: Enforce,
223223
{
224224
type ConnectionHandler = dummy::ConnectionHandler;
225-
type ToSwarm = Void;
225+
type ToSwarm = Infallible;
226226

227227
fn handle_established_inbound_connection(
228228
&mut self,
@@ -273,7 +273,7 @@ where
273273
) {
274274
// TODO: remove when Rust 1.82 is MSRV
275275
#[allow(unreachable_patterns)]
276-
void::unreachable(event)
276+
libp2p_core::util::unreachable(event)
277277
}
278278

279279
fn poll(

misc/connection-limits/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ categories = ["network-programming", "asynchronous"]
1313
libp2p-core = { workspace = true }
1414
libp2p-swarm = { workspace = true }
1515
libp2p-identity = { workspace = true, features = ["peerid"] }
16-
void = "1"
1716

1817
[dev-dependencies]
1918
async-std = { version = "1.12.0", features = ["attributes"] }

0 commit comments

Comments
 (0)