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

regression: Rustdoc shows pub(self) as pub(in a::b) #79139

Closed
jyn514 opened this issue Nov 17, 2020 · 9 comments · Fixed by #80368
Closed

regression: Rustdoc shows pub(self) as pub(in a::b) #79139

jyn514 opened this issue Nov 17, 2020 · 9 comments · Fixed by #80368
Assignees
Labels
A-visibility Area: Visibility / privacy C-bug Category: This is a bug. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. P-medium Medium priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@jyn514
Copy link
Member

jyn514 commented Nov 17, 2020

This is a pre-emptive bug report for when #77820 lands.

mod a {
  mod b {
        pub(self) struct FooInSelfSuperB;
  }
}

I expected to see this happen: Rustdoc displays the privacy as written: pub(self) struct FooInSelfSuperB;

Instead, this happened: Rustdoc displays an absolute path: pub(in a::b) struct FooInSelfSuperB;

A similar bug exists for pub(super). The regressions for other paths (pub(super::super) -> pub(crate), pub(in crate::a::b) -> pub(in a::b), etc.) are explicitly not in scope and I don't plan to fix them.

Note that this always requires using --document-private-items.

Implementation Notes

This is not trivial to fix because html::render does not have access to a TyCtxt and impl Clean for ty::Visibility does not have access to the original DefId of the item being documented. impl Clean need to be turned into a free function, and #77820 (comment) needs to be debugged. See jyn514@b997e4f for partial progress on that; feel free to take over that branch if you're interested in fixing this.

Meta

This version of rustdoc has not yet landed; see #77820.

@jyn514 jyn514 added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-visibility Area: Visibility / privacy regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. C-bug Category: This is a bug. labels Nov 17, 2020
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Nov 17, 2020
@camelid camelid added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Nov 17, 2020
@camelid
Copy link
Member

camelid commented Nov 17, 2020

Assigning P-medium and removing I-prioritize as discussed in the prioritization working group.

@camelid
Copy link
Member

camelid commented Nov 17, 2020

Is there any we can just access the original source code using a span? I guess the downside of that is there might be weird formatting, though we could just strip whitespace. Not sure if that's considered too hacky though.

@jyn514
Copy link
Member Author

jyn514 commented Nov 17, 2020

I would prefer not to do this by mangling the source code itself, rustdoc should not be parsing source code twice. The way to get the original behavior back is to get the visibility from the HIR instead of from metadata, but that means both a slowdown (because it will no longer be a query) and more code overall because all code will be penalized for the rare case of restricted visibility.

@jyn514 jyn514 added the E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. label Nov 17, 2020
@jyn514 jyn514 added the E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. label Nov 29, 2020
@camelid
Copy link
Member

camelid commented Dec 17, 2020

Note from #80101: Another way this issue manifests is that private functions are shown as pub(in foo) where foo is the module they're defined in.

@jyn514
Copy link
Member Author

jyn514 commented Dec 23, 2020

This is not trivial to fix because html::render does not have access to a TyCtxt

Since #80090 this can be done in render directly.

@camelid camelid self-assigned this Dec 23, 2020
@camelid
Copy link
Member

camelid commented Dec 24, 2020

@jyn514 I feel a bit confused: it seems that there are two impl Cleans, one for hir::Visibility and ty::Visibility. What's the difference between those, and which one needs to be changed or do both? It seems like the impl for hir::Visibility is used in 5 places, while the impl for ty::Visibility is used in 2 (I got this information by removing one and then running ./x.py check and then the same for the other).

@camelid
Copy link
Member

camelid commented Dec 24, 2020

Actually it seems like the part that needs to be changed is clean::Visibility::print_with_space? Or should I be adding more variants to clean::Visibility for pub(self), pub(super), etc.? Probably adding more variants would make the code worse, so I'm guessing I shouldn't do that.

@jyn514
Copy link
Member Author

jyn514 commented Dec 24, 2020

@camelid yes, I think the changing print_with_space is the best approach now that there's a TyCtxt in render; that's the main reason I didn't fix this before. Basically change this match to check for more cases:

clean::Visibility::Restricted(did) if did.index == CRATE_DEF_INDEX => {
write!(f, "pub(crate) ")
}

The reason there's two different Clean impls is because both are necessary; see #77820 (comment). If you can add more comments in the code itself that would be great :)

@camelid camelid added regression-from-stable-to-beta Performance or correctness regression from stable to beta. and removed regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. labels Dec 31, 2020
@camelid
Copy link
Member

camelid commented Dec 31, 2020

This regression is now on beta. Nominated the PR for beta backport.

@bors bors closed this as completed in 7d247c9 Jan 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-visibility Area: Visibility / privacy C-bug Category: This is a bug. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. P-medium Medium priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants