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

Confusing E0425 error when referencing undefined name with ::foo #63799

Closed
joshtriplett opened this issue Aug 22, 2019 · 2 comments · Fixed by #81046
Closed

Confusing E0425 error when referencing undefined name with ::foo #63799

joshtriplett opened this issue Aug 22, 2019 · 2 comments · Fixed by #81046
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name/path resolution done by `rustc_resolve` specifically C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@joshtriplett
Copy link
Member

Test program:

fn foo() { println!("foo") }

fn main() {
    ::foo()
}

This produces the following error messages:

error[E0425]: cannot find function `foo` in the crate root
 --> src/main.rs:4:7
  |
4 |     ::foo()
  |       ^^^ not found in the crate root
help: possible candidate is found in another module, you can import it into scope
  |
1 | use crate::foo;
  |

Both the error and the help seem entirely unhelpful. The error suggests that it looked for a function foo in the crate root, but in fact it looked for a crate foo. The whole "possible candidate" help seems incorrect, and adding that line would lead to a compilation failure.

@joshtriplett joshtriplett changed the title Confusing E0425 Confusing E0425 error when referencing undefined name with ::foo Aug 22, 2019
@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name/path resolution done by `rustc_resolve` specifically C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 22, 2019
@Centril
Copy link
Contributor

Centril commented Aug 22, 2019

cc @petrochenkov @estebank

@rylev
Copy link
Member

rylev commented Jan 14, 2021

This is still an issue, but at least the incorrect help message is no longer displayed:

error[E0425]: cannot find function `foo` in the crate root
 --> src/main.rs:4:7
  |
4 |     ::foo()
  |       ^^^ not found in the crate root
  

m-ou-se added a commit to m-ou-se/rust that referenced this issue Jan 20, 2021
…ebank

Improve unknown external crate error

This improves error messages when unknown items in the crate root are encountered.

Fixes rust-lang#63799

r? `@estebank`
m-ou-se added a commit to m-ou-se/rust that referenced this issue Jan 20, 2021
…ebank

Improve unknown external crate error

This improves error messages when unknown items in the crate root are encountered.

Fixes rust-lang#63799

r? ``@estebank``
@bors bors closed this as completed in a77c1d8 Jan 21, 2021
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: Name/path resolution done by `rustc_resolve` specifically C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants