Fix private intra-doc warnings on associated items

The issue was that the `kind, id` override was previously only being
considered for the disambiguator check, not the privacy check. This uses
the same ID for both.
This commit is contained in:
Joshua Nelson 2021-02-11 19:15:16 -05:00
parent 178108bf81
commit 67fb96c537
4 changed files with 31 additions and 9 deletions

View File

@ -1151,11 +1151,12 @@ impl LinkCollector<'_, '_> {
}; };
let verify = |kind: DefKind, id: DefId| { 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@` // Disallow e.g. linking to enums with `struct@`
debug!("saw kind {:?} with disambiguator {:?}", kind, disambiguator); 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))) | (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 // NOTE: this allows 'method' to mean both normal functions and associated functions
// This can't cause ambiguity because both are in the same namespace. // This can't cause ambiguity because both are in the same namespace.
@ -1190,7 +1191,7 @@ impl LinkCollector<'_, '_> {
} }
} }
Some((kind, id)) Some(())
}; };
match res { match res {
@ -1241,7 +1242,7 @@ impl LinkCollector<'_, '_> {
Some(ItemLink { link: ori_link.link, link_text, did: None, fragment }) Some(ItemLink { link: ori_link.link, link_text, did: None, fragment })
} }
Res::Def(kind, id) => { 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)); 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 }) Some(ItemLink { link: ori_link.link, link_text, did: Some(id), fragment })
} }

View File

@ -1,11 +1,19 @@
warning: public documentation for `DocMe` links to private item `DontDocMe` warning: public documentation for `DocMe` links to private item `DontDocMe`
--> $DIR/private.rs:5:11 --> $DIR/private.rs:5:11
| |
LL | /// docs [DontDocMe] LL | /// docs [DontDocMe] [DontDocMe::f]
| ^^^^^^^^^ this item is private | ^^^^^^^^^ this item is private
| |
= note: `#[warn(private_intra_doc_links)]` on by default = note: `#[warn(private_intra_doc_links)]` on by default
= note: this link resolves only because you passed `--document-private-items`, but will break without = 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

View File

@ -1,11 +1,19 @@
warning: public documentation for `DocMe` links to private item `DontDocMe` warning: public documentation for `DocMe` links to private item `DontDocMe`
--> $DIR/private.rs:5:11 --> $DIR/private.rs:5:11
| |
LL | /// docs [DontDocMe] LL | /// docs [DontDocMe] [DontDocMe::f]
| ^^^^^^^^^ this item is private | ^^^^^^^^^ this item is private
| |
= note: `#[warn(private_intra_doc_links)]` on by default = note: `#[warn(private_intra_doc_links)]` on by default
= note: this link will resolve properly if you pass `--document-private-items` = 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

View File

@ -2,8 +2,13 @@
// revisions: public private // revisions: public private
// [private]compile-flags: --document-private-items // [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`
//~| WARNING public documentation for `DocMe` links to private item `DontDocMe::f`
// FIXME: for [private] we should also make sure the link was actually generated // FIXME: for [private] we should also make sure the link was actually generated
pub struct DocMe; pub struct DocMe;
struct DontDocMe; struct DontDocMe;
impl DontDocMe {
fn f() {}
}