-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
privacy: Substitute type aliases in private-in-public checker #34193
Conversation
@@ -246,6 +245,8 @@ mod aliases_priv { | |||
use self::Priv1 as PrivUseAlias; | |||
use self::PrivTr1 as PrivUseAliasTr; | |||
type PrivAlias = Priv2; | |||
//~^ WARN private type in public interface | |||
//~| WARNING hard error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm having trouble seeing why this is an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Priv2
is used in a public interface through an alias.
The error location here is suboptimal. On one hand Priv2
is the true source of the error and pointing to PrivAlias
is misleading, on the other hand pointing to Priv2
is confusing too, because the public interface it's used in is not pointed to.
Ideally, there should be two diagnostic messages - one for the public interface location and the other for actual private type location. I'll implement this if positive decision about the whole PR is made.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused a bit. This seems like it's causing a new error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like it's causing a new error?
No, the error from line 211 (alias location) migrated to this line (aliased type location).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, there should be two diagnostic messages - one for the public interface location and the other for actual private type location.
I implemented the extra note for the private type location for type aliases, but dropped it, the situation should be rare, likely happens in advanced code and doesn't worth the extra code.
Now the error is reported at the public interface location only.
@@ -105,8 +105,6 @@ mod aliases_pub { | |||
} | |||
impl PrivTr for Priv {} | |||
|
|||
// This should be OK, if type aliases are substituted | |||
pub fn f2(arg: PrivAlias) {} //~ ERROR private type in public interface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a test to show that no error results?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's tested, the check is just moved from this file to private-in-public-warn.rs
Ideally, we would fix rustdoc to not use private type aliases as part of this PR. |
I'll try to fix this and the error locations tomorrow. If I won't be able to, it'll have to wait for another week or so. (I also don't think these are blockers for merging the PR) |
Curiously,
|
@petrochenkov I guess it's debatable what's the right thing to do there. I mean, the link still goes to the right place, I guess, and it's not clear that showing the full path will help readability overall. (And the full path in that crate may not be the same as the full path from another crate.) In any case, it feels different, because |
Updated with rustdoc changes and tweaked error locations. |
☔ The latest upstream changes (presumably #34570) made this pull request unmergeable. Please resolve the merge conflicts. |
Rebased. |
@@ -1644,8 +1683,46 @@ impl Clean<Type> for hir::Ty { | |||
FixedVector(box ty.clean(cx), n) | |||
}, | |||
TyTup(ref tys) => Tuple(tys.clean(cx)), | |||
TyPath(None, ref p) => { | |||
resolve_type(cx, p.clean(cx), self.id) | |||
TyPath(None, ref path) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will this logic work if you have a private type alias that refers to another private type alias?
e.g., type A = u32; type B = A; fn foo(x: B) { }
?
(Can you also add some tests for that scenario? I could imagine that even if your patch gets it right, it's something future patches might easily break.)
r=me once new tests are added for recursive scenario |
91063fc
to
5d4ae4b
Compare
Updated with a test for recursive substitution. |
@bors r+ |
📌 Commit 5d4ae4b has been approved by |
⌛ Testing commit 5d4ae4b with merge 11f8805... |
privacy: Substitute type aliases in private-in-public checker Closes #30503 Closes #34293 Everyone in the issue discussion seemed to be in favor, @huonw also spoke about this [here](https://www.reddit.com/r/rust/comments/3xldr9/surfaces_and_signatures_component_privacy_versus/cy615wq), but the issue haven't got any movement. I think it's reasonable to do this before turning `private_in_public` warnings into errors. r? @nikomatsakis
Closes #30503
Closes #34293
Everyone in the issue discussion seemed to be in favor, @huonw also spoke about this here, but the issue haven't got any movement.
I think it's reasonable to do this before turning
private_in_public
warnings into errors.r? @nikomatsakis