Once again, we have a case in std of adding methods and people getting broken. I really don’t want to get stuck in the sad world where we can no longer add things without new a new extension trait every time, so I want to keep this allowed breakage, but maybe there’s a way we can make it a bit less annoying.
Right now, the answer to getting the wrong method is UFCS. That certainly works, but there’s a massive gulf here—to control name resolution you need to give up on method syntax entirely, both the chaining form and the autoref behaviour. So a nice consistent method chain like
v.iter()
.filter(...)
.flatten()
.fold(..., ...)
Ends up becoming
Itertools::flatten(
v.iter().filter(...)
).fold(..., ...)
(Thankfully no extra &
s needed in this case)
The idea: What if a method name could be a path instead of just an ident?
That way the change is localized and simple, to just
v.iter()
.filter(...)
.Itertools::flatten()
.fold(..., ...)
Currently code like that gets "error: expected one of .
, ;
, ?
, }
, or an operator, found ::
", so hopefully that means it’s compatible. And it’s just restricting the search to one trait (or type, I suppose, if this needs to work with inherents) instead of all of them, so with luck it’d be low impact to do in the compiler. (And clippy would presumably be able to give a lint suggestion to remove the excess qualification should it not be needed.)
Thoughts?