Skip to content

Add listing of lints (eg via -W help) to rustdoc #83895

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

Merged
merged 1 commit into from
Apr 6, 2021
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
3 changes: 2 additions & 1 deletion compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,8 @@ the command line flag directly.
);
}

fn describe_lints(sess: &Session, lint_store: &LintStore, loaded_plugins: bool) {
/// Write to stdout lint command options, together with a list of all available lints
pub fn describe_lints(sess: &Session, lint_store: &LintStore, loaded_plugins: bool) {
println!(
"
Available lint options:
Expand Down
3 changes: 1 addition & 2 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ crate struct Options {
crate maybe_sysroot: Option<PathBuf>,
/// Lint information passed over the command-line.
crate lint_opts: Vec<(String, Level)>,
/// Whether to ask rustc to describe the lints it knows. Practically speaking, this will not be
/// used, since we abort if we have no input file, but it's included for completeness.
/// Whether to ask rustc to describe the lints it knows.
crate describe_lints: bool,
/// What level to cap lints at.
crate lint_cap: Option<Level>,
Expand Down
8 changes: 7 additions & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ use std::default::Default;
use std::env;
use std::process;

use rustc_driver::abort_on_err;
use rustc_driver::{abort_on_err, describe_lints};
use rustc_errors::ErrorReported;
use rustc_interface::interface;
use rustc_middle::ty::TyCtxt;
Expand Down Expand Up @@ -705,6 +705,12 @@ fn main_options(options: config::Options) -> MainResult {
compiler.enter(|queries| {
let sess = compiler.session();

if sess.opts.describe_lints {
let (_, lint_store) = &*queries.register_plugins()?.peek();
describe_lints(sess, lint_store, true);
return Ok(());
}

// 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
8 changes: 8 additions & 0 deletions src/test/rustdoc-ui/issue-83883-describe-lints.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// compile-flags: -W help
// check-pass
//
// ignore-tidy-linelength
//
// normalize-stdout-test: "( +name default meaning\n +---- ------- -------\n)?( *[[:word:]:-]+ (allow |warn |deny |forbid ) [^\n]+\n)+" -> " $$NAMES $$LEVELS $$MEANINGS"
// normalize-stdout-test: " +name sub-lints\n +---- ---------\n( *[[:word:]:-]+ [^\n]+\n)+" -> " $$NAMES $$SUB_LINTS"
// normalize-stdout-test: " +rustdoc::all( (rustdoc::[[:word:]-]+, )*rustdoc::[[:word:]-]+)?" -> " rustdoc::all $$GROUPS$4"
25 changes: 25 additions & 0 deletions src/test/rustdoc-ui/issue-83883-describe-lints.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Available lint options:
-W <foo> Warn about <foo>
-A <foo> Allow <foo>
-D <foo> Deny <foo>
-F <foo> Forbid <foo> (deny <foo> and all attempts to override)


Lint checks provided by rustc:

$NAMES $LEVELS $MEANINGS

Lint groups provided by rustc:

$NAMES $SUB_LINTS

Lint checks provided by plugins loaded by this crate:

$NAMES $LEVELS $MEANINGS

Lint groups provided by plugins loaded by this crate:

rustdoc::all $GROUPS