Skip to content

Commit 7db77e1

Browse files
Make sure refinement still works
1 parent 500443f commit 7db77e1

4 files changed

+53
-3
lines changed

tests/ui/async-await/in-trait/async-example-desugared-boxed.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
use std::future::Future;
55
use std::pin::Pin;
66

7-
trait MyTrait {
7+
#[allow(async_fn_in_trait)]
8+
pub trait MyTrait {
89
async fn foo(&self) -> i32;
910
}
1011

1112
impl MyTrait for i32 {
13+
#[warn(refining_impl_trait)]
1214
fn foo(&self) -> Pin<Box<dyn Future<Output = i32> + '_>> {
15+
//~^ WARN impl trait in impl method signature does not match trait method signature
1316
Box::pin(async { *self })
1417
}
1518
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
warning: impl trait in impl method signature does not match trait method signature
2+
--> $DIR/async-example-desugared-boxed.rs:14:22
3+
|
4+
LL | async fn foo(&self) -> i32;
5+
| --------------------------- return type from trait method defined here
6+
...
7+
LL | fn foo(&self) -> Pin<Box<dyn Future<Output = i32> + '_>> {
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9+
|
10+
= note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate
11+
note: the lint level is defined here
12+
--> $DIR/async-example-desugared-boxed.rs:13:12
13+
|
14+
LL | #[warn(refining_impl_trait)]
15+
| ^^^^^^^^^^^^^^^^^^^
16+
help: replace the return type so that it matches the trait
17+
|
18+
LL | fn foo(&self) -> impl Future<Output = i32> {
19+
| ~~~~~~~~~~~~~~~~~~~~~~~~~
20+
21+
warning: 1 warning emitted
22+

tests/ui/async-await/in-trait/async-example-desugared-manual.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
use std::future::Future;
55
use std::task::Poll;
66

7-
trait MyTrait {
7+
#[allow(async_fn_in_trait)]
8+
pub trait MyTrait {
89
async fn foo(&self) -> i32;
910
}
1011

11-
struct MyFuture;
12+
pub struct MyFuture;
1213
impl Future for MyFuture {
1314
type Output = i32;
1415
fn poll(self: std::pin::Pin<&mut Self>, _: &mut std::task::Context<'_>) -> Poll<Self::Output> {
@@ -17,7 +18,9 @@ impl Future for MyFuture {
1718
}
1819

1920
impl MyTrait for u32 {
21+
#[warn(refining_impl_trait)]
2022
fn foo(&self) -> MyFuture {
23+
//~^ WARN impl trait in impl method signature does not match trait method signature
2124
MyFuture
2225
}
2326
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
warning: impl trait in impl method signature does not match trait method signature
2+
--> $DIR/async-example-desugared-manual.rs:22:22
3+
|
4+
LL | async fn foo(&self) -> i32;
5+
| --------------------------- return type from trait method defined here
6+
...
7+
LL | fn foo(&self) -> MyFuture {
8+
| ^^^^^^^^
9+
|
10+
= note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate
11+
note: the lint level is defined here
12+
--> $DIR/async-example-desugared-manual.rs:21:12
13+
|
14+
LL | #[warn(refining_impl_trait)]
15+
| ^^^^^^^^^^^^^^^^^^^
16+
help: replace the return type so that it matches the trait
17+
|
18+
LL | fn foo(&self) -> impl Future<Output = i32> {
19+
| ~~~~~~~~~~~~~~~~~~~~~~~~~
20+
21+
warning: 1 warning emitted
22+

0 commit comments

Comments
 (0)