E0158 Confusing behaviour

Could someone please explain the reason behind this compile error:

pub trait Test {
    const ASSOC_CONST: u32;

    fn example(&self, some_var: u32) {
        match some_var {
            Self::ASSOC_CONST => {
                println!("matched assoc constant with value defined by concrete type")
            _ => println!("didn't match"),

I can't find a reason for the associated consts part of this error, E0158 (E0158 - Error codes index), either on the linked page or on github etc. The linked page merely states that statics are bad in patterns while constants are fine (obviously not so in this case). While I have very limited knowledge of the Rust compiler/ complex language stuff, I don't really understand the difference between normal constants and constants on traits, surely just a superficial difference.

Relevant compiler code:

let instance = match ty::Instance::resolve(self.tcx, param_env_reveal_all, def_id, substs) {
    Ok(Some(i)) => i,
    Ok(None) => {
        // It should be assoc consts if there's no error but we cannot resolve it.


        return pat_from_kind(PatKind::Wild);

    Err(_) => {
        self.tcx.sess.span_err(span, "could not evaluate constant pattern");
        return pat_from_kind(PatKind::Wild);

which also doesn't contain rationale.

The documentation is definitely mixed-up here. I've filed an issue suggesting that it be improved:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.