Final associated constants?

Tracking issue for RFC 3678: Trait method impl restrictions (`final` methods) · Issue #131179 · rust-lang/rust · GitHub is about final methods, but I think it might be equally valuable for associated constants.

For example, I currently have a piece of code that looks like this (nightly, not sure if it works on stable):

pub trait InstructionIsa<Cfg>: Instruction {
    // ...

    const ISA_STRING: &'static str = const {
        isa_string(
            Self::Reg::XLEN,
            &InheritedIsa::new::<Self, Cfg>(),
            Self::IMPLEMENTED_EXTENSIONS,
        )
    }
    .unsize()
    .as_str();

And I'm not sure I want implementers to be able to override its implementation, but I can only avoid that if I convert it to a method, which is unfortunate.

So the question is: should final associated constants be a thing too?

1 Like