Skip to content

Commit c14641a

Browse files
rustdoc: Add explanation when linting against public to private item links
The additional note helps explaining why the lint was triggered and that --document-private-items directly influences the link resolution.
1 parent ed53de0 commit c14641a

5 files changed

+11
-0
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,13 @@ fn privacy_error(
10761076
if let Some(sp) = sp {
10771077
diag.span_label(sp, "this item is private");
10781078
}
1079+
1080+
let note_msg = if cx.render_options.document_private {
1081+
"this link resolves only because you passed `--document-private-items`, but will break without"
1082+
} else {
1083+
"this link will resolve properly if you pass `--document-private-items`"
1084+
};
1085+
diag.note(note_msg);
10791086
});
10801087
}
10811088

src/test/rustdoc-ui/intra-links-private.private.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | /// docs [DontDocMe]
55
| ^^^^^^^^^ this item is private
66
|
77
= note: `#[warn(intra_doc_link_resolution_failure)]` on by default
8+
= note: this link resolves only because you passed `--document-private-items`, but will break without
89

910
warning: 1 warning emitted
1011

src/test/rustdoc-ui/intra-links-private.public.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | /// docs [DontDocMe]
55
| ^^^^^^^^^ this item is private
66
|
77
= note: `#[warn(intra_doc_link_resolution_failure)]` on by default
8+
= note: this link will resolve properly if you pass `--document-private-items`
89

910
warning: 1 warning emitted
1011

src/test/rustdoc-ui/issue-74134.private.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | /// [`PrivateType`]
55
| ^^^^^^^^^^^^^ this item is private
66
|
77
= note: `#[warn(intra_doc_link_resolution_failure)]` on by default
8+
= note: this link resolves only because you passed `--document-private-items`, but will break without
89

910
warning: 1 warning emitted
1011

src/test/rustdoc-ui/issue-74134.public.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | /// [`PrivateType`]
55
| ^^^^^^^^^^^^^ this item is private
66
|
77
= note: `#[warn(intra_doc_link_resolution_failure)]` on by default
8+
= note: this link will resolve properly if you pass `--document-private-items`
89

910
warning: 1 warning emitted
1011

0 commit comments

Comments
 (0)