Skip to content

Commit 1f2dd3b

Browse files
committed
Auto merge of rust-lang#75903 - jyn514:lint-refactor, r=GuillaumeGomez
Warn about unknown or renamed lints in rustdoc Fixes rust-lang#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 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.
2 parents 6ead622 + e11b3ee commit 1f2dd3b

File tree

6 files changed

+58
-18
lines changed

6 files changed

+58
-18
lines changed

src/librustdoc/config.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ pub struct Options {
8383
/// Codegen options strings to hand to the compiler.
8484
pub codegen_options_strs: Vec<String>,
8585
/// Debugging (`-Z`) options to pass to the compiler.
86-
pub debugging_options: DebuggingOptions,
86+
pub debugging_opts: DebuggingOptions,
8787
/// Debugging (`-Z`) options strings to pass to the compiler.
88-
pub debugging_options_strs: Vec<String>,
88+
pub debugging_opts_strs: Vec<String>,
8989
/// The target used to compile the crate against.
9090
pub target: TargetTriple,
9191
/// Edition used when reading the crate. Defaults to "2015". Also used by default when
@@ -318,9 +318,9 @@ impl Options {
318318
let error_format = config::parse_error_format(&matches, color, json_rendered);
319319

320320
let codegen_options = build_codegen_options(matches, error_format);
321-
let debugging_options = build_debugging_options(matches, error_format);
321+
let debugging_opts = build_debugging_options(matches, error_format);
322322

323-
let diag = new_handler(error_format, None, &debugging_options);
323+
let diag = new_handler(error_format, None, &debugging_opts);
324324

325325
// check for deprecated options
326326
check_deprecated_options(&matches, &diag);
@@ -365,7 +365,7 @@ impl Options {
365365
.iter()
366366
.map(|s| SearchPath::from_cli_opt(s, error_format))
367367
.collect();
368-
let externs = parse_externs(&matches, &debugging_options, error_format);
368+
let externs = parse_externs(&matches, &debugging_opts, error_format);
369369
let extern_html_root_urls = match parse_extern_html_roots(&matches) {
370370
Ok(ex) => ex,
371371
Err(err) => {
@@ -546,7 +546,7 @@ impl Options {
546546
let persist_doctests = matches.opt_str("persist-doctests").map(PathBuf::from);
547547
let test_builder = matches.opt_str("test-builder").map(PathBuf::from);
548548
let codegen_options_strs = matches.opt_strs("C");
549-
let debugging_options_strs = matches.opt_strs("Z");
549+
let debugging_opts_strs = matches.opt_strs("Z");
550550
let lib_strs = matches.opt_strs("L");
551551
let extern_strs = matches.opt_strs("extern");
552552
let runtool = matches.opt_str("runtool");
@@ -569,8 +569,8 @@ impl Options {
569569
cfgs,
570570
codegen_options,
571571
codegen_options_strs,
572-
debugging_options,
573-
debugging_options_strs,
572+
debugging_opts,
573+
debugging_opts_strs,
574574
target,
575575
edition,
576576
maybe_sysroot,

src/librustdoc/core.rs

+11-7
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,7 @@ 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.feature_gate.is_some() || allowed_lints.iter().any(|l| lint.name == l) {
261261
None
262262
} else {
263263
filter_call(lint)
@@ -294,7 +294,7 @@ pub fn run_core(
294294
externs,
295295
mut cfgs,
296296
codegen_options,
297-
debugging_options,
297+
debugging_opts,
298298
target,
299299
edition,
300300
maybe_sysroot,
@@ -328,19 +328,23 @@ pub fn run_core(
328328
let private_doc_tests = rustc_lint::builtin::PRIVATE_DOC_TESTS.name;
329329
let no_crate_level_docs = rustc_lint::builtin::MISSING_CRATE_LEVEL_DOCS.name;
330330
let invalid_codeblock_attributes_name = rustc_lint::builtin::INVALID_CODEBLOCK_ATTRIBUTES.name;
331+
let renamed_and_removed_lints = rustc_lint::builtin::RENAMED_AND_REMOVED_LINTS.name;
332+
let unknown_lints = rustc_lint::builtin::UNKNOWN_LINTS.name;
331333

332334
// In addition to those specific lints, we also need to allow those given through
333335
// command line, otherwise they'll get ignored and we don't want that.
334-
let allowed_lints = vec![
336+
let lints_to_show = vec![
335337
intra_link_resolution_failure_name.to_owned(),
336338
missing_docs.to_owned(),
337339
missing_doc_example.to_owned(),
338340
private_doc_tests.to_owned(),
339341
no_crate_level_docs.to_owned(),
340342
invalid_codeblock_attributes_name.to_owned(),
343+
renamed_and_removed_lints.to_owned(),
344+
unknown_lints.to_owned(),
341345
];
342346

343-
let (lint_opts, lint_caps) = init_lints(allowed_lints, lint_opts, |lint| {
347+
let (lint_opts, lint_caps) = init_lints(lints_to_show, lint_opts, |lint| {
344348
if lint.name == intra_link_resolution_failure_name
345349
|| lint.name == invalid_codeblock_attributes_name
346350
{
@@ -358,13 +362,13 @@ pub fn run_core(
358362
search_paths: libs,
359363
crate_types,
360364
lint_opts: if !display_warnings { lint_opts } else { vec![] },
361-
lint_cap: Some(lint_cap.unwrap_or_else(|| lint::Forbid)),
365+
lint_cap,
362366
cg: codegen_options,
363367
externs,
364368
target_triple: target,
365369
unstable_features: UnstableFeatures::from_environment(),
366370
actually_rustdoc: true,
367-
debugging_opts: debugging_options,
371+
debugging_opts,
368372
error_format,
369373
edition,
370374
describe_lints,

src/librustdoc/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ fn run_renderer<T: formats::FormatRenderer>(
472472
}
473473

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

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

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

494494
// First, parse the crate and extract all relevant information.

src/librustdoc/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ fn run_test(
281281
for codegen_options_str in &options.codegen_options_strs {
282282
compiler.arg("-C").arg(&codegen_options_str);
283283
}
284-
for debugging_option_str in &options.debugging_options_strs {
284+
for debugging_option_str in &options.debugging_opts_strs {
285285
compiler.arg("-Z").arg(&debugging_option_str);
286286
}
287287
if no_run && !compile_fail {
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)