Are object-safe associated constants possible?


#1

It is possible to make an associated function object safe by adding where Self: Sized bound. Is there a similar trick for associated constants?

Here’s the playground which demonstrates the problem: https://play.rust-lang.org/?gist=bfe8fb1b0b73b6d424e5bdc2f3716df2&version=stable


#2

This appears to be a well-known limitation, perhaps temporary. There’s some discussion of this in https://github.com/rust-lang/rust/issues/26847 and in this Reddit thread. The “workaround” (i.e. a pair of traits, one with an associated const and another without) is a real hack :slight_smile:.