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

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

Closed
huonw opened this issue Jul 22, 2013 · 2 comments · Fixed by #23411
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Path resolution

Comments

@huonw
Copy link
Member

huonw commented Jul 22, 2013

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.

@thestinger
Copy link
Contributor

triage bump

@huonw
Copy link
Member Author

huonw commented May 16, 2014

New example:

struct Foo;
fn main() {
    Foo::bar();
}
ERROR:rustc::middle::resolve: !!! (resolving module in lexical scope) module wasn't actually a module!
<anon>:18:21: 18:29 error: unresolved name
<anon>:18         struct Foo; Foo::bar()
                              ^~~~~~~~
<anon>:18:21: 18:29 error: use of undeclared module `Foo`
<anon>:18         struct Foo; Foo::bar()
                              ^~~~~~~~
ERROR:rustc::middle::resolve: !!! (resolving module in lexical scope) module wasn't actually a module!
<anon>:18:21: 18:29 error: unresolved name `Foo::bar`.
<anon>:18         struct Foo; Foo::bar()
                              ^~~~~~~~
error: aborting due to 3 previous errors
playpen: application terminated with error code 101

(The ERROR lines should disappear after #14239 lands.)

emberian added a commit that referenced this issue Mar 16, 2015
bors added a commit that referenced this issue Mar 16, 2015
flip1995 pushed a commit to flip1995/rust that referenced this issue Nov 23, 2021
Fix `explicit_counter_loop` suggestion for non-usize types

changelog: Add a new suggestion for non-usize types in [`explicit_counter_loop`]

closes: rust-lang#7920
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Path resolution
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants