Skip to content
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

pub(restricted) produces misleading diagnostic for private type in public interface lint #33174

Closed
strega-nil opened this issue Apr 24, 2016 · 4 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@strega-nil
Copy link
Contributor

pub struct DoopGeneral<T> {
  pub(crate) var: T,
}
pub type Doop = DoopGeneral<Inner>;
pub(crate) struct Inner;

fails with error: private type in public interface [E0446]

https://play.rust-lang.org/?gist=35cee8425ac59ef27aa8898bd6343083&version=nightly&backtrace=0

@petrochenkov
Copy link
Contributor

The error itself is correct, but the error messages are not updated yet.
Doop and Inner don't have the same scope (visibility), Doop is pub so its visibility is "all crates", Inner is pub(crate) so its visibility is "this crate".
Items with visibility v can't use items with visibilities v' < v in their interfaces.

@strega-nil
Copy link
Contributor Author

strega-nil commented Apr 24, 2016

@petrochenkov Oh, I see what you mean. This is... kinda annoying? But at least I understand it now.

@steveklabnik
Copy link
Member

/cc #32409

@steveklabnik steveklabnik added the A-diagnostics Area: Messages for errors, warnings, and lints label Jul 25, 2016
@Mark-Simulacrum Mark-Simulacrum changed the title Error: private type in public interface with pub(restricted), even though it has the same scope pub(restricted) produces misleading diagnostic for private type in public interface lint May 7, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 25, 2017
@estebank
Copy link
Contributor

The current output has better wording:

error[E0446]: private type `Inner` in public interface
 --> src/main.rs:6:1
  |
6 | pub type Doop = DoopGeneral<Inner>;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type

It should probably be expanded to be

error[E0446]: private type `Inner` in public interface
 --> src/main.rs:6:1
  |
6 | pub type Doop = DoopGeneral<Inner>;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
7 | pub(crate) struct Inner;
  | ----------------------- private type being leaked

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 C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

5 participants