Skip to content

Commit

Permalink
Warn about unknown or renamed lints
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jyn514 committed Aug 25, 2020
1 parent bc7bce4 commit ae93bc5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ pub fn new_handler(
/// It returns a tuple containing:
/// * Vector of tuples of lints' name and their associated "max" level
/// * HashMap of lint id with their associated "max" level
pub fn init_lints<F>(
pub(crate) fn init_lints<F>(
mut allowed_lints: Vec<String>,
lint_opts: Vec<(String, lint::Level)>,
filter_call: F,
Expand All @@ -257,7 +257,10 @@ where
.filter_map(|lint| {
// Permit feature-gated lints to avoid feature errors when trying to
// allow all lints.
if lint.name == warnings_lint_name || lint.feature_gate.is_some() {
if lint.name == warnings_lint_name
|| lint.feature_gate.is_some()
|| allowed_lints.iter().any(|l| lint.name == l)
{
None
} else {
filter_call(lint)
Expand Down Expand Up @@ -328,6 +331,8 @@ pub fn run_core(
let private_doc_tests = rustc_lint::builtin::PRIVATE_DOC_TESTS.name;
let no_crate_level_docs = rustc_lint::builtin::MISSING_CRATE_LEVEL_DOCS.name;
let invalid_codeblock_attributes_name = rustc_lint::builtin::INVALID_CODEBLOCK_ATTRIBUTES.name;
let renamed_and_removed_lints = rustc_lint::builtin::RENAMED_AND_REMOVED_LINTS.name;
let unknown_lints = rustc_lint::builtin::UNKNOWN_LINTS.name;

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

let (lint_opts, lint_caps) = init_lints(lints_to_show, lint_opts, |lint| {
Expand Down
8 changes: 8 additions & 0 deletions src/test/rustdoc-ui/unknown-renamed-lints.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![deny(unknown_lints)]
//~^ NOTE lint level is defined
#![deny(renamed_and_removed_lints)]
//~^ NOTE lint level is defined
#![deny(x)]
//~^ ERROR unknown lint
#![deny(intra_doc_link_resolution_failure)]
//~^ ERROR lint `intra_doc_link_resolution_failure` has been renamed
28 changes: 28 additions & 0 deletions src/test/rustdoc-ui/unknown-renamed-lints.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
error: unknown lint: `x`
--> $DIR/unknown-renamed-lints.rs:5:9
|
LL | #![deny(x)]
| ^
|
note: the lint level is defined here
--> $DIR/unknown-renamed-lints.rs:1:9
|
LL | #![deny(unknown_lints)]
| ^^^^^^^^^^^^^

error: lint `intra_doc_link_resolution_failure` has been renamed to `broken_intra_doc_links`
--> $DIR/unknown-renamed-lints.rs:7:9
|
LL | #![deny(intra_doc_link_resolution_failure)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `broken_intra_doc_links`
|
note: the lint level is defined here
--> $DIR/unknown-renamed-lints.rs:3:9
|
LL | #![deny(renamed_and_removed_lints)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error: Compilation failed, aborting rustdoc

error: aborting due to 3 previous errors

0 comments on commit ae93bc5

Please sign in to comment.