mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 07:44:10 +00:00
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:
parent
178108bf81
commit
67fb96c537
@ -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.
|
||||
@ -1190,7 +1191,7 @@ impl LinkCollector<'_, '_> {
|
||||
}
|
||||
}
|
||||
|
||||
Some((kind, id))
|
||||
Some(())
|
||||
};
|
||||
|
||||
match res {
|
||||
@ -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 })
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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() {}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user