about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-01-18 17:28:37 +0000
committerMichael Goulet <michael@errs.io>2024-02-05 21:08:48 +0000
commit1a3214b774f47b2fb8dadf305939f97e20993fe2 (patch)
tree0f7ecbcf26a9efe1a1d3090eb3970deccbd85457
parente65abc0ea58f2f7dd6812fafa92c4f5b2a28af7b (diff)
downloadrust-1a3214b774f47b2fb8dadf305939f97e20993fe2.tar.gz
rust-1a3214b774f47b2fb8dadf305939f97e20993fe2.zip
Make sure refinement still works
-rw-r--r--tests/ui/async-await/in-trait/async-example-desugared-boxed.rs5
-rw-r--r--tests/ui/async-await/in-trait/async-example-desugared-boxed.stderr22
-rw-r--r--tests/ui/async-await/in-trait/async-example-desugared-manual.rs7
-rw-r--r--tests/ui/async-await/in-trait/async-example-desugared-manual.stderr22
4 files changed, 53 insertions, 3 deletions
diff --git a/tests/ui/async-await/in-trait/async-example-desugared-boxed.rs b/tests/ui/async-await/in-trait/async-example-desugared-boxed.rs
index 4008e09998e..69871d0dca0 100644
--- a/tests/ui/async-await/in-trait/async-example-desugared-boxed.rs
+++ b/tests/ui/async-await/in-trait/async-example-desugared-boxed.rs
@@ -4,12 +4,15 @@
 use std::future::Future;
 use std::pin::Pin;
 
-trait MyTrait {
+#[allow(async_fn_in_trait)]
+pub trait MyTrait {
     async fn foo(&self) -> i32;
 }
 
 impl MyTrait for i32 {
+    #[warn(refining_impl_trait)]
     fn foo(&self) -> Pin<Box<dyn Future<Output = i32> + '_>> {
+        //~^ WARN impl trait in impl method signature does not match trait method signature
         Box::pin(async { *self })
     }
 }
diff --git a/tests/ui/async-await/in-trait/async-example-desugared-boxed.stderr b/tests/ui/async-await/in-trait/async-example-desugared-boxed.stderr
new file mode 100644
index 00000000000..54aba77cc05
--- /dev/null
+++ b/tests/ui/async-await/in-trait/async-example-desugared-boxed.stderr
@@ -0,0 +1,22 @@
+warning: impl trait in impl method signature does not match trait method signature
+  --> $DIR/async-example-desugared-boxed.rs:14:22
+   |
+LL |     async fn foo(&self) -> i32;
+   |     --------------------------- return type from trait method defined here
+...
+LL |     fn foo(&self) -> Pin<Box<dyn Future<Output = i32> + '_>> {
+   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate
+note: the lint level is defined here
+  --> $DIR/async-example-desugared-boxed.rs:13:12
+   |
+LL |     #[warn(refining_impl_trait)]
+   |            ^^^^^^^^^^^^^^^^^^^
+help: replace the return type so that it matches the trait
+   |
+LL |     fn foo(&self) -> impl Future<Output = i32> {
+   |                      ~~~~~~~~~~~~~~~~~~~~~~~~~
+
+warning: 1 warning emitted
+
diff --git a/tests/ui/async-await/in-trait/async-example-desugared-manual.rs b/tests/ui/async-await/in-trait/async-example-desugared-manual.rs
index 75f4ba1d076..c6e8f1ae906 100644
--- a/tests/ui/async-await/in-trait/async-example-desugared-manual.rs
+++ b/tests/ui/async-await/in-trait/async-example-desugared-manual.rs
@@ -4,11 +4,12 @@
 use std::future::Future;
 use std::task::Poll;
 
-trait MyTrait {
+#[allow(async_fn_in_trait)]
+pub trait MyTrait {
     async fn foo(&self) -> i32;
 }
 
-struct MyFuture;
+pub struct MyFuture;
 impl Future for MyFuture {
     type Output = i32;
     fn poll(self: std::pin::Pin<&mut Self>, _: &mut std::task::Context<'_>) -> Poll<Self::Output> {
@@ -17,7 +18,9 @@ impl Future for MyFuture {
 }
 
 impl MyTrait for u32 {
+    #[warn(refining_impl_trait)]
     fn foo(&self) -> MyFuture {
+        //~^ WARN impl trait in impl method signature does not match trait method signature
         MyFuture
     }
 }
diff --git a/tests/ui/async-await/in-trait/async-example-desugared-manual.stderr b/tests/ui/async-await/in-trait/async-example-desugared-manual.stderr
new file mode 100644
index 00000000000..d94afd92c56
--- /dev/null
+++ b/tests/ui/async-await/in-trait/async-example-desugared-manual.stderr
@@ -0,0 +1,22 @@
+warning: impl trait in impl method signature does not match trait method signature
+  --> $DIR/async-example-desugared-manual.rs:22:22
+   |
+LL |     async fn foo(&self) -> i32;
+   |     --------------------------- return type from trait method defined here
+...
+LL |     fn foo(&self) -> MyFuture {
+   |                      ^^^^^^^^
+   |
+   = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate
+note: the lint level is defined here
+  --> $DIR/async-example-desugared-manual.rs:21:12
+   |
+LL |     #[warn(refining_impl_trait)]
+   |            ^^^^^^^^^^^^^^^^^^^
+help: replace the return type so that it matches the trait
+   |
+LL |     fn foo(&self) -> impl Future<Output = i32> {
+   |                      ~~~~~~~~~~~~~~~~~~~~~~~~~
+
+warning: 1 warning emitted
+