Remix.run Logo
cjfd 3 days ago

The problem seems to be that people want this to be implicit. If you have to call an explicit function to turn an instance of type A into an instance of BTrait anyone can define such a function anywhere.

magicalhippo 3 days ago | parent [-]

Alternatively do what's done for functions in other languages (I don't use Rust) and use the most recently defined one.

That could lead to different results if you change include/import order but hey if you don't want that then just be explicit.

marcosdumay 3 days ago | parent [-]

That's not exactly what's done for functions. Scoping rules are always more complex than that.

But the good news is that the same rules are good for implicits too. You look back your tree to find a definition, and if it's defined only once on the most internal level, use that definition, otherwise require an explicit annotation. Add some way to annotate over the entire scope, and some way to export implicits globally for completeness.

This will lead to all kinds of problems with implicit imports that every other kind of named object has too. That's not a big deal, developers are used to those.