http-rs / http-types

Common types for HTTP operations

Home Page:https://docs.rs/http-types

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Latest `http-types` fails to compile in empty project

AlbertMarashi opened this issue · comments

Reproduction

cargo new bug --lib

Add this to Cargo.toml dependencies

http-types = "2.12.0"

Error

    Checking http-types v2.12.0
error[E0433]: failed to resolve: use of undeclared crate or module `io`
  --> /Users/albert/.cargo/registry/src/github.com-1ecc6299db9ec823/http-types-2.12.0/src/upgrade/connection.rs:36:15
   |
36 |     ) -> Poll<io::Result<usize>> {
   |               ^^ use of undeclared crate or module `io`

error[E0433]: failed to resolve: use of undeclared crate or module `io`
  --> /Users/albert/.cargo/registry/src/github.com-1ecc6299db9ec823/http-types-2.12.0/src/upgrade/connection.rs:46:15
   |
46 |     ) -> Poll<io::Result<usize>> {
   |               ^^ use of undeclared crate or module `io`

error[E0433]: failed to resolve: use of undeclared crate or module `io`
  --> /Users/albert/.cargo/registry/src/github.com-1ecc6299db9ec823/http-types-2.12.0/src/upgrade/connection.rs:50:75
   |
50 |     fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
   |                                                                           ^^ use of undeclared crate or module `io`

error[E0433]: failed to resolve: use of undeclared crate or module `io`
  --> /Users/albert/.cargo/registry/src/github.com-1ecc6299db9ec823/http-types-2.12.0/src/upgrade/connection.rs:54:75
   |
54 |     fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
   |                                                                           ^^ use of undeclared crate or module `io`

error[E0405]: cannot find trait `AsyncRead` in this scope
  --> /Users/albert/.cargo/registry/src/github.com-1ecc6299db9ec823/http-types-2.12.0/src/upgrade/connection.rs:21:12
   |
21 |         T: AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static,
   |            ^^^^^^^^^ not found in this scope
   |
help: consider importing this trait
   |
1  | use futures_lite::AsyncRead;
   |

error[E0405]: cannot find trait `AsyncWrite` in this scope
  --> /Users/albert/.cargo/registry/src/github.com-1ecc6299db9ec823/http-types-2.12.0/src/upgrade/connection.rs:21:24
   |
21 |         T: AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static,
   |                        ^^^^^^^^^^ not found in this scope
   |
help: consider importing this trait
   |
1  | use futures_lite::AsyncWrite;
   |

error[E0405]: cannot find trait `AsyncRead` in this scope
  --> /Users/albert/.cargo/registry/src/github.com-1ecc6299db9ec823/http-types-2.12.0/src/upgrade/connection.rs:28:28
   |
28 | pub trait InnerConnection: AsyncRead + AsyncWrite + Send + Sync + Unpin {}
   |                            ^^^^^^^^^ not found in this scope
   |
help: consider importing this trait
   |
1  | use futures_lite::AsyncRead;
   |

error[E0405]: cannot find trait `AsyncWrite` in this scope
  --> /Users/albert/.cargo/registry/src/github.com-1ecc6299db9ec823/http-types-2.12.0/src/upgrade/connection.rs:28:40
   |
28 | pub trait InnerConnection: AsyncRead + AsyncWrite + Send + Sync + Unpin {}
   |                                        ^^^^^^^^^^ not found in this scope
   |
help: consider importing this trait
   |
1  | use futures_lite::AsyncWrite;
   |

error[E0405]: cannot find trait `AsyncRead` in this scope
  --> /Users/albert/.cargo/registry/src/github.com-1ecc6299db9ec823/http-types-2.12.0/src/upgrade/connection.rs:29:9
   |
29 | impl<T: AsyncRead + AsyncWrite + Send + Sync + Unpin> InnerConnection for T {}
   |         ^^^^^^^^^ not found in this scope
   |
help: consider importing this trait
   |
1  | use futures_lite::AsyncRead;
   |

error[E0405]: cannot find trait `AsyncWrite` in this scope
  --> /Users/albert/.cargo/registry/src/github.com-1ecc6299db9ec823/http-types-2.12.0/src/upgrade/connection.rs:29:21
   |
29 | impl<T: AsyncRead + AsyncWrite + Send + Sync + Unpin> InnerConnection for T {}
   |                     ^^^^^^^^^^ not found in this scope
   |
help: consider importing this trait
   |
1  | use futures_lite::AsyncWrite;
   |

error[E0405]: cannot find trait `AsyncRead` in this scope
  --> /Users/albert/.cargo/registry/src/github.com-1ecc6299db9ec823/http-types-2.12.0/src/upgrade/connection.rs:31:6
   |
31 | impl AsyncRead for Connection {
   |      ^^^^^^^^^ not found in this scope
   |
help: consider importing this trait
   |
1  | use futures_lite::AsyncRead;
   |

error[E0405]: cannot find trait `AsyncWrite` in this scope
  --> /Users/albert/.cargo/registry/src/github.com-1ecc6299db9ec823/http-types-2.12.0/src/upgrade/connection.rs:41:6
   |
41 | impl AsyncWrite for Connection {
   |      ^^^^^^^^^^ not found in this scope
   |
help: consider importing this trait
   |
1  | use futures_lite::AsyncWrite;
   |

I am on the latest rust nightly

Issue seems to be that this file is missing this first line in the installed crate

use futures_lite::{io, prelude::*};

However, it appears to be there on the github?
https://github.com/http-rs/http-types/blob/main/src/upgrade/connection.rs

This line does not appear in my installed crate's code.

use std::fmt::{self, Debug};
use std::pin::Pin;
use std::task::{Context, Poll};

/// An upgraded HTTP connection.
pub struct Connection {
    inner: Box<dyn InnerConnection>,
}

impl Debug for Connection {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let inner = "Box<dyn Asyncread + AsyncWrite + Send + Sync + Unpin>";
        f.debug_struct("Connection").field("inner", &inner).finish()
    }
}

impl Connection {
    /// Create a new instance of `Connection`.
    pub fn new<T>(t: T) -> Self
    where
        T: AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static,
    {
        Self { inner: Box::new(t) }
    }
}

/// Trait to signal the requirements for an underlying connection type.
pub trait InnerConnection: AsyncRead + AsyncWrite + Send + Sync + Unpin {}
impl<T: AsyncRead + AsyncWrite + Send + Sync + Unpin> InnerConnection for T {}

impl AsyncRead for Connection {
    fn poll_read(
        mut self: Pin<&mut Self>,
        cx: &mut Context<'_>,
        buf: &mut [u8],
    ) -> Poll<io::Result<usize>> {
        Pin::new(&mut self.inner).poll_read(cx, buf)
    }
}

impl AsyncWrite for Connection {
    fn poll_write(
        mut self: Pin<&mut Self>,
        cx: &mut Context<'_>,
        buf: &[u8],
    ) -> Poll<io::Result<usize>> {
        Pin::new(&mut self.inner).poll_write(cx, buf)
    }

    fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
        Pin::new(&mut self.inner).poll_flush(cx)
    }

    fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
        Pin::new(&mut self.inner).poll_close(cx)
    }
}

Clearing my cargo cache seemed to have fixed the issue

cargo install cargo-cache
cargo cache -a

Maybe I mistakenly deleted a line? Who knows...