Skip to content
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

Fix bug in rustdoc -Whelp #98799

Merged
merged 1 commit into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 @@ -76,7 +76,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 @@ -771,15 +771,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
};
Comment on lines +777 to +786
Copy link
Member Author

@jyn514 jyn514 Jul 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can't just be register_plugins() because that ends up trying to parse the source file, which fails because it's an empty string. this code is taken from

if sopts.describe_lints {
let mut lint_store = rustc_lint::new_lint_store(
sopts.debugging_opts.no_interleave_lints,
compiler.session().unstable_options(),
);
let registered_lints =
if let Some(register_lints) = compiler.register_lints() {
register_lints(compiler.session(), &mut lint_store);
true
} else {
false
};
describe_lints(compiler.session(), &lint_store, registered_lints);
return;
}

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