Hello, I'm reviewing RFC #3913: Natural Method Disambiguation (Pre-RFC: Proposal: Syntactic Sugar for Disambiguating Conflicting Trait Methods), and I'm a bit doubtful of the RFC's reason for expr.Self::method(...) instead of expr.<Self>::method(...) (underline & i.e. mine):
In
implblocks, we can applyobj.Selfto objects that do not have the type namedSelfin that block.obj.<Self>would look like we are trying to apply a method of one type to an object of another type even if they happen to be the same.(i.e. the
Selfinexpr.<Self>::method(...)currently proposed isexpr.Self::method(...), as an indicator for "restrict to inherent methods", is easily confused with theSelftype of the currentimplblock ortraitblock)
Unfortunately, I find it hard to find examples to test this statement, other than this example in the RFC. Therefore, I am looking for code samples that:
- has a means of calling an inherent method, where, without that means, the default semantics would be to call a trait method
- does the call to the inherent method in an
implblock ortraitblock - in that
implblock ortraitblock, also uses the keyword typeSelf - preferably, the value whose inherent method is being called, has a different type from the
Selftype of theimplblock ortraitblock
The above translation of the semantics may be a bit inaccurate; what I'm ultimately looking for is code that could be rewritten using RFC's syntax to look like this:
impl ... {
fn ... {
let v = vec![Self::new(); 999];
v.iter().for_each(|x| x.Self::method());
// where x.method() would call SomeTrait::method
// which is not what we want
// Note: this fails criterion #4 but I can't think of
// something that does for now
}
}
And, as mentioned above, I'm also looking for opinions of whether that syntax should be expr.Self::method(...), or expr.<Self>::method(...), or something else.
Note: My main purpose for the topic is to collect code samples, so please include a working code sample!! You can add your opinions, but since my main purpose is to collect code samples, I won't show my approval/diasapproval.