-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.F-arbitrary_self_types`#![feature(arbitrary_self_types)]``#![feature(arbitrary_self_types)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
In the error message below, the first argument of poll
is not named self
.
use core::future::Future;
struct S;
impl Future for S {}
Errors:
Compiling playground v0.0.1 (/playground)
error[E0046]: not all trait items implemented, missing: `Output`, `poll`
--> src/lib.rs:4:1
|
4 | impl Future for S {}
| ^^^^^^^^^^^^^^^^^ missing `Output`, `poll` in implementation
|
= help: implement the missing item: `type Output = Type;`
= help: implement the missing item: `fn poll(_: std::pin::Pin<&mut Self>, _: &mut std::task::Context<'_>) -> std::task::Poll<<Self as std::future::Future>::Output> { unimplemented!() }`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0046`.
error: could not compile `playground`.
To learn more, run the command again with --verbose.
@rustbot modify labels: T-compiler, A-diagnostics, C-enhancement, D-papercut, F-arbitrary_self_types.
This issue has been assigned to @Duddino via this comment.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.F-arbitrary_self_types`#![feature(arbitrary_self_types)]``#![feature(arbitrary_self_types)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Activity
Duddino commentedon Apr 15, 2020
@rustbot claim
Duddino commentedon Apr 15, 2020
I managed to fix this issue by just manually checking if the argument is of type
std::pin::Pin<&mut Self>
, and if it is it returnsformat!("self: {}", ty);
where ty is the type of the argument (in this case std::pin::Pin<&mut Self>). I'm not sure if there is a better way, I'm going to make a PR tomorrow, if anyone has a better solution, please tell me.steffahn commentedon Apr 15, 2020
I’m not just interested in a fix for this particular case. Types that allow dispatch can be arbitrarily nested AFAIK and also I didn’t tag
F-arbitrary_self_types
for no reason - these can be extended. Furthermore the correct way to fix this is probably not to just add code but rather to changeexisting logic that must be somewhere already, for example some code currently does make...... let me double-check that....self
,&self
and&mut self
parameters print correctly and differently from non-self parameters that have typeSelf
orOh, wow, I’ll expand this bug-report.
Hint about missing trait method suggests incorrect code (non-self parameter mistakenly named "self").
Create a binary crate named “my-crate” with:
main.rs
lib.rs
Error message is:
Duddino commentedon Apr 15, 2020
Makes sense as if I recall correctly (can't link files rn as I am on my phone) the code literally just checks if the type is (&/&mut)Self and if it is it prints (&/&mut)self otherwise it prints _: Type. A potential fix could be printing (&/&mut)self only if it's the first argument of the function
steffahn commentedon Apr 15, 2020
Won’t be enough. The first parameter of a trait fn could be of type
Self
without being namedself
. It actually needs to check if it’s aself
parameter. That information should be retrievable somewhere in the compiler. Furthermore then the rest is easy: First step: check if it’s aself
parameter. If not: use_ : {ty}
. If it however is one, then check for the type beingSelf
or&Self
or&mut Self
, printingself
,&self
or&mut self
respectively; otherwise printself: {ty}
.Duddino commentedon Apr 16, 2020
Another issue related to this is when you have a function that has a signature of
fn name(whatever: &Self);
The compiler suggests to implement the function usingfn name(&self){ todo!() };
, but that doesn't workI should have fixed it, as soon as all of the tests pass I will make a PR
Rollup merge of rust-lang#71188 - Duddino:fix, r=matthewjasper
Rollup merge of rust-lang#71188 - Duddino:fix, r=matthewjasper