Rustc suggests an import that won't work if a crate and a module have the same nameΒ #90810
Closed
Description
opened on 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`
Activity