Skip to content

Commit

Permalink
Make sure refinement still works
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Feb 5, 2024
1 parent e65abc0 commit 1a3214b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
}
Expand Down
22 changes: 22 additions & 0 deletions tests/ui/async-await/in-trait/async-example-desugared-boxed.stderr
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1a3214b

Please sign in to comment.