Skip to content

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

Closed
@joshtriplett

Description

@joshtriplett

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions