Skip to content

Commit 0d07ec1

Browse files
committed
Auto merge of rust-lang#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 🙃 )
2 parents 075996e + dea9402 commit 0d07ec1

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)