Skip to content

Commit ae93bc5

Browse files
committed
Warn about unknown or renamed lints
Originally I tried to do a much broader refactoring that got rid of `init_lints` altogether. My reasoning is that now the lints aren't being run anymore (after rust-lang#73566), there's no need to ignore them explicitly. But it seems there are still some lints that aren't affected by setting `lint_mod` to a no-op: ``` deny(pub_use_of_private_extern_crate) deny(const_err) warn(unused_imports) ``` (there are possibly more, these are just the ones that failed in the rustdoc test suite). Some of these seem like we really should be warning about, but that's a much larger change and I don't propose to make it here. So for the time being, this just adds the `unknown_lints` and `renamed_or_removed_lints` passes to the list of lints rustdoc warns about.
1 parent bc7bce4 commit ae93bc5

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

src/librustdoc/core.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ pub fn new_handler(
234234
/// It returns a tuple containing:
235235
/// * Vector of tuples of lints' name and their associated "max" level
236236
/// * HashMap of lint id with their associated "max" level
237-
pub fn init_lints<F>(
237+
pub(crate) fn init_lints<F>(
238238
mut allowed_lints: Vec<String>,
239239
lint_opts: Vec<(String, lint::Level)>,
240240
filter_call: F,
@@ -257,7 +257,10 @@ where
257257
.filter_map(|lint| {
258258
// Permit feature-gated lints to avoid feature errors when trying to
259259
// allow all lints.
260-
if lint.name == warnings_lint_name || lint.feature_gate.is_some() {
260+
if lint.name == warnings_lint_name
261+
|| lint.feature_gate.is_some()
262+
|| allowed_lints.iter().any(|l| lint.name == l)
263+
{
261264
None
262265
} else {
263266
filter_call(lint)
@@ -328,6 +331,8 @@ pub fn run_core(
328331
let private_doc_tests = rustc_lint::builtin::PRIVATE_DOC_TESTS.name;
329332
let no_crate_level_docs = rustc_lint::builtin::MISSING_CRATE_LEVEL_DOCS.name;
330333
let invalid_codeblock_attributes_name = rustc_lint::builtin::INVALID_CODEBLOCK_ATTRIBUTES.name;
334+
let renamed_and_removed_lints = rustc_lint::builtin::RENAMED_AND_REMOVED_LINTS.name;
335+
let unknown_lints = rustc_lint::builtin::UNKNOWN_LINTS.name;
331336

332337
// In addition to those specific lints, we also need to allow those given through
333338
// command line, otherwise they'll get ignored and we don't want that.
@@ -338,6 +343,8 @@ pub fn run_core(
338343
private_doc_tests.to_owned(),
339344
no_crate_level_docs.to_owned(),
340345
invalid_codeblock_attributes_name.to_owned(),
346+
renamed_and_removed_lints.to_owned(),
347+
unknown_lints.to_owned(),
341348
];
342349

343350
let (lint_opts, lint_caps) = init_lints(lints_to_show, lint_opts, |lint| {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![deny(unknown_lints)]
2+
//~^ NOTE lint level is defined
3+
#![deny(renamed_and_removed_lints)]
4+
//~^ NOTE lint level is defined
5+
#![deny(x)]
6+
//~^ ERROR unknown lint
7+
#![deny(intra_doc_link_resolution_failure)]
8+
//~^ ERROR lint `intra_doc_link_resolution_failure` has been renamed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
error: unknown lint: `x`
2+
--> $DIR/unknown-renamed-lints.rs:5:9
3+
|
4+
LL | #![deny(x)]
5+
| ^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/unknown-renamed-lints.rs:1:9
9+
|
10+
LL | #![deny(unknown_lints)]
11+
| ^^^^^^^^^^^^^
12+
13+
error: lint `intra_doc_link_resolution_failure` has been renamed to `broken_intra_doc_links`
14+
--> $DIR/unknown-renamed-lints.rs:7:9
15+
|
16+
LL | #![deny(intra_doc_link_resolution_failure)]
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `broken_intra_doc_links`
18+
|
19+
note: the lint level is defined here
20+
--> $DIR/unknown-renamed-lints.rs:3:9
21+
|
22+
LL | #![deny(renamed_and_removed_lints)]
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
24+
25+
error: Compilation failed, aborting rustdoc
26+
27+
error: aborting due to 3 previous errors
28+

0 commit comments

Comments
 (0)