Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suggest changing impl parameter types to match trait
This is particularly useful for cases where arbitrary self types are used, like in custom `Future`s.
- Loading branch information
Showing
12 changed files
with
151 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use std::future::Future; | ||
use std::task::{Context, Poll}; | ||
|
||
fn main() {} | ||
|
||
struct MyFuture {} | ||
|
||
impl Future for MyFuture { | ||
type Output = (); | ||
fn poll(self, _: &mut Context<'_>) -> Poll<()> { | ||
//~^ ERROR method `poll` has an incompatible type for trait | ||
todo!() | ||
} | ||
} | ||
|
||
trait T { | ||
fn foo(self); | ||
} | ||
|
||
impl T for MyFuture { | ||
fn foo(self: Box<Self>) {} | ||
//~^ ERROR method `foo` has an incompatible type for trait | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
error[E0053]: method `poll` has an incompatible type for trait | ||
--> $DIR/bad-self-type.rs:10:13 | ||
| | ||
LL | fn poll(self, _: &mut Context<'_>) -> Poll<()> { | ||
| ^^^^ | ||
| | | ||
| expected struct `Pin`, found struct `MyFuture` | ||
| help: change the self-receiver type to match the trait: `self: Pin<&mut MyFuture>` | ||
| | ||
= note: expected fn pointer `fn(Pin<&mut MyFuture>, &mut Context<'_>) -> Poll<_>` | ||
found fn pointer `fn(MyFuture, &mut Context<'_>) -> Poll<_>` | ||
|
||
error[E0053]: method `foo` has an incompatible type for trait | ||
--> $DIR/bad-self-type.rs:21:18 | ||
| | ||
LL | fn foo(self); | ||
| ---- type in trait | ||
... | ||
LL | fn foo(self: Box<Self>) {} | ||
| ------^^^^^^^^^ | ||
| | | | ||
| | expected struct `MyFuture`, found struct `Box` | ||
| help: change the self-receiver type to match the trait: `self` | ||
| | ||
= note: expected fn pointer `fn(MyFuture)` | ||
found fn pointer `fn(Box<MyFuture>)` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0053`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters