mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-17 01:13:11 +00:00
Make sure refinement still works
This commit is contained in:
parent
e65abc0ea5
commit
1a3214b774
@ -4,12 +4,15 @@
|
|||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
|
|
||||||
trait MyTrait {
|
#[allow(async_fn_in_trait)]
|
||||||
|
pub trait MyTrait {
|
||||||
async fn foo(&self) -> i32;
|
async fn foo(&self) -> i32;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MyTrait for i32 {
|
impl MyTrait for i32 {
|
||||||
|
#[warn(refining_impl_trait)]
|
||||||
fn foo(&self) -> Pin<Box<dyn Future<Output = i32> + '_>> {
|
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 })
|
Box::pin(async { *self })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
|
@ -4,11 +4,12 @@
|
|||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::task::Poll;
|
use std::task::Poll;
|
||||||
|
|
||||||
trait MyTrait {
|
#[allow(async_fn_in_trait)]
|
||||||
|
pub trait MyTrait {
|
||||||
async fn foo(&self) -> i32;
|
async fn foo(&self) -> i32;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MyFuture;
|
pub struct MyFuture;
|
||||||
impl Future for MyFuture {
|
impl Future for MyFuture {
|
||||||
type Output = i32;
|
type Output = i32;
|
||||||
fn poll(self: std::pin::Pin<&mut Self>, _: &mut std::task::Context<'_>) -> Poll<Self::Output> {
|
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 {
|
impl MyTrait for u32 {
|
||||||
|
#[warn(refining_impl_trait)]
|
||||||
fn foo(&self) -> MyFuture {
|
fn foo(&self) -> MyFuture {
|
||||||
|
//~^ WARN impl trait in impl method signature does not match trait method signature
|
||||||
MyFuture
|
MyFuture
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user