about summary refs log tree commit diff
path: root/src/librustdoc/lint.rs
diff options
context:
space:
mode:
authorAlexis Bourget <alexis.bourget@gmail.com>2020-12-28 23:07:20 +0100
committerJoshua Nelson <jyn514@gmail.com>2021-05-17 21:31:01 -0400
commitb574c67b93fbe0fc1194865441a1fa596b8922f1 (patch)
tree51b0a7287094c0fe279a339528aa9b514d0962a7 /src/librustdoc/lint.rs
parent3e99439f4dacc8ba0d2ca48d221694362d587927 (diff)
downloadrust-b574c67b93fbe0fc1194865441a1fa596b8922f1.tar.gz
rust-b574c67b93fbe0fc1194865441a1fa596b8922f1.zip
New rustdoc lint to respect -Dwarnings correctly
This adds a new lint to `rustc` that is used in rustdoc when a code
block is empty or cannot be parsed as valid Rust code.

Previously this was unconditionally a warning. As such some
documentation comments were (unknowingly) abusing this to pass despite
the `-Dwarnings` used when compiling `rustc`, this should not be the
case anymore.
Diffstat (limited to 'src/librustdoc/lint.rs')
-rw-r--r--src/librustdoc/lint.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/librustdoc/lint.rs b/src/librustdoc/lint.rs
index 1b79811d4b0..597efed56e1 100644
--- a/src/librustdoc/lint.rs
+++ b/src/librustdoc/lint.rs
@@ -157,6 +157,18 @@ declare_rustdoc_lint! {
     "detects URLs that are not hyperlinks"
 }
 
+declare_rustdoc_lint! {
+   /// The `invalid_rust_codeblock` lint detects Rust code blocks in
+   /// documentation examples that are invalid (e.g. empty, not parsable as
+   /// Rust code). This is a `rustdoc` only lint, see the documentation in the
+   /// [rustdoc book].
+   ///
+   /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_rust_codeblock
+   INVALID_RUST_CODEBLOCK,
+   Warn,
+   "codeblock could not be parsed as valid Rust or is empty"
+}
+
 crate static RUSTDOC_LINTS: Lazy<Vec<&'static Lint>> = Lazy::new(|| {
     vec![
         BROKEN_INTRA_DOC_LINKS,
@@ -164,6 +176,7 @@ crate static RUSTDOC_LINTS: Lazy<Vec<&'static Lint>> = Lazy::new(|| {
         MISSING_DOC_CODE_EXAMPLES,
         PRIVATE_DOC_TESTS,
         INVALID_CODEBLOCK_ATTRIBUTES,
+        INVALID_RUST_CODEBLOCK,
         INVALID_HTML_TAGS,
         BARE_URLS,
         MISSING_CRATE_LEVEL_DOCS,