Skip to content

Commit c8ba39f

Browse files
authored
error: Replace Never with std::convert::Infallible (#1158)
We define an `error::Never` type that is effectively identical to the `std::convert::Infallible` type--and `Infallible` has a clearer name and provides implementations for more common traits. Most importantly, it's less surprising for new contributors. This change removes our `Never` type and re-exports `Infallible` from the `linkerd_error` crate. There are no functional changes.
1 parent 268b3be commit c8ba39f

File tree

16 files changed

+36
-52
lines changed

16 files changed

+36
-52
lines changed

linkerd/app/core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub use linkerd_cache as cache;
1717
pub use linkerd_conditional::Conditional;
1818
pub use linkerd_detect as detect;
1919
pub use linkerd_dns;
20-
pub use linkerd_error::{Error, Never, Recover};
20+
pub use linkerd_error::{Error, Infallible, Recover};
2121
pub use linkerd_exp_backoff as exp_backoff;
2222
pub use linkerd_http_metrics as http_metrics;
2323
pub use linkerd_identity as identity;

linkerd/app/gateway/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use linkerd_app_core::{
1919
svc::{self, Param},
2020
tls,
2121
transport_header::SessionProtocol,
22-
Error, NameAddr, NameMatch, Never,
22+
Error, Infallible, NameAddr, NameMatch,
2323
};
2424
use linkerd_app_inbound::{
2525
direct::{ClientInfo, GatewayConnection, GatewayTransportHeader},
@@ -185,7 +185,7 @@ where
185185
.clone()
186186
.push_http_logical(resolve)
187187
.into_stack()
188-
.push_switch(Ok::<_, Never>, endpoint.into_stack())
188+
.push_switch(Ok::<_, Infallible>, endpoint.into_stack())
189189
.push(NewGateway::layer(local_id))
190190
.push(profiles::discover::layer(profiles, move |t: HttpTarget| {
191191
if allow_discovery.matches(t.target.name()) {
@@ -264,15 +264,15 @@ where
264264
SessionProtocol::Http2 => http::Version::H2,
265265
},
266266
})),
267-
None => Ok::<_, Never>(svc::Either::B(target)),
267+
None => Ok::<_, Infallible>(svc::Either::B(target)),
268268
},
269269
tcp.push_on_response(svc::BoxService::layer())
270270
.push(svc::BoxNewService::layer())
271271
.into_inner(),
272272
)
273273
.push_switch(
274274
|gw| match gw {
275-
GatewayConnection::TransportHeader(t) => Ok::<_, Never>(svc::Either::A(t)),
275+
GatewayConnection::TransportHeader(t) => Ok::<_, Infallible>(svc::Either::A(t)),
276276
GatewayConnection::Legacy(c) => Ok(svc::Either::B(c)),
277277
},
278278
legacy_http.into_inner(),

linkerd/app/inbound/src/direct.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use linkerd_app_core::{
66
tls,
77
transport::{self, metrics::SensorIo, ClientAddr, OrigDstAddr, Remote},
88
transport_header::{self, NewTransportHeaderServer, SessionProtocol, TransportHeader},
9-
Conditional, Error, NameAddr, Never,
9+
Conditional, Error, Infallible, NameAddr,
1010
};
1111
use std::{convert::TryFrom, fmt::Debug, net::SocketAddr};
1212
use thiserror::Error;
@@ -135,7 +135,7 @@ impl<N> Inbound<N> {
135135
.push_switch(
136136
|client: ClientInfo| {
137137
if client.header_negotiated() {
138-
Ok::<_, Never>(svc::Either::A(client))
138+
Ok::<_, Infallible>(svc::Either::A(client))
139139
} else {
140140
Ok(svc::Either::B(GatewayConnection::Legacy(client)))
141141
}

linkerd/app/inbound/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use linkerd_app_core::{
2828
proxy::tcp,
2929
serve, svc, tls,
3030
transport::{self, listen::Bind, ClientAddr, Local, OrigDstAddr, Remote, ServerAddr},
31-
Error, NameMatch, Never, ProxyRuntime,
31+
Error, Infallible, NameMatch, ProxyRuntime,
3232
};
3333
use std::{convert::TryFrom, fmt::Debug, future::Future, time::Duration};
3434
use tracing::{debug_span, info_span};
@@ -282,10 +282,10 @@ where
282282
detect
283283
.instrument(|_: &_| debug_span!("proxy"))
284284
.push_switch(
285-
move |t: T| {
285+
move |t: T| -> Result<_, Infallible> {
286286
let OrigDstAddr(addr) = t.param();
287287
if !disable_detect.contains(&addr.port()) {
288-
Ok::<_, Never>(svc::Either::A(t))
288+
Ok(svc::Either::A(t))
289289
} else {
290290
Ok(svc::Either::B(TcpAccept::port_skipped(t)))
291291
}

linkerd/app/outbound/src/http/endpoint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ mod test {
7373
io,
7474
proxy::api_resolve::Metadata,
7575
svc::{NewService, ServiceExt},
76-
Never,
76+
Infallible,
7777
};
7878
use std::net::SocketAddr;
7979

@@ -259,7 +259,7 @@ mod test {
259259
.fold(rsp, |rsp, orig_proto| {
260260
rsp.header(WAS_ORIG_PROTO, orig_proto)
261261
});
262-
future::ok::<_, Never>(rsp.body(hyper::Body::default()).unwrap())
262+
future::ok::<_, Infallible>(rsp.body(hyper::Body::default()).unwrap())
263263
});
264264

265265
let mut http = hyper::server::conn::Http::new();

linkerd/app/outbound/src/http/logical.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use linkerd_app_core::{
88
http,
99
resolve::map_endpoint,
1010
},
11-
retry, svc, Error, Never,
11+
retry, svc, Error, Infallible,
1212
};
1313
use tracing::debug_span;
1414

@@ -43,7 +43,7 @@ impl<E> Outbound<E> {
4343
let identity_disabled = rt.identity.is_none();
4444
let resolve = svc::stack(resolve.into_service())
4545
.check_service::<ConcreteAddr>()
46-
.push_request_filter(|c: Concrete| Ok::<_, Never>(c.resolve))
46+
.push_request_filter(|c: Concrete| Ok::<_, Infallible>(c.resolve))
4747
.push(svc::layer::mk(move |inner| {
4848
map_endpoint::Resolve::new(endpoint::FromMetadata { identity_disabled }, inner)
4949
}))

linkerd/app/outbound/src/ingress.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use linkerd_app_core::{
99
svc::{self, stack::Param},
1010
tls,
1111
transport::{OrigDstAddr, Remote, ServerAddr},
12-
AddrMatch, Error, NameAddr, Never,
12+
AddrMatch, Error, Infallible, NameAddr,
1313
};
1414
use thiserror::Error;
1515
use tracing::{debug_span, info_span};
@@ -153,7 +153,7 @@ impl Outbound<svc::BoxNewHttp<http::Endpoint>> {
153153
.push_switch(
154154
|Http { target, version }: Http<Target>| match target {
155155
Target::Override(target) => {
156-
Ok::<_, Never>(svc::Either::A(Http { target, version }))
156+
Ok::<_, Infallible>(svc::Either::A(Http { target, version }))
157157
}
158158
Target::Forward(OrigDstAddr(addr)) => Ok(svc::Either::B(http::Endpoint {
159159
addr: Remote(ServerAddr(addr)),

linkerd/app/outbound/src/switch_logical.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{endpoint::Endpoint, logical::Logical, tcp, transport::OrigDstAddr, Outbound};
2-
use linkerd_app_core::{io, profiles, svc, Error, Never};
2+
use linkerd_app_core::{io, profiles, svc, Error, Infallible};
33
use std::fmt;
44

55
impl<S> Outbound<S> {
@@ -29,7 +29,7 @@ impl<S> Outbound<S> {
2929
self.map_stack(|_, _, endpoint| {
3030
endpoint
3131
.push_switch(
32-
move |(profile, target): (Option<profiles::Receiver>, T)| -> Result<_, Never> {
32+
move |(profile, target): (Option<profiles::Receiver>, T)| -> Result<_, Infallible> {
3333
if let Some(rx) = profile {
3434
// If the profile provides an endpoint, then the target is single endpoint and
3535
// not a logical/load-balanced service.

linkerd/app/outbound/src/tcp/logical.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use linkerd_app_core::{
88
resolve::map_endpoint,
99
tcp,
1010
},
11-
svc, Conditional, Error, Never,
11+
svc, Conditional, Error, Infallible,
1212
};
1313
use tracing::debug_span;
1414

@@ -51,7 +51,7 @@ where
5151
let identity_disabled = rt.identity.is_none();
5252
let resolve = svc::stack(resolve.into_service())
5353
.check_service::<ConcreteAddr>()
54-
.push_request_filter(|c: Concrete| Ok::<_, Never>(c.resolve))
54+
.push_request_filter(|c: Concrete| Ok::<_, Infallible>(c.resolve))
5555
.push(svc::layer::mk(move |inner| {
5656
map_endpoint::Resolve::new(endpoint::FromMetadata { identity_disabled }, inner)
5757
}))

linkerd/error/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
#![forbid(unsafe_code)]
33
#![allow(clippy::inconsistent_struct_constructor)]
44

5-
mod never;
65
pub mod recover;
76

8-
pub use self::never::Never;
97
pub use self::recover::Recover;
8+
pub use std::convert::Infallible;
109

1110
pub type Error = Box<dyn std::error::Error + Send + Sync>;

0 commit comments

Comments
 (0)