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

emit lints warnings on doc private if --document-private-items is used #76767

Closed

Conversation

GuillaumeGomez
Copy link
Member

r? @jyn514

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 15, 2020
@jyn514 jyn514 added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Sep 15, 2020
Comment on lines +76 to +77
) && (cx.renderinfo.borrow().access_levels.is_public(item.def_id)
|| cx.render_options.document_private)
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I see this used a lot in rustdoc code. Maybe it's worth adding a cx.appears_in_docs(def_id) function? Doesn't need to block this PR though.

Comment on lines +93 to +103
if cx.render_options.document_private
&& dox.is_empty()
&& !matches!(item.inner, clean::ImportItem(..))
{
let sp = span_of_attrs(&item.attrs).unwrap_or(item.source.span());
if !sp.is_dummy() {
cx.tcx.struct_span_lint_hir(rustc_lint::builtin::MISSING_DOCS, hir_id, sp, |lint| {
lint.build("missing documentation").emit()
});
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about this change.

  • missing_docs is a rustc pass, not a rustdoc pass. I don't like that both rustc and rustdoc will run the same pass but with different diagnostics.
  • clippy already lints for missing docs in private items (missing_docs_in_private_items). Do we really need to duplicate that here?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's an "outside" tool. Also, --document-private-items is a rustdoc option, meaning you can't check it in the rustc pass. This is more an extension than a pass in itself considering that it's on top.

Copy link
Member

Choose a reason for hiding this comment

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

Right, but my concern is that this doesn't belong in rustdoc. At least I'd want an FCP to be sure the rest of the team is agrees, if you feel strongly about it go ahead and start one.

Copy link
Member Author

@GuillaumeGomez GuillaumeGomez Sep 16, 2020

Choose a reason for hiding this comment

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

An FCP seems a bit big for this. Let's ping others, it might just be simpler. If we can't reach a consensus, it'll always be time to make an FCP. :)

What do you think about this @Manishearth, @ollie27 ?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I do not like that the pass is duplicated with different diagnostics.

Clippy is an outside tool as much as rustdoc is :)

Copy link
Member Author

@GuillaumeGomez GuillaumeGomez Sep 16, 2020

Choose a reason for hiding this comment

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

@Manishearth Wo, I didn't that about clippy, that's great! Also, I think you're misunderstanding something: it is not in place, it is an extension. The original lint check is still run (before this one in fact). So it's definitely not a duplication.

@ollie27: It doesn't change behavior, it's just that if you're documenting private items, it doesn't make sense to complain about the fact that they're private. And there is no way to know from rustc that --document-private-items has been passed to rustdoc (well, unless we add it to rustc directly obviously, but I'd rather not).

Copy link
Member

Choose a reason for hiding this comment

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

The original lint check is still run (before this one in fact). So it's definitely not a duplication

Right, but the diagnostics are different. The code for this should be in one place.

Such a lint already exists in clippy so the only possible next step would be to move that lint to rustc.

Totally happy to do this too. I'm not a huge fan of the lint changing behavior either.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have no issue putting this code in rustc directly, however it means that rustc will need to be aware of the --document-private-items rustdoc setting.

Copy link
Member

Choose a reason for hiding this comment

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

No, i'm saying that we can make rustc aware of that setting, by making it an internal flag that can be swapped by consumers of the rustc API (like rustdoc)

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure we should make rustc aware of it. I'd expect this to be a separate pass: --document-private should only affect whether the docs are rendered, not whether they're processed at all. Strip makes me uncomfortable for that reason, I'd prefer rustdoc linted consistently.

@jyn514 jyn514 mentioned this pull request Sep 16, 2020
@jyn514 jyn514 added the I-needs-decision Issue: In need of a decision. label Sep 17, 2020
@crlf0710 crlf0710 added the S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). label Oct 8, 2020
@bors
Copy link
Collaborator

bors commented Oct 13, 2020

☔ The latest upstream changes (presumably #76196) made this pull request unmergeable. Please resolve the merge conflicts.

Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:

@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author

@camelid camelid added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 30, 2020
@jyn514
Copy link
Member

jyn514 commented Nov 1, 2020

I'm going to close this; I think the best way forward if you want to lint private items is to uplift the clippy lint, so that the warnings are strongly delimited and rustdoc doesn't behave differently from rustc.

@jyn514 jyn514 closed this Nov 1, 2020
@GuillaumeGomez GuillaumeGomez deleted the lints-doc-private branch November 1, 2020 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. I-needs-decision Issue: In need of a decision. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants