about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2021-04-06 17:42:31 +0200
committerGitHub <noreply@github.com>2021-04-06 17:42:31 +0200
commite00893b715ee8142123d8eb2c39050a89bae0e63 (patch)
tree0fabcc903bf9865ffa8a37a7097a49ed5a028ecb
parent93b506c6fad803dade4872ef3e1d9cef9e7afd15 (diff)
parent4d23c8e9a162a91c4e25f75285353be938ea1f25 (diff)
downloadrust-e00893b715ee8142123d8eb2c39050a89bae0e63.tar.gz
rust-e00893b715ee8142123d8eb2c39050a89bae0e63.zip
Rollup merge of #83895 - eggyal:issue-83883, r=jyn514
Add listing of lints (eg via `-W help`) to rustdoc

Fixes #83883

r? `@jyn514`
-rw-r--r--compiler/rustc_driver/src/lib.rs3
-rw-r--r--src/librustdoc/config.rs3
-rw-r--r--src/librustdoc/lib.rs8
-rw-r--r--src/test/rustdoc-ui/issue-83883-describe-lints.rs8
-rw-r--r--src/test/rustdoc-ui/issue-83883-describe-lints.stdout25
5 files changed, 43 insertions, 4 deletions
diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs
index 3d26c94ec77..51699403a37 100644
--- a/compiler/rustc_driver/src/lib.rs
+++ b/compiler/rustc_driver/src/lib.rs
@@ -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:
diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs
index 821675bb9f5..c374e1f8d10 100644
--- a/src/librustdoc/config.rs
+++ b/src/librustdoc/config.rs
@@ -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>,
diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs
index fc5b7a4f4f3..241aa1f12df 100644
--- a/src/librustdoc/lib.rs
+++ b/src/librustdoc/lib.rs
@@ -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;
@@ -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.
diff --git a/src/test/rustdoc-ui/issue-83883-describe-lints.rs b/src/test/rustdoc-ui/issue-83883-describe-lints.rs
new file mode 100644
index 00000000000..a261b782d48
--- /dev/null
+++ b/src/test/rustdoc-ui/issue-83883-describe-lints.rs
@@ -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"
diff --git a/src/test/rustdoc-ui/issue-83883-describe-lints.stdout b/src/test/rustdoc-ui/issue-83883-describe-lints.stdout
new file mode 100644
index 00000000000..651faf5761f
--- /dev/null
+++ b/src/test/rustdoc-ui/issue-83883-describe-lints.stdout
@@ -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
+
+