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

E0446 Doesn't Trigger For Types In Private Modules #89264

Open
danii opened this issue Sep 26, 2021 · 3 comments
Open

E0446 Doesn't Trigger For Types In Private Modules #89264

danii opened this issue Sep 26, 2021 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@danii
Copy link
Contributor

danii commented Sep 26, 2021

Declaring a public type and a public function in a private module, and then publicly reexporting the function doesn't trigger the E0446 error on using private types in public interfaces.

mod module {
  pub struct Private; // This isn't available outside of the crate because the module it is in is private.
  
  pub fn public() -> Private {Private} // This is available outside of the crate...
}

pub use module::public; // ...because of this reexport here.

I expected to see the E0446 error, because the above code is semantically equivalent to this code, from a downstream crate's point of view.

struct Private;

pub fn public() -> Private {Private} // error[E0446]: private type `Private2` in public interface

Meta

This bug occurs both on Rust version rustc 1.56.0-nightly (3d0774d0d 2021-08-18) and version rustc 1.54.0 (a178d0322 2021-07-26).

@danii danii added the C-bug Category: This is a bug. label Sep 26, 2021
@ExpHP
Copy link
Contributor

ExpHP commented Sep 28, 2021

I don't think this is a bug. It is a central part of the sealed trait pattern. (Essentially, it allows one to define "Voldemort traits" akin to D's Voldemort types)

@pierwill
Copy link
Member

pierwill commented Jan 13, 2022

Should there be a lint for this (compiler or clippy) in certain cases, if there are any outside the sealed trait pattern? 🤔

@rustbot label +A-diagnostics +A-lint -C-bug

@rustbot rustbot added A-diagnostics Area: Messages for errors, warnings, and lints A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. and removed C-bug Category: This is a bug. labels Jan 13, 2022
@Noratrieb Noratrieb added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 5, 2023
@emilk
Copy link

emilk commented Oct 10, 2023

This bites me all the time. I usually mark most my things pub in each moduile, and then in the top lib.rs I decide what will be public to crate users. Because of this bug, E0446 almost never prevents me from "half-exporting" things (exporting a function but not its return-value, for instance).

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-lint Area: Lints (warnings about flaws in source code) such as unused_mut. 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

6 participants