Skip to content

Commit 6830ea1

Browse files
authored
Rollup merge of #82011 - jyn514:warn-private-assoc-item, r=max-heller
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. Fixes #81981. r? ``@max-heller``
2 parents 1a9d20b + 67fb96c commit 6830ea1

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1151,11 +1151,12 @@ impl LinkCollector<'_, '_> {
11511151
};
11521152

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

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

1193-
Some((kind, id))
1194+
Some(())
11941195
};
11951196

11961197
match res {
@@ -1241,7 +1242,7 @@ impl LinkCollector<'_, '_> {
12411242
Some(ItemLink { link: ori_link.link, link_text, did: None, fragment })
12421243
}
12431244
Res::Def(kind, id) => {
1244-
let (kind, id) = verify(kind, id)?;
1245+
verify(kind, id)?;
12451246
let id = clean::register_res(cx, rustc_hir::def::Res::Def(kind, id));
12461247
Some(ItemLink { link: ori_link.link, link_text, did: Some(id), fragment })
12471248
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
warning: public documentation for `DocMe` links to private item `DontDocMe`
22
--> $DIR/private.rs:5:11
33
|
4-
LL | /// docs [DontDocMe]
4+
LL | /// docs [DontDocMe] [DontDocMe::f]
55
| ^^^^^^^^^ this item is private
66
|
77
= note: `#[warn(private_intra_doc_links)]` on by default
88
= note: this link resolves only because you passed `--document-private-items`, but will break without
99

10-
warning: 1 warning emitted
10+
warning: public documentation for `DocMe` links to private item `DontDocMe::f`
11+
--> $DIR/private.rs:5:23
12+
|
13+
LL | /// docs [DontDocMe] [DontDocMe::f]
14+
| ^^^^^^^^^^^^ this item is private
15+
|
16+
= note: this link resolves only because you passed `--document-private-items`, but will break without
17+
18+
warning: 2 warnings emitted
1119

Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
warning: public documentation for `DocMe` links to private item `DontDocMe`
22
--> $DIR/private.rs:5:11
33
|
4-
LL | /// docs [DontDocMe]
4+
LL | /// docs [DontDocMe] [DontDocMe::f]
55
| ^^^^^^^^^ this item is private
66
|
77
= note: `#[warn(private_intra_doc_links)]` on by default
88
= note: this link will resolve properly if you pass `--document-private-items`
99

10-
warning: 1 warning emitted
10+
warning: public documentation for `DocMe` links to private item `DontDocMe::f`
11+
--> $DIR/private.rs:5:23
12+
|
13+
LL | /// docs [DontDocMe] [DontDocMe::f]
14+
| ^^^^^^^^^^^^ this item is private
15+
|
16+
= note: this link will resolve properly if you pass `--document-private-items`
17+
18+
warning: 2 warnings emitted
1119

src/test/rustdoc-ui/intra-doc/private.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22
// revisions: public private
33
// [private]compile-flags: --document-private-items
44

5-
/// docs [DontDocMe]
5+
/// docs [DontDocMe] [DontDocMe::f]
66
//~^ WARNING public documentation for `DocMe` links to private item `DontDocMe`
7+
//~| WARNING public documentation for `DocMe` links to private item `DontDocMe::f`
78
// FIXME: for [private] we should also make sure the link was actually generated
89
pub struct DocMe;
910
struct DontDocMe;
11+
12+
impl DontDocMe {
13+
fn f() {}
14+
}

0 commit comments

Comments
 (0)