Make sure refinement still works

This commit is contained in:
Michael Goulet 2024-01-18 17:28:37 +00:00
parent e65abc0ea5
commit 1a3214b774
4 changed files with 53 additions and 3 deletions

View File

@ -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 })
}
}

View File

@ -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

View File

@ -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
}
}

View File

@ -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