Skip to content

Cannot call static methods on type aliases, "module wasn't actually a module!" #11047

Closed
@bstrie

Description

@bstrie

Compile this:

pub mod foo {
    pub mod bar {
        pub mod baz {
            struct Qux;

            impl Qux {
                pub fn new() {}
            }
        }
    }
}

fn main() {
    type Ham = foo::bar::baz::Qux;
    let Foo = foo::bar::baz::Qux::new();  // works fine
    let Bar = Ham::new();  // oops!
}
$ rustc ty.rs
!!! (resolving module in lexical scope) module wasn't actually a module!
ty.rs:16:14: 16:22 error: unresolved name
ty.rs:16     let Bar = Ham::new();
                       ^~~~~~~~
ty.rs:16:14: 16:22 error: use of undeclared module `Ham`
ty.rs:16     let Bar = Ham::new();
                       ^~~~~~~~
!!! (resolving module in lexical scope) module wasn't actually a module!
ty.rs:16:14: 16:22 error: unresolved name `Ham::new`.
ty.rs:16     let Bar = Ham::new();
                       ^~~~~~~~
error: aborting due to 3 previous errors
task 'rustc' failed at 'explicit failure', /root/catacombs/scrap/rust/src/libsyntax/diagnostic.rs:102
task '<main>' failed at 'explicit failure', /root/catacombs/scrap/rust/src/librustc/lib.rs:392

I can't imagine that this is intentional, as it greatly limits the utility of type aliases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.P-mediumMedium priority

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions