Skip to content

Commit dea9402

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

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

clippy_lints/src/utils/internal_lints/metadata_collector.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -512,12 +512,21 @@ 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;
529+
is_code_block_rust = false;
521530
if in_code_block {
522531
let lang = info
523532
.trim()
@@ -528,6 +537,8 @@ fn extract_attr_docs(cx: &LateContext<'_>, item: &Item<'_>) -> Option<String> {
528537
.unwrap_or("rust");
529538
docs.push_str("```");
530539
docs.push_str(lang);
540+
541+
is_code_block_rust = lang == "rust";
531542
continue;
532543
}
533544
}

0 commit comments

Comments
 (0)