From 87eca014f7b0fdea8eea900d33208457b171a335 Mon Sep 17 00:00:00 2001 From: jw013 Date: Sat, 6 Jan 2024 13:53:13 -0500 Subject: [PATCH] Add test crate to test async fn and impl Future (#622) * Add test crate to test async fn and impl Future * Disable trait async fn for now, add TODO --- .../new/Cargo.toml | 7 +++++ .../new/src/lib.rs | 29 +++++++++++++++++++ .../old/Cargo.toml | 7 +++++ .../old/src/lib.rs | 29 +++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 test_crates/async_impl_future_equivalence/new/Cargo.toml create mode 100644 test_crates/async_impl_future_equivalence/new/src/lib.rs create mode 100644 test_crates/async_impl_future_equivalence/old/Cargo.toml create mode 100644 test_crates/async_impl_future_equivalence/old/src/lib.rs diff --git a/test_crates/async_impl_future_equivalence/new/Cargo.toml b/test_crates/async_impl_future_equivalence/new/Cargo.toml new file mode 100644 index 00000000..984e1e0e --- /dev/null +++ b/test_crates/async_impl_future_equivalence/new/Cargo.toml @@ -0,0 +1,7 @@ +[package] +publish = false +name = "async_impl_future_equivalence" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/test_crates/async_impl_future_equivalence/new/src/lib.rs b/test_crates/async_impl_future_equivalence/new/src/lib.rs new file mode 100644 index 00000000..3f2d8003 --- /dev/null +++ b/test_crates/async_impl_future_equivalence/new/src/lib.rs @@ -0,0 +1,29 @@ +//! async fn and return position impl Future are equivalent. +//! Switching from one to the other should NOT generate any lints + +use std::future::Future; + +pub fn switches_to_return_impl() -> impl Future { + async {} +} + +pub async fn switches_to_async() {} + +pub struct S; + +impl S { + pub fn switches_to_return_impl() -> impl Future { + async {} + } + + pub async fn switches_to_async() {} +} + +// TODO: https://github.com/obi1kenobi/cargo-semver-checks/issues/624 +// Uncomment once the project drops support for Rust < 1.75 +// +// #[allow(async_fn_in_trait)] +// pub trait Trait { +// fn switches_to_return_impl() -> impl Future; +// async fn switches_to_async(); +// } diff --git a/test_crates/async_impl_future_equivalence/old/Cargo.toml b/test_crates/async_impl_future_equivalence/old/Cargo.toml new file mode 100644 index 00000000..984e1e0e --- /dev/null +++ b/test_crates/async_impl_future_equivalence/old/Cargo.toml @@ -0,0 +1,7 @@ +[package] +publish = false +name = "async_impl_future_equivalence" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/test_crates/async_impl_future_equivalence/old/src/lib.rs b/test_crates/async_impl_future_equivalence/old/src/lib.rs new file mode 100644 index 00000000..04d5c3f3 --- /dev/null +++ b/test_crates/async_impl_future_equivalence/old/src/lib.rs @@ -0,0 +1,29 @@ +//! async fn and return position impl Future are equivalent. +//! Switching from one to the other should NOT generate any lints + +use std::future::Future; + +pub async fn switches_to_return_impl() {} + +pub fn switches_to_async() -> impl Future { + async {} +} + +pub struct S; + +impl S { + pub async fn switches_to_return_impl() {} + + pub fn switches_to_async() -> impl Future { + async {} + } +} + +// TODO: https://github.com/obi1kenobi/cargo-semver-checks/issues/624 +// Uncomment once the project drops support for Rust < 1.75 +// +// #[allow(async_fn_in_trait)] +// pub trait Trait { +// async fn switches_to_return_impl(); +// fn switches_to_async() -> impl Future; +// }