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

Fix private intra-doc warnings on associated items #82011

Merged
merged 1 commit into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,11 +1151,12 @@ impl LinkCollector<'_, '_> {
};

let verify = |kind: DefKind, id: DefId| {
debug!("intra-doc link to {} resolved to {:?}", path_str, res);
let (kind, id) = self.kind_side_channel.take().unwrap_or((kind, id));
debug!("intra-doc link to {} resolved to {:?} (id: {:?})", path_str, res, id);

// Disallow e.g. linking to enums with `struct@`
debug!("saw kind {:?} with disambiguator {:?}", kind, disambiguator);
match (self.kind_side_channel.take().map(|(kind, _)| kind).unwrap_or(kind), disambiguator) {
match (kind, disambiguator) {
| (DefKind::Const | DefKind::ConstParam | DefKind::AssocConst | DefKind::AnonConst, Some(Disambiguator::Kind(DefKind::Const)))
// NOTE: this allows 'method' to mean both normal functions and associated functions
// This can't cause ambiguity because both are in the same namespace.
Expand Down Expand Up @@ -1190,7 +1191,7 @@ impl LinkCollector<'_, '_> {
}
}

Some((kind, id))
Some(())
};

match res {
Expand Down Expand Up @@ -1241,7 +1242,7 @@ impl LinkCollector<'_, '_> {
Some(ItemLink { link: ori_link.link, link_text, did: None, fragment })
}
Res::Def(kind, id) => {
let (kind, id) = verify(kind, id)?;
verify(kind, id)?;
let id = clean::register_res(cx, rustc_hir::def::Res::Def(kind, id));
Some(ItemLink { link: ori_link.link, link_text, did: Some(id), fragment })
}
Expand Down
12 changes: 10 additions & 2 deletions src/test/rustdoc-ui/intra-doc/private.private.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
warning: public documentation for `DocMe` links to private item `DontDocMe`
--> $DIR/private.rs:5:11
|
LL | /// docs [DontDocMe]
LL | /// docs [DontDocMe] [DontDocMe::f]
| ^^^^^^^^^ this item is private
|
= note: `#[warn(private_intra_doc_links)]` on by default
= note: this link resolves only because you passed `--document-private-items`, but will break without

warning: 1 warning emitted
warning: public documentation for `DocMe` links to private item `DontDocMe::f`
--> $DIR/private.rs:5:23
|
LL | /// docs [DontDocMe] [DontDocMe::f]
| ^^^^^^^^^^^^ this item is private
|
= note: this link resolves only because you passed `--document-private-items`, but will break without

warning: 2 warnings emitted

12 changes: 10 additions & 2 deletions src/test/rustdoc-ui/intra-doc/private.public.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
warning: public documentation for `DocMe` links to private item `DontDocMe`
--> $DIR/private.rs:5:11
|
LL | /// docs [DontDocMe]
LL | /// docs [DontDocMe] [DontDocMe::f]
| ^^^^^^^^^ this item is private
|
= note: `#[warn(private_intra_doc_links)]` on by default
= note: this link will resolve properly if you pass `--document-private-items`

warning: 1 warning emitted
warning: public documentation for `DocMe` links to private item `DontDocMe::f`
--> $DIR/private.rs:5:23
|
LL | /// docs [DontDocMe] [DontDocMe::f]
| ^^^^^^^^^^^^ this item is private
|
= note: this link will resolve properly if you pass `--document-private-items`

warning: 2 warnings emitted

7 changes: 6 additions & 1 deletion src/test/rustdoc-ui/intra-doc/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
// revisions: public private
// [private]compile-flags: --document-private-items

/// docs [DontDocMe]
/// docs [DontDocMe] [DontDocMe::f]
//~^ WARNING public documentation for `DocMe` links to private item `DontDocMe`
//~| WARNING public documentation for `DocMe` links to private item `DontDocMe::f`
// FIXME: for [private] we should also make sure the link was actually generated
pub struct DocMe;
struct DontDocMe;

impl DontDocMe {
fn f() {}
}