Skip to content

make missing_doc respect the visibility rules #10277

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

Merged
merged 1 commit into from
Nov 13, 2013

Conversation

dcrewi
Copy link
Contributor

@dcrewi dcrewi commented Nov 5, 2013

Now the privacy pass returns enough information that other passes do not need to duplicate the visibility rules, and the missing_doc implementation is more consistent with other lint checks.

@alexcrichton
Copy link
Member

This pass is becoming complex enough that it should no longer be using ad-hoc rules for determining whether an item is private or public. This pass was originally implemented before there was a comprehensive privacy analysis pass (explaining why it duplicates the logic of privacy).

With that in mind, the code should get restructured to using a combination of the exported_items set from the privacy set along with the reexport_map2 from the resolve pass. The exported_items set contains all directly exported node ids in the AST, or otherwise all those which are "public all the way". The reexport_map2 is keyed by module id, and it should be used to traverse the public reexports of publicly visible modules.

I think that the privacy pass may want to output a more usable form of information which is the set of all publicly reachable items (you currently must recompute that based off the two maps above), but that may be a separate issue as well.

Regardless, seeing how this pass is getting more complicated, it's time to start using the real analysis pass of the compiler. Additionally, I believe that once the results of privacy are being used that the MissingDocVisitor can be removed entirely so we can have one and only one lint visitor.

@dcrewi
Copy link
Contributor Author

dcrewi commented Nov 5, 2013

I think you're saying that the privacy pass should be changed so that exported_items includes re-exported items. The reachability pass then doesn't even have to bother with exp_map2 and I can't find any other code in the compiler that uses exported_items. So that means the change shouldn't break anything.

After that is done, the missing_doc check can be done in the same visitor pass as the other checks and lint.rs gets cleaned up.

@alexcrichton
Copy link
Member

The exported_items set should not include re-exported items as-is. The set is used as an initial succeed-fast when doing privacy checking, and it's invalid to import a publicly exported item which would otherwise be private. There would have to be a separate set generated for specifically this purpose by the privacy pass (which isn't used internally by the privacy pass).

Otherwise yes, that's sounds like the way to go!

@dcrewi
Copy link
Contributor Author

dcrewi commented Nov 10, 2013

This was a lot more complicated than I expected it to be, but I think it's ready for review now.

@@ -491,7 +507,7 @@ pub fn each_lint(sess: session::Session,
true
}

fn check_while_true_expr(cx: &Context, e: &ast::Expr) {
fn check_while_true_expr<'a>(cx: &Context<'a>, e: &ast::Expr) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the Context is an argument, you shouldn't need an explicit lifetime parameter. It's inferred to be a "dummy parameter".

@alexcrichton
Copy link
Member

I'll take a closer look at this today or tomorrow, thanks for updating!

@dcrewi
Copy link
Contributor Author

dcrewi commented Nov 10, 2013

The force-push removed lifetime parameters and made one other small tweak.

@alexcrichton
Copy link
Member

Nice work on this! Also thanks for doing this, I really like where this is going. I've laid out comments here and there about things which I think need to get restructured, but feel free to ping me once updated!

@dcrewi
Copy link
Contributor Author

dcrewi commented Nov 13, 2013

Revised as per feedback.

@alexcrichton
Copy link
Member

Nice job! As one final thing, would you mind rebasing your commits into just one?

Previously, the `exported_items` set created by the privacy pass was
incomplete. Specifically, it did not include items that had been defined
at a private path but then `pub use`d at a public path. This commit
finds all crate exports during the privacy pass. Consequently, some code
in the reachable pass and in rustdoc is no longer necessary. This commit
then removes the separate `MissingDocLintVisitor` lint pass, opting to
check missing_doc lint in the same pass as the other lint checkers using
the visibility result computed by the privacy pass.

Fixes rust-lang#9777.
@dcrewi
Copy link
Contributor Author

dcrewi commented Nov 13, 2013

Commits squashed into one. I figured it was easier to review logically distinct changes.

@alexcrichton
Copy link
Member

It was, and thanks for that! After reviewing though, it seems like a good one-chunk change though to rebase into one (although it doesn't really matter that much)

bors added a commit that referenced this pull request Nov 13, 2013
…r=alexcrichton

Now the privacy pass returns enough information that other passes do not need to duplicate the visibility rules, and the missing_doc implementation is more consistent with other lint checks.
@bors bors merged commit 1f7eb4f into rust-lang:master Nov 13, 2013
@dcrewi dcrewi deleted the missing-doc-and-visibility-rules branch November 14, 2013 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants