mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 23:12:02 +00:00
Separate private_intra_doc_links
and broken_intra_doc_links
into separate lints
This is not ideal because it means `deny(broken_intra_doc_links)` will no longer `deny(private_intra_doc_links)`. However, it can't be fixed with a new lint group, because `broken` is already in the `rustdoc` lint group; there would need to be a way to nest groups somehow. This also removes the early `return` so that the link will be generated even though it gives a warning.
This commit is contained in:
parent
b8363295d5
commit
03d8be0896
@ -305,6 +305,7 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
|
||||
add_lint_group!(
|
||||
"rustdoc",
|
||||
BROKEN_INTRA_DOC_LINKS,
|
||||
PRIVATE_INTRA_DOC_LINKS,
|
||||
INVALID_CODEBLOCK_ATTRIBUTES,
|
||||
MISSING_DOC_CODE_EXAMPLES,
|
||||
PRIVATE_DOC_TESTS
|
||||
|
@ -1826,6 +1826,17 @@ declare_lint! {
|
||||
"failures in resolving intra-doc link targets"
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
/// This is a subset of `broken_intra_doc_links` that warns when linking from
|
||||
/// a public item to a private one. This is a `rustdoc` only lint, see the
|
||||
/// documentation in the [rustdoc book].
|
||||
///
|
||||
/// [rustdoc book]: ../../../rustdoc/lints.html#broken_intra_doc_links
|
||||
pub PRIVATE_INTRA_DOC_LINKS,
|
||||
Warn,
|
||||
"linking from a public item to a private one"
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
/// The `invalid_codeblock_attributes` lint detects code block attributes
|
||||
/// in documentation examples that have potentially mis-typed values. This
|
||||
|
@ -11,7 +11,10 @@ use rustc_hir::def::{
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_middle::ty;
|
||||
use rustc_resolve::ParentScope;
|
||||
use rustc_session::lint;
|
||||
use rustc_session::lint::{
|
||||
builtin::{BROKEN_INTRA_DOC_LINKS, PRIVATE_INTRA_DOC_LINKS},
|
||||
Lint,
|
||||
};
|
||||
use rustc_span::hygiene::MacroKind;
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_span::symbol::Symbol;
|
||||
@ -988,7 +991,7 @@ impl LinkCollector<'_, '_> {
|
||||
let report_mismatch = |specified: Disambiguator, resolved: Disambiguator| {
|
||||
// The resolved item did not match the disambiguator; give a better error than 'not found'
|
||||
let msg = format!("incompatible link kind for `{}`", path_str);
|
||||
report_diagnostic(cx, &msg, &item, dox, &link_range, |diag, sp| {
|
||||
let callback = |diag: &mut DiagnosticBuilder<'_>, sp| {
|
||||
let note = format!(
|
||||
"this link resolved to {} {}, which is not {} {}",
|
||||
resolved.article(),
|
||||
@ -998,7 +1001,8 @@ impl LinkCollector<'_, '_> {
|
||||
);
|
||||
diag.note(¬e);
|
||||
suggest_disambiguator(resolved, diag, path_str, dox, sp, &link_range);
|
||||
});
|
||||
};
|
||||
report_diagnostic(cx, BROKEN_INTRA_DOC_LINKS, &msg, &item, dox, &link_range, callback);
|
||||
};
|
||||
if let Res::PrimTy(..) = res {
|
||||
match disambiguator {
|
||||
@ -1055,7 +1059,6 @@ impl LinkCollector<'_, '_> {
|
||||
&& !self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_dst)
|
||||
{
|
||||
privacy_error(cx, &item, &path_str, dox, link_range);
|
||||
return;
|
||||
}
|
||||
}
|
||||
let id = register_res(cx, res);
|
||||
@ -1417,6 +1420,7 @@ impl Suggestion {
|
||||
/// to it.
|
||||
fn report_diagnostic(
|
||||
cx: &DocContext<'_>,
|
||||
lint: &'static Lint,
|
||||
msg: &str,
|
||||
item: &Item,
|
||||
dox: &str,
|
||||
@ -1435,7 +1439,7 @@ fn report_diagnostic(
|
||||
let attrs = &item.attrs;
|
||||
let sp = span_of_attrs(attrs).unwrap_or(item.source.span());
|
||||
|
||||
cx.tcx.struct_span_lint_hir(lint::builtin::BROKEN_INTRA_DOC_LINKS, hir_id, sp, |lint| {
|
||||
cx.tcx.struct_span_lint_hir(lint, hir_id, sp, |lint| {
|
||||
let mut diag = lint.build(msg);
|
||||
|
||||
let span = link_range
|
||||
@ -1482,6 +1486,7 @@ fn resolution_failure(
|
||||
) {
|
||||
report_diagnostic(
|
||||
collector.cx,
|
||||
BROKEN_INTRA_DOC_LINKS,
|
||||
&format!("unresolved link to `{}`", path_str),
|
||||
item,
|
||||
dox,
|
||||
@ -1695,7 +1700,7 @@ fn anchor_failure(
|
||||
),
|
||||
};
|
||||
|
||||
report_diagnostic(cx, &msg, item, dox, &link_range, |diag, sp| {
|
||||
report_diagnostic(cx, BROKEN_INTRA_DOC_LINKS, &msg, item, dox, &link_range, |diag, sp| {
|
||||
if let Some(sp) = sp {
|
||||
diag.span_label(sp, "contains invalid anchor");
|
||||
}
|
||||
@ -1734,7 +1739,7 @@ fn ambiguity_error(
|
||||
}
|
||||
}
|
||||
|
||||
report_diagnostic(cx, &msg, item, dox, &link_range, |diag, sp| {
|
||||
report_diagnostic(cx, BROKEN_INTRA_DOC_LINKS, &msg, item, dox, &link_range, |diag, sp| {
|
||||
if let Some(sp) = sp {
|
||||
diag.span_label(sp, "ambiguous link");
|
||||
} else {
|
||||
@ -1784,7 +1789,7 @@ fn privacy_error(
|
||||
let msg =
|
||||
format!("public documentation for `{}` links to private item `{}`", item_name, path_str);
|
||||
|
||||
report_diagnostic(cx, &msg, item, dox, &link_range, |diag, sp| {
|
||||
report_diagnostic(cx, PRIVATE_INTRA_DOC_LINKS, &msg, item, dox, &link_range, |diag, sp| {
|
||||
if let Some(sp) = sp {
|
||||
diag.span_label(sp, "this item is private");
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ warning: public documentation for `DocMe` links to private item `DontDocMe`
|
||||
LL | /// docs [DontDocMe]
|
||||
| ^^^^^^^^^ this item is private
|
||||
|
|
||||
= note: `#[warn(broken_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
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
@ -4,7 +4,7 @@ warning: public documentation for `DocMe` links to private item `DontDocMe`
|
||||
LL | /// docs [DontDocMe]
|
||||
| ^^^^^^^^^ this item is private
|
||||
|
|
||||
= note: `#[warn(broken_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`
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
@ -4,7 +4,7 @@ warning: public documentation for `public_item` links to private item `PrivateTy
|
||||
LL | /// [`PrivateType`]
|
||||
| ^^^^^^^^^^^^^ this item is private
|
||||
|
|
||||
= note: `#[warn(broken_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
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
@ -4,7 +4,7 @@ warning: public documentation for `public_item` links to private item `PrivateTy
|
||||
LL | /// [`PrivateType`]
|
||||
| ^^^^^^^^^^^^^ this item is private
|
||||
|
|
||||
= note: `#[warn(broken_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`
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
6
src/test/rustdoc/intra-doc-link-private.rs
Normal file
6
src/test/rustdoc/intra-doc-link-private.rs
Normal file
@ -0,0 +1,6 @@
|
||||
#![crate_name = "private"]
|
||||
// compile-flags: --document-private-items
|
||||
/// docs [DontDocMe]
|
||||
// @has private/struct.DocMe.html '//*a[@href="../private/struct.DontDocMe.html"]' 'DontDocMe'
|
||||
pub struct DocMe;
|
||||
struct DontDocMe;
|
Loading…
Reference in New Issue
Block a user