You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Method resolution fails to find inherent method on custom Deref type #53843
use std::{
ops::Deref,};pubstructPin<P>(P);impl<P,T>DerefforPin<P>whereP:Deref<Target=T>,{typeTarget = T;fnderef(&self) -> &T{&*self.0}}impl<P>Pin<P>{fnpoll(self){}}fnmain(){letmut unit = ();let pin = Pin(&mut unit);
pin.poll();}
The error goes away if you remove the Deref impl for Pin altogether. What happens is the final type produced by autoderef is an inference variable (https://github.com/rust-lang/rust/blob/master/src/librustc_typeck/check/method/probe.rs#L349), causing an error to be raised when structurally_resolved_type is called, because that type could have another method named poll that might conflict. Without the Deref impl for Pin, the error goes away, because the final type for autoderef is just Pin<&mut ()>.
Of course, the final type of autoderef in this case should actually be <Pin<&mut ()> as Deref>::Target, which is (). The fact that it is an inference variable seems like a bug.
My last comment is only for the "type annotations needed" error. I thought the "no method named poll found for type Pin<&mut ()>" error was also being caused by that, but it looks like it might be separate. Investigating...
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.
Activity
withoutboats commentedon Aug 31, 2018
It's specifically the transitive dereferencing that causes the bug, if the deref impl is changed to this it compiles fine:
mikeyhew commentedon Aug 31, 2018
I managed to reduce it a bit more:
The error goes away if you remove the
Derefimpl forPinaltogether. What happens is the final type produced by autoderef is an inference variable (https://github.com/rust-lang/rust/blob/master/src/librustc_typeck/check/method/probe.rs#L349), causing an error to be raised whenstructurally_resolved_typeis called, because that type could have another method namedpollthat might conflict. Without theDerefimpl forPin, the error goes away, because the final type for autoderef is justPin<&mut ()>.Of course, the final type of autoderef in this case should actually be
<Pin<&mut ()> as Deref>::Target, which is(). The fact that it is an inference variable seems like a bug.mikeyhew commentedon Aug 31, 2018
My last comment is only for the "type annotations needed" error. I thought the "no method named
pollfound for typePin<&mut ()>" error was also being caused by that, but it looks like it might be separate. Investigating...mikeyhew commentedon Aug 31, 2018
Never mind, looks like the ambiguity error is triggering the "method not found" error. The reason is the
return Nonehere (https://github.com/rust-lang/rust/blob/master/src/librustc_typeck/check/method/probe.rs#L351), which makes the caller think that no methods by that name were found. If we remove that early return it should avoid the double error.arielb1 commentedon Aug 31, 2018
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
arielb1 commentedon Aug 31, 2018
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.
aturon commentedon Sep 14, 2018
I've assigned @nikomatsakis and @eddyb with the hopes that we can make some progress here :-)
nikomatsakis commentedon Sep 14, 2018
Note that this version does compile:
The only difference is that I am using
P::Targetand notTaturon commentedon Sep 14, 2018
Sounds from @cramertj that this should be enough to unblock the pin API work -- thanks @nikomatsakis!
process nested obligations in autoderef
Auto merge of #54252 - arielb1:deref-query, r=<try>
process nested obligations in autoderef