Skip to content

"[E0603] unit variant X is private. help: import X directly" suggests invalid path in private module #140831

Open
@ZaneErebos

Description

@ZaneErebos

Code

pub fn parse_config() {
  let _json = jso::parse::Null;
}

Current output

error[E0603]: unit variant `Null` is private
  --> src/lib.rs:2:27
   |
2  |   let _json = jso::parse::Null;
   |                           ^^^^ private unit variant
   |
note: the unit variant `Null` is defined here
  --> /home/user/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/jso-1.0.0/src/parse.rs:11:24
   |
11 | use crate::Val::{self, *};
   |                        ^
help: consider importing this unit variant instead
   |
2  -   let _json = jso::parse::Null;
2  +   let _json = jso::Val::Null;
   |
help: import `Null` directly
   |
2  -   let _json = jso::parse::Null;
2  +   let _json = jso::val::Val::Null::Null;
   |

Desired output

error[E0603]: unit variant `Null` is private
  --> src/lib.rs:2:27
   |
2  |   let _json = jso::parse::Null;
   |                           ^^^^ private unit variant
   |
note: the unit variant `Null` is defined here
  --> /home/user/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/jso-1.0.0/src/parse.rs:11:24
   |
11 | use crate::Val::{self, *};
   |                        ^
help: consider importing this unit variant instead
   |
2  -   let _json = jso::parse::Null;
2  +   let _json = jso::Val::Null;
   |

Rationale and extra context

The first suggestion to use Val::Null is fine. The second suggestion has 2 issues:

  1. the val module is private
  2. Val::Null::Null is not a valid path
    thus it is not needed in this case

Other cases

Rust Version

rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: x86_64-unknown-linux-gnu
release: 1.86.0
LLVM version: 19.1.7

Anything else?

Stumbled upon this because I noticed rust-analyzer was only suggesting types in type position. Wanted to see if it would suggest functions where applicable, and noticed it was also suggesting imported (but not re-exported) items in the scope of the parse module of the crate.

If you use the suggestion of val::Val::Null:Null, it will tell you the val mod is private, but once again also suggests to use an invalid path, Val::Null::Null:

[...]

error[E0603]: module `val` is private
  --> src/lib.rs:2:20
   |
2  |   let _json = jso::val::Val::Null::Null;
   |                    ^^^ private module
   |
note: the module `val` is defined here
  --> /home/user/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/jso-1.0.0/src/lib.rs:14:1
   |
14 | mod val;
   | ^^^^^^^
help: consider importing this variant instead
   |
2  -   let _json = jso::val::Val::Null::Null;
2  +   let _json = jso::Val::Null::Null;
   |

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyA-visibilityArea: Visibility / privacyD-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