Skip to content

Rustc suggests the same use statement that caused the error when two modules share their name #116970

Closed
@CastilloDel

Description

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

Activity

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

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-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