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

private_in_public warning for private methods #40844

Closed
bluss opened this issue Mar 26, 2017 · 2 comments
Closed

private_in_public warning for private methods #40844

bluss opened this issue Mar 26, 2017 · 2 comments
Assignees
Labels
A-visibility Area: Visibility / privacy.

Comments

@bluss
Copy link
Member

bluss commented Mar 26, 2017

The private in public warning triggers even for impl blocks that have no public methods. See code below to reproduce.

#![crate_type="lib"]

trait PrivateTrait {
}

pub struct Foo<T>(T);

impl<T: PrivateTrait> Foo<T> {
    fn new() -> Self {
        panic!()
    }
}

warning:

rustc 1.17.0-nightly (49c67bd63 2017-03-24)
warning: private trait `PrivateTrait` in public interface (error E0445)
  --> <anon>:8:1
   |
8  |   impl<T: PrivateTrait> Foo<T> {
   |  _^ starting here...
9  | |     fn new() -> Self {
10 | |         panic!()
11 | |     }
12 | | }
   | |_^ ...ending here
   |
   = note: #[warn(private_in_public)] on by default
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>

cc @petrochenkov, you probably know if this is as designed or not

@petrochenkov
Copy link
Contributor

@bluss
impl Foo<T> is a public impl (because Foo is pub and T is... anything) so PrivateTrait can't be used in it's interface (see rust-lang/rfcs#1671 (comment) for the reason why).
So, this currently works as intended, but hopefully not for long - prohibiting private traits in bounds is the most unnecessary part of the private-in-public checker because rust-lang/rfcs#1671 (comment) has an alternative solution - rust-lang/rfcs#1671 (comment).
I hope to finish https://internals.rust-lang.org/t/lang-team-minutes-private-in-public-rules/4504/47 until the next weekend, and after that various private-in-public restrictions can be relaxed.

@petrochenkov petrochenkov added the A-visibility Area: Visibility / privacy. label Mar 26, 2017
@petrochenkov petrochenkov self-assigned this Mar 26, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 27, 2017
@petrochenkov
Copy link
Contributor

I'll close this since it works as expected with current rules.
See rust-lang/rfcs#2145 for the proposed solution.

@petrochenkov petrochenkov removed the C-bug Category: This is a bug. label Oct 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-visibility Area: Visibility / privacy.
Projects
None yet
Development

No branches or pull requests

3 participants