Skip to content

E0603: duplicate suggestions when using private items in value context #157454

@fee1-dead

Description

@fee1-dead

Code

mod public {
    pub struct hi;
}

mod testing {
    use crate::public::hi;
}

fn main() {
    testing::hi;
}

Current output

error[E0603]: unit struct import `hi` is private
  --> src/main.rs:10:14
   |
10 |     testing::hi;
   |              ^^ private unit struct import
   |
note: the unit struct import `hi` is defined here...
  --> src/main.rs:6:9
   |
 6 |     use crate::public::hi;
   |         ^^^^^^^^^^^^^^^^^
note: ...and refers to the unit struct `hi` which is defined here
  --> src/main.rs:2:5
   |
 2 |     pub struct hi;
   |     ^^^^^^^^^^^^^^ you could import this directly
help: consider importing this unit struct instead
   |
10 -     testing::hi;
10 +     public::hi;
   |
help: import `hi` directly
   |
10 -     testing::hi;
10 +     crate::public::hi;
   |

Desired output

error[E0603]: unit struct import `hi` is private
  --> src/main.rs:10:14
   |
10 |     testing::hi;
   |              ^^ private unit struct import
   |
note: the unit struct import `hi` is defined here...
  --> src/main.rs:6:9
   |
 6 |     use crate::public::hi;
   |         ^^^^^^^^^^^^^^^^^
note: ...and refers to the unit struct `hi` which is defined here
  --> src/main.rs:2:5
   |
 2 |     pub struct hi;
   |     ^^^^^^^^^^^^^^ you could import this directly
help: consider importing this unit struct instead
   |
10 -     testing::hi;
10 +     public::hi;
   |

Rationale and extra context

Suggestions should not be duplicated

Other cases

Rust Version

latest playground nightly

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-verboseDiagnostics: Too much output caused by a single piece of incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions