Skip to content

Commit e00893b

Browse files
authored
Rollup merge of #83895 - eggyal:issue-83883, r=jyn514
Add listing of lints (eg via `-W help`) to rustdoc Fixes #83883 r? `@jyn514`
2 parents 93b506c + 4d23c8e commit e00893b

File tree

5 files changed

+43
-4
lines changed

5 files changed

+43
-4
lines changed

compiler/rustc_driver/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,8 @@ the command line flag directly.
845845
);
846846
}
847847

848-
fn describe_lints(sess: &Session, lint_store: &LintStore, loaded_plugins: bool) {
848+
/// Write to stdout lint command options, together with a list of all available lints
849+
pub fn describe_lints(sess: &Session, lint_store: &LintStore, loaded_plugins: bool) {
849850
println!(
850851
"
851852
Available lint options:

src/librustdoc/config.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ crate struct Options {
9797
crate maybe_sysroot: Option<PathBuf>,
9898
/// Lint information passed over the command-line.
9999
crate lint_opts: Vec<(String, Level)>,
100-
/// Whether to ask rustc to describe the lints it knows. Practically speaking, this will not be
101-
/// used, since we abort if we have no input file, but it's included for completeness.
100+
/// Whether to ask rustc to describe the lints it knows.
102101
crate describe_lints: bool,
103102
/// What level to cap lints at.
104103
crate lint_cap: Option<Level>,

src/librustdoc/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ use std::default::Default;
7474
use std::env;
7575
use std::process;
7676

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

708+
if sess.opts.describe_lints {
709+
let (_, lint_store) = &*queries.register_plugins()?.peek();
710+
describe_lints(sess, lint_store, true);
711+
return Ok(());
712+
}
713+
708714
// We need to hold on to the complete resolver, so we cause everything to be
709715
// cloned for the analysis passes to use. Suboptimal, but necessary in the
710716
// current architecture.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// compile-flags: -W help
2+
// check-pass
3+
//
4+
// ignore-tidy-linelength
5+
//
6+
// normalize-stdout-test: "( +name default meaning\n +---- ------- -------\n)?( *[[:word:]:-]+ (allow |warn |deny |forbid ) [^\n]+\n)+" -> " $$NAMES $$LEVELS $$MEANINGS"
7+
// normalize-stdout-test: " +name sub-lints\n +---- ---------\n( *[[:word:]:-]+ [^\n]+\n)+" -> " $$NAMES $$SUB_LINTS"
8+
// normalize-stdout-test: " +rustdoc::all( (rustdoc::[[:word:]-]+, )*rustdoc::[[:word:]-]+)?" -> " rustdoc::all $$GROUPS$4"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Available lint options:
3+
-W <foo> Warn about <foo>
4+
-A <foo> Allow <foo>
5+
-D <foo> Deny <foo>
6+
-F <foo> Forbid <foo> (deny <foo> and all attempts to override)
7+
8+
9+
Lint checks provided by rustc:
10+
11+
$NAMES $LEVELS $MEANINGS
12+
13+
Lint groups provided by rustc:
14+
15+
$NAMES $SUB_LINTS
16+
17+
Lint checks provided by plugins loaded by this crate:
18+
19+
$NAMES $LEVELS $MEANINGS
20+
21+
Lint groups provided by plugins loaded by this crate:
22+
23+
rustdoc::all $GROUPS
24+
25+

0 commit comments

Comments
 (0)