Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About rust1.41 compile tokio BUG #3849

Closed
houfangdong opened this issue Jun 8, 2021 · 1 comment
Closed

About rust1.41 compile tokio BUG #3849

houfangdong opened this issue Jun 8, 2021 · 1 comment
Labels
A-tokio Area: The main tokio crate C-question User questions that are neither feature requests nor bug reports

Comments

@houfangdong
Copy link

Version
[root@k8s tokio-1.2.0]# rustc --version
rustc 1.41.1 (f3e1a954d 2020-02-24)
[root@k8s tokio-1.2.0]# cargo --version
cargo 1.41.0 (626f0f40e 2019-12-03)
[root@k8s tokio-1.2.0]#

Platform
[root@k8s tokio-1.2.0]# uname -a
Linux k8s 4.18.0-240.el8.x86_64 #1 SMP Fri Sep 25 19:48:47 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Description
Using rust1.41 to compile tokio1.20~1.6.0, an error is reported

[short summary of the bug]

I tried this code:

I expected to see this happen: [explanation]
Using rust1.41 to compile tokio1.20~1.6.0, an error is reported. How to solve it without upgrading the rust version?

Instead, this happened: [explanation]

[root@k8s tokio-1.2.0]# cargo build --all-features
   Compiling libc v0.2.95
   Compiling cfg-if v1.0.0
   Compiling proc-macro2 v1.0.27
   Compiling unicode-xid v0.2.2
   Compiling log v0.4.14
   Compiling syn v1.0.72
   Compiling scopeguard v1.1.0
   Compiling autocfg v1.0.1
   Compiling smallvec v1.6.1
   Compiling memchr v2.4.0
   Compiling once_cell v1.7.2
   Compiling bytes v1.0.1
   Compiling pin-project-lite v0.2.6
   Compiling instant v0.1.9
   Compiling lock_api v0.4.4
   Compiling tokio v1.2.0 (/root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.2.0)
   Compiling quote v1.0.9
   Compiling parking_lot_core v0.8.3
   Compiling mio v0.7.11
   Compiling signal-hook-registry v1.4.0
   Compiling num_cpus v1.13.0
   Compiling parking_lot v0.11.1
   Compiling tokio-macros v1.2.0
error: unexpected `self` parameter in function
   --> src/net/tcp/stream.rs:627:40
    |
627 |         pub fn try_read_buf<B: BufMut>(&self, buf: &mut B) -> io::Result<usize> {
    |                                        ^^^^^ not valid as function parameter
    |
    = note: `self` is only valid as the first parameter of an associated function

error: expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, or `unsafe`, found `#[doc =
  r" Try to read data from the stream into the provided buffer, advancing the"]
#[doc = r" buffer's internal cursor, returning how many bytes were read."]
#[doc = r""]
#[doc =
  r" Receives any pending data from the socket but does not wait for new data"]
#[doc = r" to arrive. On success, returns the number of bytes read. Because"]
#[doc =
  r" `try_read_buf()` is non-blocking, the buffer does not have to be stored by"]
#[doc = r" the async task and can exist entirely on the stack."]
#[doc = r""]
#[doc =
  r" Usually, [`readable()`] or [`ready()`] is used with this function."]
#[doc = r""]
#[doc = r" [`readable()`]: TcpStream::readable()"]
#[doc = r" [`ready()`]: TcpStream::ready()"]
#[doc = r""]
#[doc = r" # Return"]
#[doc = r""]
#[doc =
  r" If data is successfully read, `Ok(n)` is returned, where `n` is the"]
#[doc =
  r" number of bytes read. `Ok(0)` indicates the stream's read half is closed"]
#[doc =
  r" and will no longer yield data. If the stream is not ready to read data"]
#[doc = r" `Err(io::ErrorKind::WouldBlock)` is returned."]
#[doc = r""]
#[doc = r" # Examples"]
#[doc = r""]
#[doc = r" ```no_run"]
#[doc = r" use tokio::net::TcpStream;"]
#[doc = r" use std::error::Error;"]
#[doc = r" use std::io;"]
#[doc = r""]
#[doc = r" #[tokio::main]"]
#[doc = r" async fn main() -> Result<(), Box<dyn Error>> {"]
#[doc = r"     // Connect to a peer"]
#[doc = r#"     let stream = TcpStream::connect("127.0.0.1:8080").await?;"#]
#[doc = r""]
#[doc = r"     loop {"]
#[doc = r"         // Wait for the socket to be readable"]
#[doc = r"         stream.readable().await?;"]
#[doc = r""]
#[doc = r"         let mut buf = Vec::with_capacity(4096);"]
#[doc = r""]
#[doc =
  r"         // Try to read data, this may still fail with `WouldBlock`"]
#[doc = r"         // if the readiness event is a false positive."]
#[doc = r"         match stream.try_read_buf(&mut buf) {"]
#[doc = r"             Ok(0) => break,"]
#[doc = r"             Ok(n) => {"]
#[doc = r#"                 println!("read {} bytes", n);"#]
#[doc = r"             }"]
#[doc =
  r"             Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {"]
#[doc = r"                 continue;"]
#[doc = r"             }"]
#[doc = r"             Err(e) => {"]
#[doc = r"                 return Err(e.into());"]
#[doc = r"             }"]
#[doc = r"         }"]
#[doc = r"     }"]
#[doc = r""]
#[doc = r"     Ok(())"]
#[doc = r" }"]
#[doc = r" ```"]
pub fn try_read_buf<B: BufMut>(self: (/*ERROR*/), buf: &mut B)
 -> io::Result<usize> {
    self.io.registration().try_io(Interest::READABLE,
                                  ||
                                      {
                                          use std::io::Read;
                                          let dst = buf.chunk_mut();
                                          let dst =
                                              unsafe {
                                                  &mut *(dst as *mut _ as
                                                             *mut [std::mem::MaybeUninit<u8>]
                                                             as *mut [u8])
                                              };
                                          let n = (&*self.io).read(dst)?;
                                          unsafe { buf.advance_mut(n); }
                                          Ok(n)
                                      })
}`
   --> src/macros/cfg.rs:132:13
    |
131 |               #[cfg_attr(docsrs, doc(cfg(feature = "io-util")))]
    |                                                                 - expected one of 9 possible tokens
132 |               $item
    |               ^^^^^ unexpected token
    | 
   ::: src/net/tcp/stream.rs:569:5
    |
569 | /     cfg_io_util! {
570 | |         /// Try to read data from the stream into the provided buffer, advancing the
571 | |         /// buffer's internal cursor, returning how many bytes were read.
572 | |         ///
...   |
645 | |         }
646 | |     }
    | |_____- in this macro invocation

error: aborting due to 2 previous errors

error: could not compile `tokio`.

To learn more, run the command again with --verbose.
@houfangdong houfangdong added A-tokio Area: The main tokio crate C-bug Category: This is a bug. labels Jun 8, 2021
@sfackler
Copy link
Contributor

sfackler commented Jun 8, 2021

The minimum supported Rust version is 1.45.0: https://github.com/tokio-rs/tokio#supported-rust-versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-question User questions that are neither feature requests nor bug reports
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants