-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Method resolution fails to find inherent method on custom Deref type #53843
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
It's specifically the transitive dereferencing that causes the bug, if the deref impl is changed to this it compiles fine: impl<P> Deref for Pin<P> where {
type Target = P;
fn deref(&self) -> &P {
&self.0
}
} |
I managed to reduce it a bit more: use std::{
ops::Deref,
};
pub struct Pin<P>(P);
impl<P, T> Deref for Pin<P>
where
P: Deref<Target=T>,
{
type Target = T;
fn deref(&self) -> &T {
&*self.0
}
}
impl<P> Pin<P> {
fn poll(self) {}
}
fn main() {
let mut unit = ();
let pin = Pin(&mut unit);
pin.poll();
} The error goes away if you remove the Of course, the final type of autoderef in this case should actually be |
My last comment is only for the "type annotations needed" error. I thought the "no method named |
Never mind, looks like the ambiguity error is triggering the "method not found" error. The reason is the |
The problem is that autoderef is not eagerly executing nested obligations. The original reason for that is that we can't use the "outer" fulfillment context, while creating a nested fulfillment context felt like it would cause problems (or maybe it did cause a problem back then?). I'm not sure there's a good reason not to create a fulfillment context and drain it there, only passing the remaining obligations downwards. cc @nikomatsakis |
Now that we have canonoicalization, I'm think a good idea would be to do the autoderef chain in a "canonicalization context", and only apply a deref when we are considering it. |
I've assigned @nikomatsakis and @eddyb with the hopes that we can make some progress here :-) |
Note that this version does compile: use std::ops::Deref;
pub struct Pin<P>(P);
impl<P> Deref for Pin<P> where
P: Deref,
{
type Target = P::Target;
fn deref(&self) -> &P::Target {
&*self.0
}
}
impl<'a, F> Pin<&'a mut F> {
fn poll(self) {}
}
fn test(pin: Pin<&mut ()>) {
pin.poll()
} The only difference is that I am using |
Sounds from @cramertj that this should be enough to unblock the pin API work -- thanks @nikomatsakis! |
This is a hack-fix to rust-lang#53843, but I am worried it might break things because it makes the "inference pollution" problem worse. Fixes rust-lang#53843 (but introduces a bug that someone might notice).
process nested obligations in autoderef This is a hack-fix to #53843, but I am worried it might break things because it makes the "inference pollution" problem worse. I need to do the "autoderef querification" thing somehow to solve t. Fixes #53843 (but introduces a bug that someone might notice). r? @nikomatsakis
This is a hack-fix to rust-lang#53843, but I am worried it might break things because it makes the "inference pollution" problem worse. Fixes rust-lang#53843 (but introduces a bug that someone might notice).
process nested obligations in autoderef This is a hack-fix to #53843, but I am worried it might break things because it makes the "inference pollution" problem worse. I need to do the "autoderef querification" thing somehow to solve t. Fixes #53843 (but introduces a bug that someone might notice). r? @nikomatsakis
This is a hack-fix to rust-lang#53843, but I am worried it might break things because it makes the "inference pollution" problem worse. Fixes rust-lang#53843 (but introduces a bug that someone might notice).
process nested obligations in autoderef Fixes #53843. r? @nikomatsakis
This cannot find the
poll
method onPin
:https://play.rust-lang.org/?gist=6e3b3f6f3aa4e8a49cb45480f4dd7e7a&version=stable&mode=debug&edition=2015
This clearly should compile.
This bug may be a blocker on changing the Pin API to a composeable form.
cc @nikomatsakis @eddyb @arielb1 @cramertj
The text was updated successfully, but these errors were encountered: