Open weiznich opened 4 months ago
Minimized reproduction:
trait Requirement {}
trait Extension {
fn foo(self, x: i32)
where
Self: Requirement;
}
impl<T> Extension for T {
fn foo(self)
where
Self: Requirement,
{
}
}
struct Thing;
impl Thing {
fn foo(&self) {} // Note: &self, not self
}
fn what(x: Thing) {
x.foo()
}
This happens because, when resolving the method call, rust checks calling the method on Thing
before trying to call the method on &Thing
. See the reference, which states that "This process does not take into account the mutability or lifetime of the receiver, or whether a method is unsafe." Is appears that this process also doesn't take into account the where
bounds on the method.
This can be worked around by using the disambiguated function call syntax, e.g. Thing::foo(&x)
I tried this code:
I expected to see this happen: Code compiles without error as
ArcSwap::load()
existsInstead, this happened: Code fails to compile with the following error:
The method provided by diesel does clearly not apply as:
Meta
rustc --version --verbose
:(Although the same behavior can be observed with the latest nightly compiler)
Backtrace
```
```