rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.48k stars 1.55k forks source link

Unneeded `rust` as language in `rustdoc`'s documentation examples #13604

Open ojeda opened 4 weeks ago

ojeda commented 4 weeks ago

What it does

In a documentation example, when processed by rustdoc, it is strictly equivalent to write rust or not (https://doc.rust-lang.org/rustdoc/write-documentation/documentation-tests.html).

Thus it would be nice to have a lint that suggest the removal of the unneeded rust as language for the example.

Some projects may prefer the opposite, i.e. always writing rust, but consistency is typically an improvement.

Advantage

Drawbacks

Example

/// ```rust
/// let x = 5;
/// ```

Could be written as:

/// ```
/// let x = 5;
/// ```
GnomedDev commented 4 weeks ago

Should this be a part of clippy? This seems like a better fit for a rustdoc warning, as it has all the markdown parsing code already.

ojeda commented 4 weeks ago

Yeah, that may be right, I wasn't sure where to place it (there are other doc-related lints in Clippy already and perhaps rustdoc treats "stylistic diagnostics" like rustc, i.e. leaves those up to Clippy and other tools).

Cc @GuillaumeGomez

GuillaumeGomez commented 4 weeks ago

I think it's actually a better idea to put it into clippy as a style lint because it's completely ok to add rust marker on a codeblock, even if useless in most cases.