rust-lang / rust-lang/rust

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

Open
#140,831 1 comment 0 reactions 1 assignee View on GitHub

@xizheyin is already working on this.

Since May 9, 2025.

A-diagnostics A-resolve A-visibility D-invalid-suggestion T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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;
   |

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.