You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For Rust code blocks, and for code blocks in many other languages, it is very likely that extra indentation is not indented if it is applied across the entire contents of the code block, e.g. an extra space on all lines (or even just all non-empty lines).
Having said that, when/if rustfmt stabilizes formatting code blocks in documentation, this lint may not be needed anymore.
Possibly related, at least implementation-wise: #15023 and #15024.
Advantage
More consistency in docs.
Less time spent by reviewers.
Drawbacks
No response
Example
/// ```/// fn f() {}/// ```
Should be written as:
/// ```/// fn f() {}/// ```
The text was updated successfully, but these errors were encountered:
@ojeda small nitpick: I'd clarify that this is for code blocks inside of doc comments, in the title. That way it's easier to understand that this is not something that rustfmt already covers.
(I might just be me not used to the wording, but when I was reading this issue, I saw "code blocks" and I thought "but yeah, this is something rustfmt has had since forever")
BTW, has this need been talked about at the rustfmt repo / chat? It super feels to me like something under the sphere of rustfmt rather than clippy.
That being said, #13711 exists, so I bet this lint can easily be extended from that and then both can be deprecated after rustfmt addresses doc comment indentation
ojeda
changed the title
Detect extra "base indentation" in Rust code blocks
Detect extra "base indentation" in Rust code blocks in docs
Jun 10, 2025
I'd clarify that this is for code blocks inside of doc comments, in the title.
Done, thanks!
BTW, has this need been talked about at the rustfmt repo / chat?
No, I didn't talk about it with rustfmt (nor rustdoc, for that matter). I think it would be nice to have a way to ping them in this sort of cross-issues (e.g. see #14402 (comment) for another case), since it is convenient to open new lint ideas in a single place and then "redirect them" (to compiler, rustdoc or rustfmt) if needed.
It super feels to me like something under the sphere of rustfmt rather than clippy.
Yeah, I agree that rustfmt may want to cover this.
Uh oh!
There was an error while loading. Please reload this page.
What it does
For Rust code blocks, and for code blocks in many other languages, it is very likely that extra indentation is not indented if it is applied across the entire contents of the code block, e.g. an extra space on all lines (or even just all non-empty lines).
Having said that, when/if
rustfmt
stabilizes formatting code blocks in documentation, this lint may not be needed anymore.Possibly related, at least implementation-wise: #15023 and #15024.
Advantage
Drawbacks
No response
Example
Should be written as:
The text was updated successfully, but these errors were encountered: