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

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

Closed
jyn514 opened this issue Nov 11, 2021 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jyn514
Copy link
Member

jyn514 commented Nov 11, 2021

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`
@jyn514 jyn514 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. D-papercut Diagnostics: An error or lint that needs small tweaks. labels Nov 11, 2021
@fmease
Copy link
Member

fmease commented May 3, 2024

The current output (stable, nightly) is now exactly what you've suggested (suggesting global paths).
I fixed it some time ago in #117009.
Closing as fixed.

@fmease fmease closed this as completed May 3, 2024
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 D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants