Skip to content

E0603: relative paths are not being correctly suggested for help: import directly #157455

Description

@fee1-dead

Code

mod public {
    pub struct hi;
}

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

use testing::hi;

Current output

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

Desired output

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

Rationale and extra context

super is not correct

Other cases

Rust Version

latest playground nightly

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-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