Skip to content

Warn about unknown or renamed lints in rustdoc #75903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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