Skip to content

Associated constants are not resolved on structs from other crates in patterns #30992

Closed
@petrochenkov

Description

@petrochenkov

Crate 1:

// This must be a `struct` (of any kind), but not `enum` or `type`
pub struct S;

Crate 2:

extern crate crate1;

trait Tr {
    const C: u8;
}

impl Tr for crate1::S {
    const C: u8 = 0;
}

fn main() {
    match 0u8 {
        // This must be a pattern, but not expression
        crate1::S::C => {}, // error: no associated item named `C` found for type `crate1::S` in the current scope
        _ => {},
    }
}

The reason is related to #30361, structs from other crates are defined as DefStruct and local structs are defined as DefTy.
Associated item resolution in patterns somehow works with with DefTy, but not with DefStruct.
I audited the use of both definitions in type checker, but still wasn't able to figure out what exactly happens.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions