Skip to content

Commit 7f793aa

Browse files
committed
Remove hidden code lines in Clippy's lint list
1 parent 075996e commit 7f793aa

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

clippy_lints/src/utils/internal_lints/metadata_collector.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,18 @@ fn extract_attr_docs(cx: &LateContext<'_>, item: &Item<'_>) -> Option<String> {
512512
let mut lines = attrs.iter().filter_map(ast::Attribute::doc_str);
513513
let mut docs = String::from(&*lines.next()?.as_str());
514514
let mut in_code_block = false;
515+
let mut is_code_block_rust = false;
515516
for line in lines {
516-
docs.push('\n');
517517
let line = line.as_str();
518518
let line = &*line;
519+
520+
// Rustdoc hides code lines starting with `# ` and this removes them from Clippy's lint list :)
521+
if is_code_block_rust && line.trim_start().starts_with("# ") {
522+
continue;
523+
}
524+
525+
// The line should be represented in the lint list, even if it's just an empty line
526+
docs.push('\n');
519527
if let Some(info) = line.trim_start().strip_prefix("```") {
520528
in_code_block = !in_code_block;
521529
if in_code_block {
@@ -528,7 +536,11 @@ fn extract_attr_docs(cx: &LateContext<'_>, item: &Item<'_>) -> Option<String> {
528536
.unwrap_or("rust");
529537
docs.push_str("```");
530538
docs.push_str(lang);
539+
540+
is_code_block_rust = lang == "rust";
531541
continue;
542+
} else {
543+
is_code_block_rust = false;
532544
}
533545
}
534546
// This removes the leading space that the macro translation introduces

0 commit comments

Comments
 (0)