Rollup merge of #80527 - jyn514:rustdoc-lints, r=GuillaumeGomez
Make rustdoc lints a tool lint instead of built-in - Rename `broken_intra_doc_links` to `rustdoc::broken_intra_doc_links` (and similar for other rustdoc lints; I don't expect any others to be used frequently, though). - Ensure that the old lint names still work and give deprecation errors - Register lints even when running doctests - Move lint machinery into a separate file - Add `declare_rustdoc_lint!` macro Unblocks https://github.com/rust-lang/rust/pull/80300, https://github.com/rust-lang/rust/pull/79816, https://github.com/rust-lang/rust/pull/80965. Makes the strangeness in https://github.com/rust-lang/rust/pull/77364 more apparent to the end user (note that `missing_docs` is *not* moved to rustdoc in this PR). Closes https://github.com/rust-lang/rust/issues/78786. ## Current status This is blocked on #82620 (see https://github.com/rust-lang/rust/pull/80527#issuecomment-787401519)
This commit is contained in:
commit
f898aa3f5b
86 changed files with 495 additions and 339 deletions
|
@ -34,7 +34,7 @@ impl MarkedAttrs {
|
|||
}
|
||||
|
||||
pub fn is_known_lint_tool(m_item: Ident) -> bool {
|
||||
[sym::clippy, sym::rustc].contains(&m_item.name)
|
||||
[sym::clippy, sym::rustc, sym::rustdoc].contains(&m_item.name)
|
||||
}
|
||||
|
||||
impl NestedMetaItem {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#![deny(invalid_codeblock_attributes)]
|
||||
#![cfg_attr(bootstrap, deny(invalid_codeblock_attributes))]
|
||||
#![cfg_attr(not(bootstrap), deny(rustdoc::invalid_codeblock_attributes))]
|
||||
//! This library is used to gather all error codes into one place,
|
||||
//! the goal being to make their maintenance easier.
|
||||
|
||||
|
|
|
@ -89,6 +89,7 @@ impl SessionLintStore for LintStore {
|
|||
}
|
||||
|
||||
/// The target of the `by_name` map, which accounts for renaming/deprecation.
|
||||
#[derive(Debug)]
|
||||
enum TargetLint {
|
||||
/// A direct lint target
|
||||
Id(LintId),
|
||||
|
@ -470,7 +471,10 @@ impl LintStore {
|
|||
Some(&Id(ref id)) => {
|
||||
CheckLintNameResult::Tool(Err((Some(slice::from_ref(id)), complete_name)))
|
||||
}
|
||||
_ => CheckLintNameResult::NoLint(None),
|
||||
Some(other) => {
|
||||
tracing::debug!("got renamed lint {:?}", other);
|
||||
CheckLintNameResult::NoLint(None)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,9 +69,7 @@ use rustc_hir::def_id::LocalDefId;
|
|||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_session::lint::builtin::{
|
||||
BARE_TRAIT_OBJECTS, BROKEN_INTRA_DOC_LINKS, ELIDED_LIFETIMES_IN_PATHS,
|
||||
EXPLICIT_OUTLIVES_REQUIREMENTS, INVALID_CODEBLOCK_ATTRIBUTES, INVALID_HTML_TAGS,
|
||||
MISSING_DOC_CODE_EXAMPLES, NON_AUTOLINKS, PRIVATE_DOC_TESTS,
|
||||
BARE_TRAIT_OBJECTS, ELIDED_LIFETIMES_IN_PATHS, EXPLICIT_OUTLIVES_REQUIREMENTS,
|
||||
};
|
||||
use rustc_span::symbol::{Ident, Symbol};
|
||||
use rustc_span::Span;
|
||||
|
@ -314,17 +312,6 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
|
|||
// MACRO_USE_EXTERN_CRATE
|
||||
);
|
||||
|
||||
add_lint_group!(
|
||||
"rustdoc",
|
||||
NON_AUTOLINKS,
|
||||
BROKEN_INTRA_DOC_LINKS,
|
||||
PRIVATE_INTRA_DOC_LINKS,
|
||||
INVALID_CODEBLOCK_ATTRIBUTES,
|
||||
MISSING_DOC_CODE_EXAMPLES,
|
||||
PRIVATE_DOC_TESTS,
|
||||
INVALID_HTML_TAGS
|
||||
);
|
||||
|
||||
// Register renamed and removed lints.
|
||||
store.register_renamed("single_use_lifetime", "single_use_lifetimes");
|
||||
store.register_renamed("elided_lifetime_in_path", "elided_lifetimes_in_paths");
|
||||
|
@ -334,8 +321,29 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
|
|||
store.register_renamed("async_idents", "keyword_idents");
|
||||
store.register_renamed("exceeding_bitshifts", "arithmetic_overflow");
|
||||
store.register_renamed("redundant_semicolon", "redundant_semicolons");
|
||||
store.register_renamed("intra_doc_link_resolution_failure", "broken_intra_doc_links");
|
||||
store.register_renamed("overlapping_patterns", "overlapping_range_endpoints");
|
||||
|
||||
// These were moved to tool lints, but rustc still sees them when compiling normally, before
|
||||
// tool lints are registered, so `check_tool_name_for_backwards_compat` doesn't work. Use
|
||||
// `register_removed` explicitly.
|
||||
const RUSTDOC_LINTS: &[&str] = &[
|
||||
"broken_intra_doc_links",
|
||||
"private_intra_doc_links",
|
||||
"missing_crate_level_docs",
|
||||
"missing_doc_code_examples",
|
||||
"private_doc_tests",
|
||||
"invalid_codeblock_attributes",
|
||||
"invalid_html_tags",
|
||||
"non_autolinks",
|
||||
];
|
||||
for rustdoc_lint in RUSTDOC_LINTS {
|
||||
store.register_removed(rustdoc_lint, &format!("use `rustdoc::{}` instead", rustdoc_lint));
|
||||
}
|
||||
store.register_removed(
|
||||
"intra_doc_link_resolution_failure",
|
||||
"use `rustdoc::broken_intra_doc_links` instead",
|
||||
);
|
||||
|
||||
store.register_removed("unknown_features", "replaced by an error");
|
||||
store.register_removed("unsigned_negation", "replaced by negate_unsigned feature gate");
|
||||
store.register_removed("negate_unsigned", "cast a signed value instead");
|
||||
|
|
|
@ -1875,93 +1875,6 @@ declare_lint! {
|
|||
"detects labels that are never used"
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
/// The `broken_intra_doc_links` lint detects failures in resolving
|
||||
/// intra-doc link targets. This is a `rustdoc` only lint, see the
|
||||
/// documentation in the [rustdoc book].
|
||||
///
|
||||
/// [rustdoc book]: ../../../rustdoc/lints.html#broken_intra_doc_links
|
||||
pub BROKEN_INTRA_DOC_LINKS,
|
||||
Warn,
|
||||
"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#private_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
|
||||
/// is a `rustdoc` only lint, see the documentation in the [rustdoc book].
|
||||
///
|
||||
/// [rustdoc book]: ../../../rustdoc/lints.html#invalid_codeblock_attributes
|
||||
pub INVALID_CODEBLOCK_ATTRIBUTES,
|
||||
Warn,
|
||||
"codeblock attribute looks a lot like a known one"
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
/// The `missing_crate_level_docs` lint detects if documentation is
|
||||
/// missing at the crate root. This is a `rustdoc` only lint, see the
|
||||
/// documentation in the [rustdoc book].
|
||||
///
|
||||
/// [rustdoc book]: ../../../rustdoc/lints.html#missing_crate_level_docs
|
||||
pub MISSING_CRATE_LEVEL_DOCS,
|
||||
Allow,
|
||||
"detects crates with no crate-level documentation"
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
/// The `missing_doc_code_examples` lint detects publicly-exported items
|
||||
/// without code samples in their documentation. This is a `rustdoc` only
|
||||
/// lint, see the documentation in the [rustdoc book].
|
||||
///
|
||||
/// [rustdoc book]: ../../../rustdoc/lints.html#missing_doc_code_examples
|
||||
pub MISSING_DOC_CODE_EXAMPLES,
|
||||
Allow,
|
||||
"detects publicly-exported items without code samples in their documentation"
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
/// The `private_doc_tests` lint detects code samples in docs of private
|
||||
/// items not documented by `rustdoc`. This is a `rustdoc` only lint, see
|
||||
/// the documentation in the [rustdoc book].
|
||||
///
|
||||
/// [rustdoc book]: ../../../rustdoc/lints.html#private_doc_tests
|
||||
pub PRIVATE_DOC_TESTS,
|
||||
Allow,
|
||||
"detects code samples in docs of private items not documented by rustdoc"
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
/// The `invalid_html_tags` lint detects invalid HTML tags. This is a
|
||||
/// `rustdoc` only lint, see the documentation in the [rustdoc book].
|
||||
///
|
||||
/// [rustdoc book]: ../../../rustdoc/lints.html#invalid_html_tags
|
||||
pub INVALID_HTML_TAGS,
|
||||
Allow,
|
||||
"detects invalid HTML tags in doc comments"
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
/// The `non_autolinks` lint detects when a URL could be written using
|
||||
/// only angle brackets. This is a `rustdoc` only lint, see the
|
||||
/// documentation in the [rustdoc book].
|
||||
///
|
||||
/// [rustdoc book]: ../../../rustdoc/lints.html#non_autolinks
|
||||
pub NON_AUTOLINKS,
|
||||
Warn,
|
||||
"detects URLs that could be written using only angle brackets"
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
/// The `where_clauses_object_safety` lint detects for [object safety] of
|
||||
/// [where clauses].
|
||||
|
@ -3020,14 +2933,6 @@ declare_lint_pass! {
|
|||
ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
|
||||
UNSTABLE_NAME_COLLISIONS,
|
||||
IRREFUTABLE_LET_PATTERNS,
|
||||
BROKEN_INTRA_DOC_LINKS,
|
||||
PRIVATE_INTRA_DOC_LINKS,
|
||||
INVALID_CODEBLOCK_ATTRIBUTES,
|
||||
MISSING_CRATE_LEVEL_DOCS,
|
||||
MISSING_DOC_CODE_EXAMPLES,
|
||||
INVALID_HTML_TAGS,
|
||||
PRIVATE_DOC_TESTS,
|
||||
NON_AUTOLINKS,
|
||||
WHERE_CLAUSES_OBJECT_SAFETY,
|
||||
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
|
||||
MACRO_USE_EXTERN_CRATE,
|
||||
|
|
|
@ -1021,6 +1021,7 @@ symbols! {
|
|||
rustc_then_this_would_need,
|
||||
rustc_unsafe_specialization_marker,
|
||||
rustc_variance,
|
||||
rustdoc,
|
||||
rustfmt,
|
||||
rvalue_static_promotion,
|
||||
sanitize,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue