Skip to content

Calling a static method on a type with no static method gives undeclared module error #7950

Closed
@huonw

Description

@huonw
rusti> enum Foo{Bar} Foo::doesnt_exist()
rust: ~"\"!!! (resolving module in lexical scope) module wasn\\\'t actually a module!\""
<anon>:16:0: 16:17 error: unresolved name
<anon>:16 Foo::doesnt_exist();
          ^~~~~~~~~~~~~~~~~
<anon>:16:0: 16:17 error: use of undeclared module `Foo`
<anon>:16 Foo::doesnt_exist();
          ^~~~~~~~~~~~~~~~~
<anon>:16:0: 16:17 error: unresolved name `Foo::doesnt_exist`.
<anon>:16 Foo::doesnt_exist();
          ^~~~~~~~~~~~~~~~~
error: aborting due to 3 previous errors
rust: task failed at 'explicit failure', /home/huon/rust/src/libsyntax/diagnostic.rs:96
rusti> enum Foo{Bar} impl Foo { fn exists() {} } Foo::doesnt_exist()
<anon>:19:0: 19:17 error: unresolved name `Foo::doesnt_exist`.
<anon>:19 Foo::doesnt_exist();
          ^~~~~~~~~~~~~~~~~
error: aborting due to previous error

This is pretty confusing, it'd be nice to at least mention that there isn't a static method with that name like in the second run where there is another static method.

I presume this is because static methods create a secret mod with the same name as the type, one possible resolution would be to always create this mod rather than only doing so when required.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specifically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions