Skip to content

Commit ea7c3e7

Browse files
authored
Rollup merge of rust-lang#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 rust-lang#80300, rust-lang#79816, rust-lang#80965. Makes the strangeness in rust-lang#77364 more apparent to the end user (note that `missing_docs` is *not* moved to rustdoc in this PR). Closes rust-lang#78786. ## Current status This is blocked on rust-lang#82620 (see rust-lang#80527 (comment))
2 parents 045261f + 75efb6e commit ea7c3e7

File tree

86 files changed

+495
-339
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+495
-339
lines changed

compiler/rustc_ast/src/attr/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl MarkedAttrs {
3434
}
3535

3636
pub fn is_known_lint_tool(m_item: Ident) -> bool {
37-
[sym::clippy, sym::rustc].contains(&m_item.name)
37+
[sym::clippy, sym::rustc, sym::rustdoc].contains(&m_item.name)
3838
}
3939

4040
impl NestedMetaItem {

compiler/rustc_error_codes/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#![deny(invalid_codeblock_attributes)]
1+
#![cfg_attr(bootstrap, deny(invalid_codeblock_attributes))]
2+
#![cfg_attr(not(bootstrap), deny(rustdoc::invalid_codeblock_attributes))]
23
//! This library is used to gather all error codes into one place,
34
//! the goal being to make their maintenance easier.
45

compiler/rustc_lint/src/context.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ impl SessionLintStore for LintStore {
8989
}
9090

9191
/// The target of the `by_name` map, which accounts for renaming/deprecation.
92+
#[derive(Debug)]
9293
enum TargetLint {
9394
/// A direct lint target
9495
Id(LintId),
@@ -470,7 +471,10 @@ impl LintStore {
470471
Some(&Id(ref id)) => {
471472
CheckLintNameResult::Tool(Err((Some(slice::from_ref(id)), complete_name)))
472473
}
473-
_ => CheckLintNameResult::NoLint(None),
474+
Some(other) => {
475+
tracing::debug!("got renamed lint {:?}", other);
476+
CheckLintNameResult::NoLint(None)
477+
}
474478
}
475479
}
476480
}

compiler/rustc_lint/src/lib.rs

+23-15
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ use rustc_hir::def_id::LocalDefId;
6969
use rustc_middle::ty::query::Providers;
7070
use rustc_middle::ty::TyCtxt;
7171
use rustc_session::lint::builtin::{
72-
BARE_TRAIT_OBJECTS, BROKEN_INTRA_DOC_LINKS, ELIDED_LIFETIMES_IN_PATHS,
73-
EXPLICIT_OUTLIVES_REQUIREMENTS, INVALID_CODEBLOCK_ATTRIBUTES, INVALID_HTML_TAGS,
74-
MISSING_DOC_CODE_EXAMPLES, NON_AUTOLINKS, PRIVATE_DOC_TESTS,
72+
BARE_TRAIT_OBJECTS, ELIDED_LIFETIMES_IN_PATHS, EXPLICIT_OUTLIVES_REQUIREMENTS,
7573
};
7674
use rustc_span::symbol::{Ident, Symbol};
7775
use rustc_span::Span;
@@ -314,17 +312,6 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
314312
// MACRO_USE_EXTERN_CRATE
315313
);
316314

317-
add_lint_group!(
318-
"rustdoc",
319-
NON_AUTOLINKS,
320-
BROKEN_INTRA_DOC_LINKS,
321-
PRIVATE_INTRA_DOC_LINKS,
322-
INVALID_CODEBLOCK_ATTRIBUTES,
323-
MISSING_DOC_CODE_EXAMPLES,
324-
PRIVATE_DOC_TESTS,
325-
INVALID_HTML_TAGS
326-
);
327-
328315
// Register renamed and removed lints.
329316
store.register_renamed("single_use_lifetime", "single_use_lifetimes");
330317
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) {
334321
store.register_renamed("async_idents", "keyword_idents");
335322
store.register_renamed("exceeding_bitshifts", "arithmetic_overflow");
336323
store.register_renamed("redundant_semicolon", "redundant_semicolons");
337-
store.register_renamed("intra_doc_link_resolution_failure", "broken_intra_doc_links");
338324
store.register_renamed("overlapping_patterns", "overlapping_range_endpoints");
325+
326+
// These were moved to tool lints, but rustc still sees them when compiling normally, before
327+
// tool lints are registered, so `check_tool_name_for_backwards_compat` doesn't work. Use
328+
// `register_removed` explicitly.
329+
const RUSTDOC_LINTS: &[&str] = &[
330+
"broken_intra_doc_links",
331+
"private_intra_doc_links",
332+
"missing_crate_level_docs",
333+
"missing_doc_code_examples",
334+
"private_doc_tests",
335+
"invalid_codeblock_attributes",
336+
"invalid_html_tags",
337+
"non_autolinks",
338+
];
339+
for rustdoc_lint in RUSTDOC_LINTS {
340+
store.register_removed(rustdoc_lint, &format!("use `rustdoc::{}` instead", rustdoc_lint));
341+
}
342+
store.register_removed(
343+
"intra_doc_link_resolution_failure",
344+
"use `rustdoc::broken_intra_doc_links` instead",
345+
);
346+
339347
store.register_removed("unknown_features", "replaced by an error");
340348
store.register_removed("unsigned_negation", "replaced by negate_unsigned feature gate");
341349
store.register_removed("negate_unsigned", "cast a signed value instead");

compiler/rustc_lint_defs/src/builtin.rs

-95
Original file line numberDiff line numberDiff line change
@@ -1875,93 +1875,6 @@ declare_lint! {
18751875
"detects labels that are never used"
18761876
}
18771877

1878-
declare_lint! {
1879-
/// The `broken_intra_doc_links` lint detects failures in resolving
1880-
/// intra-doc link targets. This is a `rustdoc` only lint, see the
1881-
/// documentation in the [rustdoc book].
1882-
///
1883-
/// [rustdoc book]: ../../../rustdoc/lints.html#broken_intra_doc_links
1884-
pub BROKEN_INTRA_DOC_LINKS,
1885-
Warn,
1886-
"failures in resolving intra-doc link targets"
1887-
}
1888-
1889-
declare_lint! {
1890-
/// This is a subset of `broken_intra_doc_links` that warns when linking from
1891-
/// a public item to a private one. This is a `rustdoc` only lint, see the
1892-
/// documentation in the [rustdoc book].
1893-
///
1894-
/// [rustdoc book]: ../../../rustdoc/lints.html#private_intra_doc_links
1895-
pub PRIVATE_INTRA_DOC_LINKS,
1896-
Warn,
1897-
"linking from a public item to a private one"
1898-
}
1899-
1900-
declare_lint! {
1901-
/// The `invalid_codeblock_attributes` lint detects code block attributes
1902-
/// in documentation examples that have potentially mis-typed values. This
1903-
/// is a `rustdoc` only lint, see the documentation in the [rustdoc book].
1904-
///
1905-
/// [rustdoc book]: ../../../rustdoc/lints.html#invalid_codeblock_attributes
1906-
pub INVALID_CODEBLOCK_ATTRIBUTES,
1907-
Warn,
1908-
"codeblock attribute looks a lot like a known one"
1909-
}
1910-
1911-
declare_lint! {
1912-
/// The `missing_crate_level_docs` lint detects if documentation is
1913-
/// missing at the crate root. This is a `rustdoc` only lint, see the
1914-
/// documentation in the [rustdoc book].
1915-
///
1916-
/// [rustdoc book]: ../../../rustdoc/lints.html#missing_crate_level_docs
1917-
pub MISSING_CRATE_LEVEL_DOCS,
1918-
Allow,
1919-
"detects crates with no crate-level documentation"
1920-
}
1921-
1922-
declare_lint! {
1923-
/// The `missing_doc_code_examples` lint detects publicly-exported items
1924-
/// without code samples in their documentation. This is a `rustdoc` only
1925-
/// lint, see the documentation in the [rustdoc book].
1926-
///
1927-
/// [rustdoc book]: ../../../rustdoc/lints.html#missing_doc_code_examples
1928-
pub MISSING_DOC_CODE_EXAMPLES,
1929-
Allow,
1930-
"detects publicly-exported items without code samples in their documentation"
1931-
}
1932-
1933-
declare_lint! {
1934-
/// The `private_doc_tests` lint detects code samples in docs of private
1935-
/// items not documented by `rustdoc`. This is a `rustdoc` only lint, see
1936-
/// the documentation in the [rustdoc book].
1937-
///
1938-
/// [rustdoc book]: ../../../rustdoc/lints.html#private_doc_tests
1939-
pub PRIVATE_DOC_TESTS,
1940-
Allow,
1941-
"detects code samples in docs of private items not documented by rustdoc"
1942-
}
1943-
1944-
declare_lint! {
1945-
/// The `invalid_html_tags` lint detects invalid HTML tags. This is a
1946-
/// `rustdoc` only lint, see the documentation in the [rustdoc book].
1947-
///
1948-
/// [rustdoc book]: ../../../rustdoc/lints.html#invalid_html_tags
1949-
pub INVALID_HTML_TAGS,
1950-
Allow,
1951-
"detects invalid HTML tags in doc comments"
1952-
}
1953-
1954-
declare_lint! {
1955-
/// The `non_autolinks` lint detects when a URL could be written using
1956-
/// only angle brackets. This is a `rustdoc` only lint, see the
1957-
/// documentation in the [rustdoc book].
1958-
///
1959-
/// [rustdoc book]: ../../../rustdoc/lints.html#non_autolinks
1960-
pub NON_AUTOLINKS,
1961-
Warn,
1962-
"detects URLs that could be written using only angle brackets"
1963-
}
1964-
19651878
declare_lint! {
19661879
/// The `where_clauses_object_safety` lint detects for [object safety] of
19671880
/// [where clauses].
@@ -3020,14 +2933,6 @@ declare_lint_pass! {
30202933
ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
30212934
UNSTABLE_NAME_COLLISIONS,
30222935
IRREFUTABLE_LET_PATTERNS,
3023-
BROKEN_INTRA_DOC_LINKS,
3024-
PRIVATE_INTRA_DOC_LINKS,
3025-
INVALID_CODEBLOCK_ATTRIBUTES,
3026-
MISSING_CRATE_LEVEL_DOCS,
3027-
MISSING_DOC_CODE_EXAMPLES,
3028-
INVALID_HTML_TAGS,
3029-
PRIVATE_DOC_TESTS,
3030-
NON_AUTOLINKS,
30312936
WHERE_CLAUSES_OBJECT_SAFETY,
30322937
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
30332938
MACRO_USE_EXTERN_CRATE,

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,7 @@ symbols! {
10221022
rustc_then_this_would_need,
10231023
rustc_unsafe_specialization_marker,
10241024
rustc_variance,
1025+
rustdoc,
10251026
rustfmt,
10261027
rvalue_static_promotion,
10271028
sanitize,

library/core/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ pub mod primitive;
297297
unused_imports,
298298
unsafe_op_in_unsafe_fn
299299
)]
300-
#[allow(non_autolinks)]
300+
#[cfg_attr(bootstrap, allow(non_autolinks))]
301+
#[cfg_attr(not(bootstrap), allow(rustdoc::non_autolinks))]
301302
// FIXME: This annotation should be moved into rust-lang/stdarch after clashing_extern_declarations is
302303
// merged. It currently cannot because bootstrap fails as the lint hasn't been defined yet.
303304
#[allow(clashing_extern_declarations)]

src/bootstrap/builder.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -735,8 +735,15 @@ impl<'a> Builder<'a> {
735735
.env("RUSTDOC_LIBDIR", self.rustc_libdir(compiler))
736736
.env("CFG_RELEASE_CHANNEL", &self.config.channel)
737737
.env("RUSTDOC_REAL", self.rustdoc(compiler))
738-
.env("RUSTC_BOOTSTRAP", "1")
739-
.arg("-Winvalid_codeblock_attributes");
738+
.env("RUSTC_BOOTSTRAP", "1");
739+
740+
// cfg(bootstrap), can be removed on the next beta bump
741+
if compiler.stage == 0 {
742+
cmd.arg("-Winvalid_codeblock_attributes");
743+
} else {
744+
cmd.arg("-Wrustdoc::invalid_codeblock_attributes");
745+
}
746+
740747
if self.config.deny_warnings {
741748
cmd.arg("-Dwarnings");
742749
}
@@ -1292,7 +1299,12 @@ impl<'a> Builder<'a> {
12921299
// fixed via better support from Cargo.
12931300
cargo.env("RUSTC_LINT_FLAGS", lint_flags.join(" "));
12941301

1295-
rustdocflags.arg("-Winvalid_codeblock_attributes");
1302+
// cfg(bootstrap), can be removed on the next beta bump
1303+
if compiler.stage == 0 {
1304+
rustdocflags.arg("-Winvalid_codeblock_attributes");
1305+
} else {
1306+
rustdocflags.arg("-Wrustdoc::invalid_codeblock_attributes");
1307+
}
12961308
}
12971309

12981310
if mode == Mode::Rustc {

src/doc/rustdoc/src/lints.md

+21-14
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
can use them like any other lints by doing this:
55

66
```rust
7-
#![allow(missing_docs)] // allows the lint, no diagnostics will be reported
8-
#![warn(missing_docs)] // warn if there are missing docs
9-
#![deny(missing_docs)] // error if there are missing docs
10-
# //! Crate docs.
7+
#![allow(rustdoc::broken_intra_doc_links)] // allows the lint, no diagnostics will be reported
8+
#![warn(rustdoc::broken_intra_doc_links)] // warn if there are broken intra-doc links
9+
#![deny(rustdoc::broken_intra_doc_links)] // error if there are broken intra-doc links
1110
```
1211

12+
Note that, except for `missing_docs`, these lints are only available when running `rustdoc`, not `rustc`.
13+
1314
Here is the list of the lints provided by `rustdoc`:
1415

1516
## broken_intra_doc_links
@@ -51,7 +52,7 @@ warning: `Foo` is both an enum and a function
5152
1 | /// [`Foo`]
5253
| ^^^^^ ambiguous link
5354
|
54-
= note: `#[warn(broken_intra_doc_links)]` on by default
55+
= note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
5556
help: to link to the enum, prefix with the item type
5657
|
5758
1 | /// [`enum@Foo`]
@@ -83,7 +84,7 @@ warning: public documentation for `public` links to private item `private`
8384
1 | /// [private]
8485
| ^^^^^^^ this item is private
8586
|
86-
= note: `#[warn(private_intra_doc_links)]` on by default
87+
= note: `#[warn(rustdoc::private_intra_doc_links)]` on by default
8788
= note: this link will resolve properly if you pass `--document-private-items`
8889
```
8990

@@ -97,7 +98,7 @@ warning: public documentation for `public` links to private item `private`
9798
1 | /// [private]
9899
| ^^^^^^^ this item is private
99100
|
100-
= note: `#[warn(private_intra_doc_links)]` on by default
101+
= note: `#[warn(rustdoc::private_intra_doc_links)]` on by default
101102
= note: this link resolves only because you passed `--document-private-items`, but will break without
102103
```
103104

@@ -125,13 +126,15 @@ warning: missing documentation for a function
125126
| ^^^^^^^^^^^^^^^^^^^^^
126127
```
127128

129+
Note that unlike other rustdoc lints, this lint is also available from `rustc` directly.
130+
128131
## missing_crate_level_docs
129132

130133
This lint is **allowed by default**. It detects if there is no documentation
131134
at the crate root. For example:
132135

133136
```rust
134-
#![warn(missing_crate_level_docs)]
137+
#![warn(rustdoc::missing_crate_level_docs)]
135138
```
136139

137140
This will generate the following warning:
@@ -155,7 +158,7 @@ This lint is **allowed by default** and is **nightly-only**. It detects when a d
155158
is missing a code example. For example:
156159

157160
```rust
158-
#![warn(missing_doc_code_examples)]
161+
#![warn(rustdoc::missing_doc_code_examples)]
159162

160163
/// There is no code example!
161164
pub fn no_code_example() {}
@@ -191,7 +194,7 @@ This lint is **allowed by default**. It detects documentation tests when they
191194
are on a private item. For example:
192195

193196
```rust
194-
#![warn(private_doc_tests)]
197+
#![warn(rustdoc::private_doc_tests)]
195198

196199
mod foo {
197200
/// private doc test
@@ -245,7 +248,7 @@ warning: unknown attribute `should-panic`. Did you mean `should_panic`?
245248
5 | | /// ```
246249
| |_______^
247250
|
248-
= note: `#[warn(invalid_codeblock_attributes)]` on by default
251+
= note: `#[warn(rustdoc::invalid_codeblock_attributes)]` on by default
249252
= help: the code block will either not be tested if not marked as a rust one or won't fail if it doesn't panic when running
250253
```
251254

@@ -258,7 +261,7 @@ This lint is **allowed by default** and is **nightly-only**. It detects unclosed
258261
or invalid HTML tags. For example:
259262

260263
```rust
261-
#![warn(invalid_html_tags)]
264+
#![warn(rustdoc::invalid_html_tags)]
262265

263266
/// <h1>
264267
/// </script>
@@ -275,7 +278,11 @@ warning: unopened HTML tag `script`
275278
2 | | /// </script>
276279
| |_____________^
277280
|
278-
= note: `#[warn(invalid_html_tags)]` on by default
281+
note: the lint level is defined here
282+
--> foo.rs:1:9
283+
|
284+
1 | #![warn(rustdoc::invalid_html_tags)]
285+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
279286
280287
warning: unclosed HTML tag `h1`
281288
--> foo.rs:1:1
@@ -310,7 +317,7 @@ warning: this URL is not a hyperlink
310317
1 | /// http://example.org
311318
| ^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<http://example.org>`
312319
|
313-
= note: `#[warn(non_autolinks)]` on by default
320+
= note: `#[warn(rustdoc::non_autolinks)]` on by default
314321
315322
warning: unneeded long form for URL
316323
--> foo.rs:2:5

0 commit comments

Comments
 (0)