Skip to content

Commit ce76d73

Browse files
authored
Rollup merge of #98799 - jyn514:rustdoc-lint-help, r=GuillaumeGomez
Fix bug in `rustdoc -Whelp` Previously, this printed the debugging options, not the lint options, and only handled `-Whelp`, not `-A/-D/-F`. This also fixes a few other misc issues: - Fix `// check-stdout` for UI tests; previously it only worked for run-fail and compile-fail tests - Add lint headers for tool lints, not just builtin lints #98533 (comment) r? ```@GuillaumeGomez```
2 parents 87df0f1 + 17da4e0 commit ce76d73

File tree

10 files changed

+69
-422
lines changed

10 files changed

+69
-422
lines changed

compiler/rustc_driver/src/lib.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -849,10 +849,10 @@ Available lint options:
849849
};
850850

851851
println!("Lint checks provided by rustc:\n");
852-
println!(" {} {:7.7} {}", padded("name"), "default", "meaning");
853-
println!(" {} {:7.7} {}", padded("----"), "-------", "-------");
854852

855853
let print_lints = |lints: Vec<&Lint>| {
854+
println!(" {} {:7.7} {}", padded("name"), "default", "meaning");
855+
println!(" {} {:7.7} {}", padded("----"), "-------", "-------");
856856
for lint in lints {
857857
let name = lint.name_lower().replace('_', "-");
858858
println!(
@@ -884,11 +884,15 @@ Available lint options:
884884
};
885885

886886
println!("Lint groups provided by rustc:\n");
887-
println!(" {} sub-lints", padded("name"));
888-
println!(" {} ---------", padded("----"));
889-
println!(" {} all lints that are set to issue warnings", padded("warnings"));
890887

891-
let print_lint_groups = |lints: Vec<(&'static str, Vec<LintId>)>| {
888+
let print_lint_groups = |lints: Vec<(&'static str, Vec<LintId>)>, all_warnings| {
889+
println!(" {} sub-lints", padded("name"));
890+
println!(" {} ---------", padded("----"));
891+
892+
if all_warnings {
893+
println!(" {} all lints that are set to issue warnings", padded("warnings"));
894+
}
895+
892896
for (name, to) in lints {
893897
let name = name.to_lowercase().replace('_', "-");
894898
let desc = to
@@ -901,7 +905,7 @@ Available lint options:
901905
println!("\n");
902906
};
903907

904-
print_lint_groups(builtin_groups);
908+
print_lint_groups(builtin_groups, true);
905909

906910
match (loaded_plugins, plugin.len(), plugin_groups.len()) {
907911
(false, 0, _) | (false, _, 0) => {
@@ -916,7 +920,7 @@ Available lint options:
916920
}
917921
if g > 0 {
918922
println!("Lint groups provided by plugins loaded by this crate:\n");
919-
print_lint_groups(plugin_groups);
923+
print_lint_groups(plugin_groups, false);
920924
}
921925
}
922926
}

src/librustdoc/config.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,7 @@ impl Options {
353353
print_flag_list("-C", config::CG_OPTIONS);
354354
return Err(0);
355355
}
356-
let w_flags = matches.opt_strs("W");
357-
if w_flags.iter().any(|x| *x == "help") {
358-
print_flag_list("-W", config::DB_OPTIONS);
359-
return Err(0);
360-
}
356+
361357
if matches.opt_strs("passes") == ["list"] {
362358
println!("Available passes for running rustdoc:");
363359
for pass in passes::PASSES {
@@ -439,15 +435,19 @@ impl Options {
439435
return Err(0);
440436
}
441437

442-
if matches.free.is_empty() {
438+
let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);
439+
440+
let input = PathBuf::from(if describe_lints {
441+
"" // dummy, this won't be used
442+
} else if matches.free.is_empty() {
443443
diag.struct_err("missing file operand").emit();
444444
return Err(1);
445-
}
446-
if matches.free.len() > 1 {
445+
} else if matches.free.len() > 1 {
447446
diag.struct_err("too many file operands").emit();
448447
return Err(1);
449-
}
450-
let input = PathBuf::from(&matches.free[0]);
448+
} else {
449+
&matches.free[0]
450+
});
451451

452452
let libs = matches
453453
.opt_strs("L")
@@ -698,8 +698,6 @@ impl Options {
698698
let with_examples = matches.opt_strs("with-examples");
699699
let call_locations = crate::scrape_examples::load_call_locations(with_examples, &diag)?;
700700

701-
let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);
702-
703701
Ok(Options {
704702
input,
705703
proc_macro_crate,

src/librustdoc/lib.rs

+17-8
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ use std::env::{self, VarError};
7575
use std::io;
7676
use std::process;
7777

78-
use rustc_driver::{abort_on_err, describe_lints};
78+
use rustc_driver::abort_on_err;
7979
use rustc_errors::ErrorGuaranteed;
8080
use rustc_interface::interface;
8181
use rustc_middle::ty::TyCtxt;
@@ -770,15 +770,24 @@ fn main_options(options: config::Options) -> MainResult {
770770
let config = core::create_config(options);
771771

772772
interface::create_compiler_and_run(config, |compiler| {
773-
compiler.enter(|queries| {
774-
let sess = compiler.session();
773+
let sess = compiler.session();
775774

776-
if sess.opts.describe_lints {
777-
let (_, lint_store) = &*queries.register_plugins()?.peek();
778-
describe_lints(sess, lint_store, true);
779-
return Ok(());
780-
}
775+
if sess.opts.describe_lints {
776+
let mut lint_store = rustc_lint::new_lint_store(
777+
sess.opts.debugging_opts.no_interleave_lints,
778+
sess.unstable_options(),
779+
);
780+
let registered_lints = if let Some(register_lints) = compiler.register_lints() {
781+
register_lints(sess, &mut lint_store);
782+
true
783+
} else {
784+
false
785+
};
786+
rustc_driver::describe_lints(sess, &lint_store, registered_lints);
787+
return Ok(());
788+
}
781789

790+
compiler.enter(|queries| {
782791
// We need to hold on to the complete resolver, so we cause everything to be
783792
// cloned for the analysis passes to use. Suboptimal, but necessary in the
784793
// current architecture.

src/test/run-make/issue-88756-opt-help/Makefile

-4
This file was deleted.

src/test/run-make/issue-88756-opt-help/README.md

-1
This file was deleted.

0 commit comments

Comments
 (0)