Skip to content

Commit

Permalink
Rollup merge of #98799 - jyn514:rustdoc-lint-help, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
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```
  • Loading branch information
RalfJung committed Jul 3, 2022
2 parents 87df0f1 + 17da4e0 commit ce76d73
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 422 deletions.
20 changes: 12 additions & 8 deletions compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,10 +849,10 @@ Available lint options:
};

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

let print_lints = |lints: Vec<&Lint>| {
println!(" {} {:7.7} {}", padded("name"), "default", "meaning");
println!(" {} {:7.7} {}", padded("----"), "-------", "-------");
for lint in lints {
let name = lint.name_lower().replace('_', "-");
println!(
Expand Down Expand Up @@ -884,11 +884,15 @@ Available lint options:
};

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

let print_lint_groups = |lints: Vec<(&'static str, Vec<LintId>)>| {
let print_lint_groups = |lints: Vec<(&'static str, Vec<LintId>)>, all_warnings| {
println!(" {} sub-lints", padded("name"));
println!(" {} ---------", padded("----"));

if all_warnings {
println!(" {} all lints that are set to issue warnings", padded("warnings"));
}

for (name, to) in lints {
let name = name.to_lowercase().replace('_', "-");
let desc = to
Expand All @@ -901,7 +905,7 @@ Available lint options:
println!("\n");
};

print_lint_groups(builtin_groups);
print_lint_groups(builtin_groups, true);

match (loaded_plugins, plugin.len(), plugin_groups.len()) {
(false, 0, _) | (false, _, 0) => {
Expand All @@ -916,7 +920,7 @@ Available lint options:
}
if g > 0 {
println!("Lint groups provided by plugins loaded by this crate:\n");
print_lint_groups(plugin_groups);
print_lint_groups(plugin_groups, false);
}
}
}
Expand Down
22 changes: 10 additions & 12 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,7 @@ impl Options {
print_flag_list("-C", config::CG_OPTIONS);
return Err(0);
}
let w_flags = matches.opt_strs("W");
if w_flags.iter().any(|x| *x == "help") {
print_flag_list("-W", config::DB_OPTIONS);
return Err(0);
}

if matches.opt_strs("passes") == ["list"] {
println!("Available passes for running rustdoc:");
for pass in passes::PASSES {
Expand Down Expand Up @@ -439,15 +435,19 @@ impl Options {
return Err(0);
}

if matches.free.is_empty() {
let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);

let input = PathBuf::from(if describe_lints {
"" // dummy, this won't be used
} else if matches.free.is_empty() {
diag.struct_err("missing file operand").emit();
return Err(1);
}
if matches.free.len() > 1 {
} else if matches.free.len() > 1 {
diag.struct_err("too many file operands").emit();
return Err(1);
}
let input = PathBuf::from(&matches.free[0]);
} else {
&matches.free[0]
});

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

let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);

Ok(Options {
input,
proc_macro_crate,
Expand Down
25 changes: 17 additions & 8 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ use std::env::{self, VarError};
use std::io;
use std::process;

use rustc_driver::{abort_on_err, describe_lints};
use rustc_driver::abort_on_err;
use rustc_errors::ErrorGuaranteed;
use rustc_interface::interface;
use rustc_middle::ty::TyCtxt;
Expand Down Expand Up @@ -770,15 +770,24 @@ fn main_options(options: config::Options) -> MainResult {
let config = core::create_config(options);

interface::create_compiler_and_run(config, |compiler| {
compiler.enter(|queries| {
let sess = compiler.session();
let sess = compiler.session();

if sess.opts.describe_lints {
let (_, lint_store) = &*queries.register_plugins()?.peek();
describe_lints(sess, lint_store, true);
return Ok(());
}
if sess.opts.describe_lints {
let mut lint_store = rustc_lint::new_lint_store(
sess.opts.debugging_opts.no_interleave_lints,
sess.unstable_options(),
);
let registered_lints = if let Some(register_lints) = compiler.register_lints() {
register_lints(sess, &mut lint_store);
true
} else {
false
};
rustc_driver::describe_lints(sess, &lint_store, registered_lints);
return Ok(());
}

compiler.enter(|queries| {
// We need to hold on to the complete resolver, so we cause everything to be
// cloned for the analysis passes to use. Suboptimal, but necessary in the
// current architecture.
Expand Down
4 changes: 0 additions & 4 deletions src/test/run-make/issue-88756-opt-help/Makefile

This file was deleted.

1 change: 0 additions & 1 deletion src/test/run-make/issue-88756-opt-help/README.md

This file was deleted.

Loading

0 comments on commit ce76d73

Please sign in to comment.