Skip to content

match variant with fields unresolved when enum type in scope #14221

@pnkfelix

Description

@pnkfelix

Here is some code (derived from something I actually saw recently in rustc):

pub mod a {
    pub enum E {
                         A,
                         B,
        #[cfg(show_bug)] C(int),
    }
    pub mod b {
        pub fn key(e: ::a::E) -> StrBuf {
            match e {
                                 A => "A",
                                 B => "B",
                #[cfg(show_bug)] C(_) => "C",

            }.to_strbuf()
        }
    }
}

fn main() {
    println!("Hello World {}", a::b::key(a::A));
}

Now the bug:

% rustc /tmp/e.rs && ./e
Hello World A
% rustc --cfg show_bug /tmp/e.rs && ./e
/tmp/e.rs:12:34: 12:35 error: unresolved enum variant, struct or const `C`
/tmp/e.rs:12                 #[cfg(show_bug)] C(_) => "C",
                                              ^
error: aborting due to previous error

(The workaround is to explicitly import the enum variant with the field. It does not suffice to just do use a::EnumType; see comments below.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-resolveArea: Name/path resolution done by `rustc_resolve` specifically

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions