Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ZaneErebos opened this issue May 8, 2025 · 1 comment
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name/path resolution done by `rustc_resolve` specifically A-visibility Area: Visibility / privacy D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ZaneErebos
Copy link

ZaneErebos commented May 8, 2025

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;
   |
@ZaneErebos ZaneErebos added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 8, 2025
@xizheyin
Copy link
Contributor

xizheyin commented May 9, 2025

@rustbot claim

@fmease fmease added A-resolve Area: Name/path resolution done by `rustc_resolve` specifically A-visibility Area: Visibility / privacy D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels May 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name/path resolution done by `rustc_resolve` specifically A-visibility Area: Visibility / privacy D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants