diff --git a/.clippy.toml b/.clippy.toml index 7e3a473ba35..62ca7423409 100644 --- a/.clippy.toml +++ b/.clippy.toml @@ -1 +1 @@ -msrv = "1.49" +msrv = "1.56" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0c00616005a..a3b22cc06f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ env: # - tokio-util/Cargo.toml # - tokio-test/Cargo.toml # - tokio-stream/Cargo.toml - rust_min: 1.49.0 + rust_min: 1.56.0 defaults: run: diff --git a/README.md b/README.md index eee0dce32c6..7fec89a14e2 100644 --- a/README.md +++ b/README.md @@ -187,7 +187,20 @@ When updating this, also update: Tokio will keep a rolling MSRV (minimum supported rust version) policy of **at least** 6 months. When increasing the MSRV, the new Rust version must have been -released at least six months ago. The current MSRV is 1.49.0. +released at least six months ago. The current MSRV is 1.56.0. + +Note that the MSRV is not increased automatically, and only as part of a minor +release. The MSRV history for past minor releases can be found below: + + * 1.27 to now - Rust 1.56 + * 1.17 to 1.26 - Rust 1.49 + * 1.15 to 1.16 - Rust 1.46 + * 1.0 to 1.14 - Rust 1.45 + +Note that although we try to avoid the situation where a dependency transitively +increases the MSRV of Tokio, we do not guarantee that this does not happen. +However, every minor release will have some set of versions of dependencies that +works with the MSRV of that minor release. ## Release schedule @@ -202,9 +215,9 @@ warrants a patch release with a fix for the bug, it will be backported and released as a new patch release for each LTS minor version. Our current LTS releases are: - * `1.18.x` - LTS release until June 2023 - * `1.20.x` - LTS release until September 2023. - * `1.25.x` - LTS release until March 2024 + * `1.18.x` - LTS release until June 2023. (MSRV 1.49) + * `1.20.x` - LTS release until September 2023. (MSRV 1.49) + * `1.25.x` - LTS release until March 2024. (MSRV 1.49) Each LTS release will continue to receive backported fixes for at least a year. If you wish to use a fixed minor release in your project, we recommend that you diff --git a/tokio-macros/Cargo.toml b/tokio-macros/Cargo.toml index ea536a8d134..79772bdb470 100644 --- a/tokio-macros/Cargo.toml +++ b/tokio-macros/Cargo.toml @@ -6,7 +6,7 @@ name = "tokio-macros" # - Create "tokio-macros-1.x.y" git tag. version = "1.8.2" edition = "2018" -rust-version = "1.49" +rust-version = "1.56" authors = ["Tokio Contributors "] license = "MIT" repository = "https://github.com/tokio-rs/tokio" diff --git a/tokio-stream/Cargo.toml b/tokio-stream/Cargo.toml index f87b59a3654..6711e29bcec 100644 --- a/tokio-stream/Cargo.toml +++ b/tokio-stream/Cargo.toml @@ -6,7 +6,7 @@ name = "tokio-stream" # - Create "tokio-stream-0.1.x" git tag. version = "0.1.12" edition = "2018" -rust-version = "1.49" +rust-version = "1.56" authors = ["Tokio Contributors "] license = "MIT" repository = "https://github.com/tokio-rs/tokio" diff --git a/tokio-test/Cargo.toml b/tokio-test/Cargo.toml index 30cacead51f..603a4b4affc 100644 --- a/tokio-test/Cargo.toml +++ b/tokio-test/Cargo.toml @@ -6,7 +6,7 @@ name = "tokio-test" # - Create "tokio-test-0.4.x" git tag. version = "0.4.2" edition = "2018" -rust-version = "1.49" +rust-version = "1.56" authors = ["Tokio Contributors "] license = "MIT" repository = "https://github.com/tokio-rs/tokio" diff --git a/tokio-util/Cargo.toml b/tokio-util/Cargo.toml index 267662b4d5b..cf9f0474051 100644 --- a/tokio-util/Cargo.toml +++ b/tokio-util/Cargo.toml @@ -6,7 +6,7 @@ name = "tokio-util" # - Create "tokio-util-0.7.x" git tag. version = "0.7.7" edition = "2018" -rust-version = "1.49" +rust-version = "1.56" authors = ["Tokio Contributors "] license = "MIT" repository = "https://github.com/tokio-rs/tokio" diff --git a/tokio-util/src/sync/cancellation_token/tree_node.rs b/tokio-util/src/sync/cancellation_token/tree_node.rs index f1abb4a8d33..f9068bc097e 100644 --- a/tokio-util/src/sync/cancellation_token/tree_node.rs +++ b/tokio-util/src/sync/cancellation_token/tree_node.rs @@ -239,11 +239,7 @@ fn remove_child(parent: &mut Inner, mut node: MutexGuard<'_, Inner>) { let len = parent.children.len(); if 4 * len <= parent.children.capacity() { - // equal to: - // parent.children.shrink_to(2 * len); - // but shrink_to was not yet stabilized in our minimal compatible version - let old_children = std::mem::replace(&mut parent.children, Vec::with_capacity(2 * len)); - parent.children.extend(old_children); + parent.children.shrink_to(2 * len); } } diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index 70bf412d61a..450a59cc425 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -7,8 +7,8 @@ name = "tokio" # - Update CHANGELOG.md. # - Create "v1.x.y" git tag. version = "1.26.0" -edition = "2018" -rust-version = "1.49" +edition = "2021" +rust-version = "1.56" authors = ["Tokio Contributors "] license = "MIT" readme = "README.md" diff --git a/tokio/README.md b/tokio/README.md index eee0dce32c6..7fec89a14e2 100644 --- a/tokio/README.md +++ b/tokio/README.md @@ -187,7 +187,20 @@ When updating this, also update: Tokio will keep a rolling MSRV (minimum supported rust version) policy of **at least** 6 months. When increasing the MSRV, the new Rust version must have been -released at least six months ago. The current MSRV is 1.49.0. +released at least six months ago. The current MSRV is 1.56.0. + +Note that the MSRV is not increased automatically, and only as part of a minor +release. The MSRV history for past minor releases can be found below: + + * 1.27 to now - Rust 1.56 + * 1.17 to 1.26 - Rust 1.49 + * 1.15 to 1.16 - Rust 1.46 + * 1.0 to 1.14 - Rust 1.45 + +Note that although we try to avoid the situation where a dependency transitively +increases the MSRV of Tokio, we do not guarantee that this does not happen. +However, every minor release will have some set of versions of dependencies that +works with the MSRV of that minor release. ## Release schedule @@ -202,9 +215,9 @@ warrants a patch release with a fix for the bug, it will be backported and released as a new patch release for each LTS minor version. Our current LTS releases are: - * `1.18.x` - LTS release until June 2023 - * `1.20.x` - LTS release until September 2023. - * `1.25.x` - LTS release until March 2024 + * `1.18.x` - LTS release until June 2023. (MSRV 1.49) + * `1.20.x` - LTS release until September 2023. (MSRV 1.49) + * `1.25.x` - LTS release until March 2024. (MSRV 1.49) Each LTS release will continue to receive backported fixes for at least a year. If you wish to use a fixed minor release in your project, we recommend that you diff --git a/tokio/build.rs b/tokio/build.rs index 0e2480ed846..2d2ec5641c0 100644 --- a/tokio/build.rs +++ b/tokio/build.rs @@ -10,13 +10,6 @@ const CONST_THREAD_LOCAL_PROBE: &str = r#" } "#; -const ADDR_OF_PROBE: &str = r#" -{ - let my_var = 10; - ::std::ptr::addr_of!(my_var) -} -"#; - const CONST_MUTEX_NEW_PROBE: &str = r#" { static MY_MUTEX: ::std::sync::Mutex = ::std::sync::Mutex::new(1); @@ -53,7 +46,6 @@ const TARGET_ATOMIC_U64_PROBE: &str = r#" fn main() { let mut enable_const_thread_local = false; - let mut enable_addr_of = false; let mut enable_target_has_atomic = false; let mut enable_const_mutex_new = false; let mut enable_as_fd = false; @@ -81,21 +73,6 @@ fn main() { } } - // The `addr_of` and `addr_of_mut` macros were stabilized in 1.51. - if ac.probe_rustc_version(1, 52) { - enable_addr_of = true; - } else if ac.probe_rustc_version(1, 51) { - // This compiler claims to be 1.51, but there are some nightly - // compilers that claim to be 1.51 without supporting the - // feature. Explicitly probe to check if code using them - // compiles. - // - // The oldest nightly that supports the feature is 2021-01-31. - if ac.probe_expression(ADDR_OF_PROBE) { - enable_addr_of = true; - } - } - // The `target_has_atomic` cfg was stabilized in 1.60. if ac.probe_rustc_version(1, 61) { enable_target_has_atomic = true; @@ -167,14 +144,6 @@ fn main() { autocfg::emit("tokio_no_const_thread_local") } - if !enable_addr_of { - // To disable this feature on compilers that support it, you can - // explicitly pass this flag with the following environment variable: - // - // RUSTFLAGS="--cfg tokio_no_addr_of" - autocfg::emit("tokio_no_addr_of") - } - if !enable_target_has_atomic { // To disable this feature on compilers that support it, you can // explicitly pass this flag with the following environment variable: diff --git a/tokio/src/macros/addr_of.rs b/tokio/src/macros/addr_of.rs index 51d488972d9..9d28158f200 100644 --- a/tokio/src/macros/addr_of.rs +++ b/tokio/src/macros/addr_of.rs @@ -1,7 +1,6 @@ //! This module defines a macro that lets you go from a raw pointer to a struct //! to a raw pointer to a field of the struct. -#[cfg(not(tokio_no_addr_of))] macro_rules! generate_addr_of_methods { ( impl<$($gen:ident)*> $struct_name:ty {$( @@ -21,33 +20,3 @@ macro_rules! generate_addr_of_methods { )*} }; } - -// The `addr_of_mut!` macro is only available for MSRV at least 1.51.0. This -// version of the macro uses a workaround for older versions of rustc. -#[cfg(tokio_no_addr_of)] -macro_rules! generate_addr_of_methods { - ( - impl<$($gen:ident)*> $struct_name:ty {$( - $(#[$attrs:meta])* - $vis:vis unsafe fn $fn_name:ident(self: NonNull) -> NonNull<$field_type:ty> { - &self$(.$field_name:tt)+ - } - )*} - ) => { - impl<$($gen)*> $struct_name {$( - $(#[$attrs])* - $vis unsafe fn $fn_name(me: ::core::ptr::NonNull) -> ::core::ptr::NonNull<$field_type> { - let me = me.as_ptr(); - let me_u8 = me as *mut u8; - - let field_offset = { - let me_ref = &*me; - let field_ref_u8 = (&me_ref $(.$field_name)+ ) as *const $field_type as *const u8; - field_ref_u8.offset_from(me_u8) - }; - - ::core::ptr::NonNull::new_unchecked(me_u8.offset(field_offset).cast()) - } - )*} - }; -} diff --git a/tokio/src/net/tcp/listener.rs b/tokio/src/net/tcp/listener.rs index 0e429761d25..34e393c895f 100644 --- a/tokio/src/net/tcp/listener.rs +++ b/tokio/src/net/tcp/listener.rs @@ -5,7 +5,6 @@ cfg_not_wasi! { use crate::net::{to_socket_addrs, ToSocketAddrs}; } -use std::convert::TryFrom; use std::fmt; use std::io; use std::net::{self, SocketAddr}; diff --git a/tokio/src/net/tcp/stream.rs b/tokio/src/net/tcp/stream.rs index 2ea6da2de74..b7104d78b40 100644 --- a/tokio/src/net/tcp/stream.rs +++ b/tokio/src/net/tcp/stream.rs @@ -8,7 +8,6 @@ use crate::io::{AsyncRead, AsyncWrite, Interest, PollEvented, ReadBuf, Ready}; use crate::net::tcp::split::{split, ReadHalf, WriteHalf}; use crate::net::tcp::split_owned::{split_owned, OwnedReadHalf, OwnedWriteHalf}; -use std::convert::TryFrom; use std::fmt; use std::io; use std::net::{Shutdown, SocketAddr}; diff --git a/tokio/src/net/udp.rs b/tokio/src/net/udp.rs index 40732a0a294..f8006627df0 100644 --- a/tokio/src/net/udp.rs +++ b/tokio/src/net/udp.rs @@ -1,7 +1,6 @@ use crate::io::{Interest, PollEvented, ReadBuf, Ready}; use crate::net::{to_socket_addrs, ToSocketAddrs}; -use std::convert::TryFrom; use std::fmt; use std::io; use std::net::{self, Ipv4Addr, Ipv6Addr, SocketAddr}; diff --git a/tokio/src/net/unix/datagram/socket.rs b/tokio/src/net/unix/datagram/socket.rs index dd7e6ef9d1f..bd192b3798d 100644 --- a/tokio/src/net/unix/datagram/socket.rs +++ b/tokio/src/net/unix/datagram/socket.rs @@ -1,7 +1,6 @@ use crate::io::{Interest, PollEvented, ReadBuf, Ready}; use crate::net::unix::SocketAddr; -use std::convert::TryFrom; use std::fmt; use std::io; use std::net::Shutdown; diff --git a/tokio/src/net/unix/listener.rs b/tokio/src/net/unix/listener.rs index 1a2614feff4..6a050f39be9 100644 --- a/tokio/src/net/unix/listener.rs +++ b/tokio/src/net/unix/listener.rs @@ -1,7 +1,6 @@ use crate::io::{Interest, PollEvented}; use crate::net::unix::{SocketAddr, UnixStream}; -use std::convert::TryFrom; use std::fmt; use std::io; #[cfg(not(tokio_no_as_fd))] diff --git a/tokio/src/net/unix/stream.rs b/tokio/src/net/unix/stream.rs index 65903da7731..f8afa5a8266 100644 --- a/tokio/src/net/unix/stream.rs +++ b/tokio/src/net/unix/stream.rs @@ -5,7 +5,6 @@ use crate::net::unix::split_owned::{split_owned, OwnedReadHalf, OwnedWriteHalf}; use crate::net::unix::ucred::{self, UCred}; use crate::net::unix::SocketAddr; -use std::convert::TryFrom; use std::fmt; use std::io::{self, Read, Write}; use std::net::Shutdown; diff --git a/tokio/src/process/mod.rs b/tokio/src/process/mod.rs index d4ba1bacc9d..58c50aa8afb 100644 --- a/tokio/src/process/mod.rs +++ b/tokio/src/process/mod.rs @@ -156,7 +156,6 @@ //! ```no_run //! use tokio::join; //! use tokio::process::Command; -//! use std::convert::TryInto; //! use std::process::Stdio; //! //! #[tokio::main] @@ -245,7 +244,6 @@ mod kill; use crate::io::{AsyncRead, AsyncWrite, ReadBuf}; use crate::process::kill::Kill; -use std::convert::TryInto; use std::ffi::OsStr; use std::future::Future; use std::io; diff --git a/tokio/src/runtime/metrics/batch.rs b/tokio/src/runtime/metrics/batch.rs index 4e6b28d68ed..ec299741398 100644 --- a/tokio/src/runtime/metrics/batch.rs +++ b/tokio/src/runtime/metrics/batch.rs @@ -1,6 +1,5 @@ use crate::runtime::WorkerMetrics; -use std::convert::TryFrom; use std::sync::atomic::Ordering::Relaxed; use std::time::Instant; diff --git a/tokio/src/runtime/time/source.rs b/tokio/src/runtime/time/source.rs index 39483b5c0ad..412812da193 100644 --- a/tokio/src/runtime/time/source.rs +++ b/tokio/src/runtime/time/source.rs @@ -1,7 +1,5 @@ use crate::time::{Clock, Duration, Instant}; -use std::convert::TryInto; - /// A structure which handles conversion from Instants to u64 timestamps. #[derive(Debug)] pub(crate) struct TimeSource { diff --git a/tokio/src/signal/windows/sys.rs b/tokio/src/signal/windows/sys.rs index f8133e026c4..26e6bdf8182 100644 --- a/tokio/src/signal/windows/sys.rs +++ b/tokio/src/signal/windows/sys.rs @@ -1,4 +1,3 @@ -use std::convert::TryFrom; use std::io; use std::sync::Once; diff --git a/tokio/src/time/instant.rs b/tokio/src/time/instant.rs index f18492930a7..14cf6e567b5 100644 --- a/tokio/src/time/instant.rs +++ b/tokio/src/time/instant.rs @@ -188,7 +188,7 @@ impl ops::Sub for Instant { type Output = Instant; fn sub(self, rhs: Duration) -> Instant { - Instant::from_std(self.std - rhs) + Instant::from_std(std::time::Instant::sub(self.std, rhs)) } } diff --git a/tokio/src/time/interval.rs b/tokio/src/time/interval.rs index ea8b3939f46..d933164daad 100644 --- a/tokio/src/time/interval.rs +++ b/tokio/src/time/interval.rs @@ -2,10 +2,10 @@ use crate::future::poll_fn; use crate::time::{sleep_until, Duration, Instant, Sleep}; use crate::util::trace; +use std::future::Future; use std::panic::Location; use std::pin::Pin; use std::task::{Context, Poll}; -use std::{convert::TryInto, future::Future}; /// Creates new [`Interval`] that yields with interval of `period`. The first /// tick completes immediately. The default [`MissedTickBehavior`] is diff --git a/tokio/src/util/slab.rs b/tokio/src/util/slab.rs index 0e16e40e99a..cc1208ebef4 100644 --- a/tokio/src/util/slab.rs +++ b/tokio/src/util/slab.rs @@ -560,7 +560,7 @@ impl Slots { assert!(slot >= base, "unexpected pointer"); let idx = (slot - base) / width; - assert!(idx < self.slots.len() as usize); + assert!(idx < self.slots.len()); idx } diff --git a/tokio/tests/macros_select.rs b/tokio/tests/macros_select.rs index 26d6fec874b..0514c864d5e 100644 --- a/tokio/tests/macros_select.rs +++ b/tokio/tests/macros_select.rs @@ -206,47 +206,56 @@ async fn nested() { assert_eq!(res, 3); } -#[maybe_tokio_test] #[cfg(target_pointer_width = "64")] -async fn struct_size() { +mod pointer_64_tests { + use super::maybe_tokio_test; use futures::future; use std::mem; - let fut = async { - let ready = future::ready(0i32); + #[maybe_tokio_test] + async fn struct_size_1() { + let fut = async { + let ready = future::ready(0i32); - tokio::select! { - _ = ready => {}, - } - }; + tokio::select! { + _ = ready => {}, + } + }; - assert_eq!(mem::size_of_val(&fut), 40); + assert_eq!(mem::size_of_val(&fut), 32); + } - let fut = async { - let ready1 = future::ready(0i32); - let ready2 = future::ready(0i32); + #[maybe_tokio_test] + async fn struct_size_2() { + let fut = async { + let ready1 = future::ready(0i32); + let ready2 = future::ready(0i32); - tokio::select! { - _ = ready1 => {}, - _ = ready2 => {}, - } - }; + tokio::select! { + _ = ready1 => {}, + _ = ready2 => {}, + } + }; - assert_eq!(mem::size_of_val(&fut), 48); + assert_eq!(mem::size_of_val(&fut), 40); + } - let fut = async { - let ready1 = future::ready(0i32); - let ready2 = future::ready(0i32); - let ready3 = future::ready(0i32); + #[maybe_tokio_test] + async fn struct_size_3() { + let fut = async { + let ready1 = future::ready(0i32); + let ready2 = future::ready(0i32); + let ready3 = future::ready(0i32); - tokio::select! { - _ = ready1 => {}, - _ = ready2 => {}, - _ = ready3 => {}, - } - }; + tokio::select! { + _ = ready1 => {}, + _ = ready2 => {}, + _ = ready3 => {}, + } + }; - assert_eq!(mem::size_of_val(&fut), 56); + assert_eq!(mem::size_of_val(&fut), 48); + } } #[maybe_tokio_test] diff --git a/tokio/tests/net_bind_resource.rs b/tokio/tests/net_bind_resource.rs index 1c604aa534c..76378b3ea1e 100644 --- a/tokio/tests/net_bind_resource.rs +++ b/tokio/tests/net_bind_resource.rs @@ -3,7 +3,6 @@ use tokio::net::TcpListener; -use std::convert::TryFrom; use std::net; #[test] diff --git a/tokio/tests/process_kill_on_drop.rs b/tokio/tests/process_kill_on_drop.rs index 658e4addd61..d919b1a27fe 100644 --- a/tokio/tests/process_kill_on_drop.rs +++ b/tokio/tests/process_kill_on_drop.rs @@ -12,7 +12,7 @@ use tokio_test::assert_ok; #[tokio::test] async fn kill_on_drop() { let mut cmd = Command::new("bash"); - cmd.args(&[ + cmd.args([ "-c", " # Fork another child that won't get killed diff --git a/tokio/tests/tcp_peek.rs b/tokio/tests/tcp_peek.rs index b7120232ca4..a5fd6ba4fe5 100644 --- a/tokio/tests/tcp_peek.rs +++ b/tokio/tests/tcp_peek.rs @@ -7,7 +7,7 @@ use tokio::net::TcpStream; use tokio_test::assert_ok; use std::thread; -use std::{convert::TryInto, io::Write, net}; +use std::{io::Write, net}; #[tokio::test] async fn peek() {