Files
Jacob Pratt 654c350837 Rollup merge of #154610 - jakubadamw:issue-13065, r=TaKO8Ki
Suggest public re-exports when a private module makes an import path inaccessible

This is an attempt at solving rust-lang/rust#13065.

When a `use` path fails because it passes through a private module (E0603), and a public re-export of the target item exists elsewhere, the compiler will now suggest importing through that re-export instead.

For example, given:

```rust
mod outer {
    pub use self::inner::MyStruct;
    mod inner {
        pub struct MyStruct;
    }
}

use outer::inner::MyStruct; // error: module `inner` is private
```

the compiler will now suggest use `outer::MyStruct`; - the publicly accessible path - rather than just pointing at the private module definition and leaving the user to figure out the alternative.

When possible, relative paths are suggested, including those using `super` (currently capped at a maximum of one `super` path item).

The newly added test is parametrised by editions because of the change in behaviour around `crate::`-prefixed imports in edition 2018. Perhaps that’s an overkill – I’ll be happy to remove the variations for editions 2021 and 2024.

Closes rust-lang/rust#13065.
2026-04-30 22:28:31 -04:00
..
2026-04-09 23:27:38 +08:00
2026-04-09 23:27:38 +08:00