Skip to content

Rustc suggests an import that won't work if a crate and a module have the same nameΒ #90810

Closed
@jyn514

Description

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=53b3ea413465b7a61e0b2780a07a6a20

mod http {}

fn f() -> http::Parts {}

The current output is:

error[E0412]: cannot find type `Parts` in module `http`
 --> src/lib.rs:4:17
  |
4 | fn f() -> http::Parts { loop {} }
  |                 ^^^^^ not found in `http`
  |
help: consider importing one of these items
  |
2 | use http::request::Parts;
  |
2 | use http::response::Parts;
  |
2 | use http::uri::Parts;
  |
2 | use hyper::client::conn::Parts;
  |
    and 2 other candidates

Ideally the output should look like:

error[E0412]: cannot find type `Parts` in module `http`
 --> src/lib.rs:4:17
  |
4 | fn f() -> http::Parts { loop {} }
  |                 ^^^^^ not found in `http`
  |
help: consider importing one of these items
  |
2 | use ::http::request::Parts;
  |
2 | use ::http::response::Parts;
  |
2 | use ::http::uri::Parts;
  |
2 | use hyper::client::conn::Parts;
  |
    and 2 other candidates

I couldn't quite replicate it in playground, but locally (in cloudflare/wrangler-legacy@886fa42), use http::request::Parts does not give an error that it's ambiguous between the crate and module; instead it silently resolves to the module, leading to a very confusing error:

 1  error[E0433]: failed to resolve: could not find `request` in `http`
   --> src/commands/dev/gcs/server/mod.rs:21:22
    |
 21 |     mut parts: http::request::Parts,
    |                      ^^^^^^^ could not find `request` in `http`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-papercutDiagnostics: An error or lint that needs small tweaks.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