Skip to content

Commit

Permalink
Auto merge of #75903 - jyn514:lint-refactor, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
Warn about unknown or renamed lints in rustdoc

Fixes #75884.
This is best reviewed one commit at a time.
r? @GuillaumeGomez

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 #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
bors committed Aug 26, 2020
2 parents 6ead622 + e11b3ee commit 1f2dd3b
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 18 deletions.
16 changes: 8 additions & 8 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ pub struct Options {
/// Codegen options strings to hand to the compiler.
pub codegen_options_strs: Vec<String>,
/// Debugging (`-Z`) options to pass to the compiler.
pub debugging_options: DebuggingOptions,
pub debugging_opts: DebuggingOptions,
/// Debugging (`-Z`) options strings to pass to the compiler.
pub debugging_options_strs: Vec<String>,
pub debugging_opts_strs: Vec<String>,
/// The target used to compile the crate against.
pub target: TargetTriple,
/// Edition used when reading the crate. Defaults to "2015". Also used by default when
Expand Down Expand Up @@ -318,9 +318,9 @@ impl Options {
let error_format = config::parse_error_format(&matches, color, json_rendered);

let codegen_options = build_codegen_options(matches, error_format);
let debugging_options = build_debugging_options(matches, error_format);
let debugging_opts = build_debugging_options(matches, error_format);

let diag = new_handler(error_format, None, &debugging_options);
let diag = new_handler(error_format, None, &debugging_opts);

// check for deprecated options
check_deprecated_options(&matches, &diag);
Expand Down Expand Up @@ -365,7 +365,7 @@ impl Options {
.iter()
.map(|s| SearchPath::from_cli_opt(s, error_format))
.collect();
let externs = parse_externs(&matches, &debugging_options, error_format);
let externs = parse_externs(&matches, &debugging_opts, error_format);
let extern_html_root_urls = match parse_extern_html_roots(&matches) {
Ok(ex) => ex,
Err(err) => {
Expand Down Expand Up @@ -546,7 +546,7 @@ impl Options {
let persist_doctests = matches.opt_str("persist-doctests").map(PathBuf::from);
let test_builder = matches.opt_str("test-builder").map(PathBuf::from);
let codegen_options_strs = matches.opt_strs("C");
let debugging_options_strs = matches.opt_strs("Z");
let debugging_opts_strs = matches.opt_strs("Z");
let lib_strs = matches.opt_strs("L");
let extern_strs = matches.opt_strs("extern");
let runtool = matches.opt_str("runtool");
Expand All @@ -569,8 +569,8 @@ impl Options {
cfgs,
codegen_options,
codegen_options_strs,
debugging_options,
debugging_options_strs,
debugging_opts,
debugging_opts_strs,
target,
edition,
maybe_sysroot,
Expand Down
18 changes: 11 additions & 7 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,7 @@ 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.feature_gate.is_some() || allowed_lints.iter().any(|l| lint.name == l) {
None
} else {
filter_call(lint)
Expand Down Expand Up @@ -294,7 +294,7 @@ pub fn run_core(
externs,
mut cfgs,
codegen_options,
debugging_options,
debugging_opts,
target,
edition,
maybe_sysroot,
Expand Down Expand Up @@ -328,19 +328,23 @@ 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.
let allowed_lints = vec![
let lints_to_show = vec![
intra_link_resolution_failure_name.to_owned(),
missing_docs.to_owned(),
missing_doc_example.to_owned(),
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(allowed_lints, lint_opts, |lint| {
let (lint_opts, lint_caps) = init_lints(lints_to_show, lint_opts, |lint| {
if lint.name == intra_link_resolution_failure_name
|| lint.name == invalid_codeblock_attributes_name
{
Expand All @@ -358,13 +362,13 @@ pub fn run_core(
search_paths: libs,
crate_types,
lint_opts: if !display_warnings { lint_opts } else { vec![] },
lint_cap: Some(lint_cap.unwrap_or_else(|| lint::Forbid)),
lint_cap,
cg: codegen_options,
externs,
target_triple: target,
unstable_features: UnstableFeatures::from_environment(),
actually_rustdoc: true,
debugging_opts: debugging_options,
debugging_opts,
error_format,
edition,
describe_lints,
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ fn run_renderer<T: formats::FormatRenderer>(
}

fn main_options(options: config::Options) -> MainResult {
let diag = core::new_handler(options.error_format, None, &options.debugging_options);
let diag = core::new_handler(options.error_format, None, &options.debugging_opts);

match (options.should_test, options.markdown_input()) {
(true, true) => return wrap_return(&diag, markdown::test(options)),
Expand All @@ -488,7 +488,7 @@ fn main_options(options: config::Options) -> MainResult {

// need to move these items separately because we lose them by the time the closure is called,
// but we can't crates the Handler ahead of time because it's not Send
let diag_opts = (options.error_format, options.edition, options.debugging_options.clone());
let diag_opts = (options.error_format, options.edition, options.debugging_opts.clone());
let show_coverage = options.show_coverage;

// First, parse the crate and extract all relevant information.
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ fn run_test(
for codegen_options_str in &options.codegen_options_strs {
compiler.arg("-C").arg(&codegen_options_str);
}
for debugging_option_str in &options.debugging_options_strs {
for debugging_option_str in &options.debugging_opts_strs {
compiler.arg("-Z").arg(&debugging_option_str);
}
if no_run && !compile_fail {
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 1f2dd3b

Please sign in to comment.