Skip to content

Commit e070784

Browse files
committed
Auto merge of rust-lang#13261 - antonilol:fix-doc-code-blocks, r=xFrednet
fix code blocks in doc comments inconsistently using 3 or 4 spaces of indentation The metadata collector script was treating the space lines all start with as indentation. This caused code block's triple backticks to get a space in front of it, like this: ``` ```rust ^ this space ``` Code after that that is indented with 4 spaces will only have 3 of those rendered. Example (taken from [here](https://rust-lang.github.io/rust-clippy/master/index.html#/missing_panics_doc)): ```rust ... pub fn divide_by(x: i32, y: i32) -> i32 { if y == 0 { // 3 spaces panic!("Cannot divide by 0") // 7 spaces ... ``` Also added 'compile_fail' alongside the other rustdoc directives (second code block [here](https://rust-lang.github.io/rust-clippy/master/index.html#/macro_metavars_in_unsafe) had no highlighting), fixed a doc comment using 'rs' instead of 'rust' and removed some spaces causing an extra missing space of indentation (see second code block [here](https://rust-lang.github.io/rust-clippy/master/index.html#/map_err_ignore)). changelog: none
2 parents 1984752 + d7f1252 commit e070784

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

clippy_lints/src/doc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ declare_clippy_lint! {
309309
/// ### Known problems
310310
/// Inner doc comments can only appear before items, so there are certain cases where the suggestion
311311
/// made by this lint is not valid code. For example:
312-
/// ```rs
312+
/// ```rust
313313
/// fn foo() {}
314314
/// ///!
315315
/// fn bar() {}

clippy_lints/src/methods/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2702,10 +2702,10 @@ declare_clippy_lint! {
27022702
/// }
27032703
/// })
27042704
/// }
2705-
/// ```
2705+
/// ```
27062706
///
2707-
/// After:
2708-
/// ```rust
2707+
/// After:
2708+
/// ```rust
27092709
/// use std::{fmt, num::ParseIntError};
27102710
///
27112711
/// #[derive(Debug)]

clippy_lints/src/utils/internal_lints/metadata_collector.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,10 +687,12 @@ fn cleanup_docs(docs_collection: &Vec<String>) -> String {
687687
.trim()
688688
.split(',')
689689
// remove rustdoc directives
690-
.find(|&s| !matches!(s, "" | "ignore" | "no_run" | "should_panic"))
690+
.find(|&s| !matches!(s, "" | "ignore" | "no_run" | "should_panic" | "compile_fail"))
691691
// if no language is present, fill in "rust"
692692
.unwrap_or("rust");
693-
let len_diff = line.len() - line.trim_start().len();
693+
let len_diff = line
694+
.strip_prefix(' ')
695+
.map_or(0, |line| line.len() - line.trim_start().len());
694696
if len_diff != 0 {
695697
// We put back the indentation.
696698
docs.push_str(&line[..len_diff]);

0 commit comments

Comments
 (0)