about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-10-26 20:56:23 +0000
committerbors <bors@rust-lang.org>2021-10-26 20:56:23 +0000
commit0d07ec127f0dfa60c21481efa8db19ac5c0462d5 (patch)
tree1a89913793b408a03ce56fbe3d9ea956cac89e22
parent075996efd788613af0e19c0a241a81b1584b4cd1 (diff)
parentdea940259e34a7a78f5006562bea5d74201c88b8 (diff)
downloadrust-0d07ec127f0dfa60c21481efa8db19ac5c0462d5.tar.gz
rust-0d07ec127f0dfa60c21481efa8db19ac5c0462d5.zip
Auto merge of #7887 - xFrednet:7172-hiding-hidden-lines-online, r=flip1995
Remove hidden code lines in Clippy's lint list

This PR removes code lines from Clippy's lint list, which would also be hidden, when generating docs with rustdoc.

"A picture is worth a thousand words"... and here are even two pictures:

**Before:**

![image](https://user-images.githubusercontent.com/17087237/138952314-676dd9e7-ee80-459e-b521-bc42d8d03517.png)

**After:**

![image](https://user-images.githubusercontent.com/17087237/138952684-4fef969d-6880-4434-a338-b1a5a45539f0.png)

---

changelog: none

r? `@camsteffen` (Since you implemented the code block filtering :upside_down_face: )
-rw-r--r--clippy_lints/src/utils/internal_lints/metadata_collector.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/clippy_lints/src/utils/internal_lints/metadata_collector.rs b/clippy_lints/src/utils/internal_lints/metadata_collector.rs
index 0d27874b7af..99cf4c1ed40 100644
--- a/clippy_lints/src/utils/internal_lints/metadata_collector.rs
+++ b/clippy_lints/src/utils/internal_lints/metadata_collector.rs
@@ -512,12 +512,21 @@ fn extract_attr_docs(cx: &LateContext<'_>, item: &Item<'_>) -> Option<String> {
     let mut lines = attrs.iter().filter_map(ast::Attribute::doc_str);
     let mut docs = String::from(&*lines.next()?.as_str());
     let mut in_code_block = false;
+    let mut is_code_block_rust = false;
     for line in lines {
-        docs.push('\n');
         let line = line.as_str();
         let line = &*line;
+
+        // Rustdoc hides code lines starting with `# ` and this removes them from Clippy's lint list :)
+        if is_code_block_rust && line.trim_start().starts_with("# ") {
+            continue;
+        }
+
+        // The line should be represented in the lint list, even if it's just an empty line
+        docs.push('\n');
         if let Some(info) = line.trim_start().strip_prefix("```") {
             in_code_block = !in_code_block;
+            is_code_block_rust = false;
             if in_code_block {
                 let lang = info
                     .trim()
@@ -528,6 +537,8 @@ fn extract_attr_docs(cx: &LateContext<'_>, item: &Item<'_>) -> Option<String> {
                     .unwrap_or("rust");
                 docs.push_str("```");
                 docs.push_str(lang);
+
+                is_code_block_rust = lang == "rust";
                 continue;
             }
         }