Rustc suggests the same use
statement that caused the error when two modules share their name #116970
Closed
Description
opened on Oct 20, 2023
Code
I tried to reproduce the problem in the playground
mod a {
pub mod log {
pub struct S {}
}
}
use a::log::{self};
use log::SetLoggerError;
fn main() {}
Current output
The output for the playground code is the following:
error[E0432]: unresolved import `log::SetLoggerError`
--> src/main.rs:12:5
|
12 | use log::SetLoggerError;
| ^^^^^^^^^^^^^^^^^^^ no `SetLoggerError` in `a::log`
|
help: consider importing this struct instead
|
12 | use log::SetLoggerError;
| ~~~~~~~~~~~~~~~~~~~
The one I actually saw:
unresolved import `proto::LogLevelValue`
--> tests/tests/server_api.rs:3:5
|
3 | use proto::LogLevelValue;
| ^^^^^^^^^^^^^^^^^^^^ no `LogLevelValue` in `proto`
|
help: consider importing this enum instead
|
3 | use proto::LogLevelValue;
| ~~~~~~~~~~~~~~~~~~~~
The second one is worse, because "no LogLevelValue
in proto
" doesn't indicate that this proto
comes is a different proto
than the one in the suggestion. I think this happens because the modules aren't in the same file or crate, so I couldn't reproduce it in the playground.
Desired output
Ideally, rustc
should be able to notify the user that the error comes from the fact that there are two modules with the same name, instead of suggesting the same code as a fix.
Rationale and extra context
rustc 1.73.0 (cc66ad468 2023-10-03)
Other cases
No response
Anything else?
Sorry if this is duplicated, but I couldn't find an issue regarding this problem
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Name/path resolution done by `rustc_resolve` specificallyArea: Suggestions generated by the compiler applied by `cargo fix`Diagnostics: A structured suggestion resulting in incorrect code.Status: A Minimal Complete and Verifiable Example has been found for this issueRelevant to the compiler team, which will review and decide on the PR/issue.
Activity