Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upPrivate trait's methods reachable through a public subtrait #28514
Comments
This comment has been minimized.
This comment has been minimized.
|
cc @alexcrichton, because you've weighed in on other privacy issues |
This comment has been minimized.
This comment has been minimized.
|
I would personally expect a privacy error to be generated. I'm also a little surprised about how resolution allows using a method without importing the trait as well, but that may perhaps be intended behavior. cc @rust-lang/lang, @nrc triage: I-nominated |
rust-highfive
added
the
I-nominated
label
Sep 19, 2015
alexcrichton
added
the
T-lang
label
Sep 19, 2015
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
I think the error here is that |
This comment has been minimized.
This comment has been minimized.
|
public or accessible from all the places |
This comment has been minimized.
This comment has been minimized.
|
I'd be fine so long as it was limited to "marked |
This comment has been minimized.
This comment has been minimized.
|
I am somewhat surprised, but this test case passes too. The difference here is that the type mod inner {
struct I32;
trait A {
fn a(&self) { }
}
pub trait B {
fn b(&self) { }
}
pub trait C: A + B {
fn c(&self) { }
}
impl A for I32 {}
impl B for I32 {}
impl C for I32 {} // <-- I expected an error here and on the impl of B
}
fn main() {
} |
This comment has been minimized.
This comment has been minimized.
|
(I'm inclined to think that the invocation |
This comment has been minimized.
This comment has been minimized.
|
(namely, if one changes @nikomatsakis example so that it says |
This comment has been minimized.
This comment has been minimized.
|
The heart of this question is what a private trait means. After some discussion in the language team, we came to the following conclusions:
There is definitely concern that people are going to be relying on this kind of setup, though also concern that they may not be getting the guarantees that they think they are. |
This comment has been minimized.
This comment has been minimized.
|
triage: P-high |
rust-highfive
added
P-high
and removed
I-nominated
labels
Oct 1, 2015
nikomatsakis
assigned
nrc
Oct 1, 2015
aturon
assigned
aturon
and unassigned
nrc
Oct 8, 2015
bluss
referenced this issue
Oct 23, 2015
Merged
Remove unnecessary trait accessibility check. #28504
This comment has been minimized.
This comment has been minimized.
|
This variation shows how using a trait bound with fn use_c<T: C>(x: &T) {
// A is private
// B is pub, not reexported
// C : A + B is pub, reexported
x.a(); // can call
x.b(); // can call
x.c(); // ok
C::a(x); // can call
C::b(x); // can call
C::c(x); // ok
}
|
This comment has been minimized.
This comment has been minimized.
|
The last comment shows a regression in nightly. |
nikomatsakis
added
the
regression-from-stable-to-nightly
label
Oct 23, 2015
This comment has been minimized.
This comment has been minimized.
|
Unfortunately, the current assignee (@aturon) is out for a while, so someone else will have to look into this. |
arielb1
changed the title
Private trait's methods reachable through UFCS
Private trait's methods reachable through a public supertrait
Oct 23, 2015
aturon
referenced this issue
Nov 5, 2015
Closed
Type alias can be used to bypass privacy check #28450
This comment has been minimized.
This comment has been minimized.
|
Is this on beta/stable yet? |
This comment has been minimized.
This comment has been minimized.
|
The regression mentioned in this comment seems to be fixed in nightly (and never reached beta). I think it was fixed in #29325 |
bluss
removed
the
regression-from-stable-to-nightly
label
Nov 18, 2015
This comment has been minimized.
This comment has been minimized.
|
@petrochenkov Are you interested in taking this on? |
This comment has been minimized.
This comment has been minimized.
|
@aturon |
This comment has been minimized.
This comment has been minimized.
brson
added
the
P-medium
label
Jul 14, 2016
This comment has been minimized.
This comment has been minimized.
|
Triage: Moving this to P-medium since nobody is working on it. cc @rust-lang/lang @petrochenkov |
This comment has been minimized.
This comment has been minimized.
|
also ping @jseyfried, if this is no longer an issue, could you provide a summary as to why as well? It'd be great to close out! |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton I believe this issue can only happen if a public trait has a private parent, which is already a |
alexcrichton
removed
the
P-high
label
Jul 14, 2016
This comment has been minimized.
This comment has been minimized.
|
Awesome! I @rust-lang/lang, thoughts about closing? (also applying a nomination for bringing it up) |
alexcrichton
added
the
I-nominated
label
Jul 14, 2016
petrochenkov
referenced this issue
Jul 14, 2016
Open
Tracking issue for `private_in_public` compatibility lint. #34537
This comment has been minimized.
This comment has been minimized.
petrochenkov
added a commit
to petrochenkov/rust
that referenced
this issue
Jul 14, 2016
aturon
added
E-needstest
and removed
I-nominated
P-medium
labels
Jul 14, 2016
This comment has been minimized.
This comment has been minimized.
|
Switching to needstest! |
bors
closed this
in
b052dd6
Aug 14, 2016
This comment has been minimized.
This comment has been minimized.
|
Reopening this since |
petrochenkov
reopened this
Apr 11, 2017
petrochenkov
added
A-visibility
and removed
E-needstest
labels
Apr 11, 2017
This comment has been minimized.
This comment has been minimized.
|
Visibility of a trait item is inherited from its trait, so the fix is to check this trait visibility every time a trait item is named. C::a(x); // ERROR, trait A is private / not accessible from here |
This comment has been minimized.
This comment has been minimized.
C::b(&0);is an orthogonal problem. C::b(&0); // ERROR no method b in the current scopeEDIT: This interpretation incorrect, I didn't realize this is about |
bluss commentedSep 19, 2015
I'm not 100% sure how the privacy rules should work.
A's methods should not be callable because the trait is private, but it's reachable though the trait C that inherits A, by calling
C::a().B's methods are reachable the same way, even if it's marked pub but not publically reachable.
Playpen