E0603: import directly/through re-export should attach good suggestions for grouped imports
Open
@raushan728 is already working on this.
Since Jun 25, 2026.
A-diagnostics
D-lack-of-suggestion
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
mod one {
pub struct One();
}
mod two {
use crate::one::One;
pub struct Two();
}
mod test {
use crate::two::{One, Two};
use std::{fs::Path};
}
Current output
error[E0603]: struct import `One` is private
--> src/lib.rs:11:22
|
11 | use crate::two::{One, Two};
| ^^^ private struct import
|
note: the struct import `One` is defined here...
--> src/lib.rs:6:9
|
6 | use crate::one::One;
| ^^^^^^^^^^^^^^^
note: ...and refers to the struct `One` which is defined here
--> src/lib.rs:2:5
|
2 | pub struct One();
| ^^^^^^^^^^^^^^^^^ you could import this directly
error[E0603]: struct `Path` is private
--> src/lib.rs:12:19
|
12 | use std::{fs::Path};
| ^^^^ private struct
|
note: the struct `Path` is defined here
--> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/fs.rs:46:19
|
46 | use crate::path::{Path, PathBuf};
| ^^^^
Desired output
error[E0603]: struct import `One` is private
--> src/lib.rs:11:22
|
11 | use crate::two::{One, Two};
| ^^^ private struct import
|
note: the struct import `One` is defined here...
--> src/lib.rs:6:9
|
6 | use crate::one::One;
| ^^^^^^^^^^^^^^^
note: ...and refers to the struct `One` which is defined here
--> src/lib.rs:2:5
|
2 | pub struct One();
| ^^^^^^^^^^^^^^^^^ you could import this directly
help: import `One` through the re-export
|
10 | +use crate::one::One;
11 | ~use crate::two::Two;
error[E0603]: struct `Path` is private
--> src/lib.rs:12:19
|
12 | use std::{fs::Path};
| ^^^^ private struct
|
note: the struct `Path` is defined here
--> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/fs.rs:46:19
|
46 | use crate::path::{Path, PathBuf};
| ^^^^
help: import `Path` directly
|
12 | ~use std::path::Path;
Rationale and extra context
#156244 fixed #156060 and #155348 by not emitting a suggestion at all, however I think we could still emit good suggestion, by: extracting an import out of a group and use the right path if the path is inside a group; or change the entire import if we're in a group of 1.
Other cases
Rust Version
latest playground nightly
Anything else?
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.