Idea: trait methods with un-overridable implementations

The type_name example is related to #57893; namely, always preferring the user defined method in cases of overlap breaks invocations of .type_id() on dyn Any (preferring the built-in implementation in that case is load bearing). Which is considered unfortunate as preferring the user implementation is the best fix from a soundness perspective, as I understand it.[1]

Whatever ends up happening to fix that bug will probably involve weird exceptions no matter what. The new trait solver already prefers the user implementation in more cases.

If final fn is always not in the vtable, it would basically act like preferring the user implementation. Corollary: Any::type_id could not be a final fn.


  1. See this example of preferring the built-in implementation causing unsoundness. ↩︎

1 Like