mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-02 00:07:42 +03:00
654c350837
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.