Skip to content

Commit

Permalink
Work around rust-lang/rust#65863
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhoo committed Jun 6, 2020
1 parent 7dbac40 commit 062b880
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ debug=true
[patch.crates-io]
# https://github.com/tower-rs/tokio-tower/pull/6
# optional -- just a perf optimization
# comment this out if you want cargo doc to work!
tokio-tower = { git = "https://github.com/tower-rs/tokio-tower.git", branch = "no-box" }
6 changes: 6 additions & 0 deletions noria/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ where
type Response = hyper::body::Bytes;
type Error = failure::Error;

#[cfg(not(doc))]
type Future = impl Future<Output = Result<Self::Response, Self::Error>> + Send;
#[cfg(doc)]
type Future = crate::doc_mock::Future<Result<Self::Response, Self::Error>>;

fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
Expand Down Expand Up @@ -172,7 +175,10 @@ impl ControllerHandle<consensus::ZookeeperAuthority> {

// this alias is needed to work around -> impl Trait capturing _all_ lifetimes by default
// the A parameter is needed so it gets captured into the impl Trait
#[cfg(not(doc))]
type RpcFuture<A, R> = impl Future<Output = Result<R, failure::Error>>;
#[cfg(doc)]
type RpcFuture<A, R> = crate::doc_mock::FutureWithExtra<Result<R, failure::Error>, A>;

// Needed b/c of https://github.com/rust-lang/rust/issues/65442
async fn finalize<R, E>(
Expand Down
50 changes: 50 additions & 0 deletions noria/src/doc_mock.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//! This module exists entirely to work around https://github.com/rust-lang/rust/issues/65863
/// impl Discover.
///
/// https://github.com/rust-lang/rust/issues/65863
pub struct Discover<S>(std::marker::PhantomData<S>);

impl<S> tower_discover::Discover for Discover<S> {
type Key = usize;
type Service = S;
type Error = tokio::io::Error;

fn poll_discover(
self: std::pin::Pin<&mut Self>,
_: &mut std::task::Context<'_>,
) -> std::task::Poll<Result<tower_discover::Change<Self::Key, Self::Service>, Self::Error>>
{
loop {}
}
}

/// impl Future.
///
/// https://github.com/rust-lang/rust/issues/65863
pub struct Future<O>(std::marker::PhantomData<O>);

impl<O> std::future::Future for Future<O> {
type Output = O;
fn poll(
self: std::pin::Pin<&mut Self>,
_: &mut std::task::Context<'_>,
) -> std::task::Poll<Self::Output> {
loop {}
}
}

/// impl Future.
///
/// https://github.com/rust-lang/rust/issues/65863
pub struct FutureWithExtra<O, T>(std::marker::PhantomData<O>, std::marker::PhantomData<T>);

impl<O, T> std::future::Future for FutureWithExtra<O, T> {
type Output = O;
fn poll(
self: std::pin::Pin<&mut Self>,
_: &mut std::task::Context<'_>,
) -> std::task::Poll<Self::Output> {
loop {}
}
}
2 changes: 2 additions & 0 deletions noria/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ pub mod channel;
#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/57411
pub mod consensus;
#[doc(hidden)]
pub mod doc_mock;
#[doc(hidden)]
#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/57411
pub mod internal;

Expand Down
13 changes: 12 additions & 1 deletion noria/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,11 @@ type InnerService = multiplex::Client<
impl Service<()> for Endpoint {
type Response = InnerService;
type Error = tokio::io::Error;

#[cfg(not(doc))]
type Future = impl Future<Output = Result<Self::Response, Self::Error>>;
#[cfg(doc)]
type Future = crate::doc_mock::Future<Result<Self::Response, Self::Error>>;

fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
Expand Down Expand Up @@ -256,16 +260,19 @@ fn make_table_discover(addr: SocketAddr) -> Discover {
}

// Unpin + Send bounds are needed due to https://github.com/rust-lang/rust/issues/55997
#[cfg(not(doc))]
type Discover = impl tower_discover::Discover<Key = usize, Service = InnerService, Error = tokio::io::Error>
+ Unpin
+ Send;
#[cfg(doc)]
type Discover = crate::doc_mock::Discover<InnerService>;

pub(crate) type TableRpc = Buffer<
ConcurrencyLimit<Balance<Discover, Tagged<LocalOrNot<Input>>>>,
Tagged<LocalOrNot<Input>>,
>;

/// A failed [`SyncTable`] operation.
/// A failed [`Table`] operation.
#[derive(Debug, Fail)]
pub enum TableError {
/// The wrong number of columns was given when inserting a row.
Expand Down Expand Up @@ -577,7 +584,11 @@ impl Table {
impl Service<Vec<TableOperation>> for Table {
type Error = TableError;
type Response = <TableRpc as Service<Tagged<LocalOrNot<Input>>>>::Response;

#[cfg(not(doc))]
type Future = impl Future<Output = Result<Tagged<()>, TableError>> + Send;
#[cfg(doc)]
type Future = crate::doc_mock::Future<Result<Tagged<()>, TableError>>;

fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
for s in &mut self.shards {
Expand Down
13 changes: 12 additions & 1 deletion noria/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ type InnerService = multiplex::Client<
impl Service<()> for Endpoint {
type Response = InnerService;
type Error = tokio::io::Error;

#[cfg(not(doc))]
type Future = impl Future<Output = Result<Self::Response, Self::Error>>;
#[cfg(doc)]
type Future = crate::doc_mock::Future<Result<Self::Response, Self::Error>>;

fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
Expand Down Expand Up @@ -81,14 +85,17 @@ fn make_views_discover(addr: SocketAddr) -> Discover {
}

// Unpin + Send bounds are needed due to https://github.com/rust-lang/rust/issues/55997
#[cfg(not(doc))]
type Discover = impl tower_discover::Discover<Key = usize, Service = InnerService, Error = tokio::io::Error>
+ Unpin
+ Send;
#[cfg(doc)]
type Discover = crate::doc_mock::Discover<InnerService>;

pub(crate) type ViewRpc =
Buffer<ConcurrencyLimit<Balance<Discover, Tagged<ReadQuery>>>, Tagged<ReadQuery>>;

/// A failed [`SyncView`] operation.
/// A failed [`View`] operation.
#[derive(Debug, Fail)]
pub enum ViewError {
/// The given view is not yet available.
Expand Down Expand Up @@ -233,7 +240,11 @@ use self::results::{Results, Row};
impl Service<(Vec<Vec<DataType>>, bool)> for View {
type Response = Vec<Results>;
type Error = ViewError;

#[cfg(not(doc))]
type Future = impl Future<Output = Result<Self::Response, Self::Error>> + Send;
#[cfg(doc)]
type Future = crate::doc_mock::Future<Result<Self::Response, Self::Error>>;

fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
for s in &mut self.shards {
Expand Down

0 comments on commit 062b880

Please sign in to comment.