Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
petrochenkov opened this issue Jan 18, 2016 · 0 comments · Fixed by #31010
Closed

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

petrochenkov opened this issue Jan 18, 2016 · 0 comments · Fixed by #31010

Comments

@petrochenkov
Copy link
Contributor

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.

bors added a commit that referenced this issue Jan 21, 2016
All structs and their constructors are defined as `DefStruct`.
`DefTy` is splitted into `DefEnum` and `DefTyAlias`.
Ad hoc flag `bool is_structure` is removed from `DefVariant`, it was required in one place in resolve and could be obtained by other means.
Flag `bool is_ctor` is removed from `DefFn`, it wasn't really used for constructors outside of metadata decoding.

Observable effects:
More specific error messages are selected in some cases.
Two name resolution bugs fixed (#30992 and FIXME in compile-fail/empty-struct-braces-expr.rs).

Fixes #30992
Closes #30361
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant