rust-lang / rust-lang/rust-clippy

tabs_in_doc_comments: Clippy flags tab-indented code in doc tests

Open
#12,425 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-positive
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

The tabs_in_doc_comments complains about tab-indented doctests.

Running cargo doc generates nice-looking and correctly-indented documentation when using tabs in this way, so I see no reason for Clippy to emit a lint.

Note that rustfmt doesn't change the formatting/indentation of doctests like this regardless of whether hard_tabs = true is set in .rustfmt.toml.

Lint Name

tabs_in_doc_comments

Reproducer

I tried this code:

/// ```
/// fn testing() {
/// 	println!("this line is tab-indented")
/// }
/// ```
pub fn foo() {
    println!("Hello, world")
}

I saw this happen:

    Checking clippy-repro v1.4.4 (/home/user/fend/clippy-repro)
warning: using tabs in doc comments is not recommended
 --> clippy-repro/src/lib.rs:3:5
  |
3 | ///     println!("this line is tab-indented")
  |     ^^^^ help: consider using four spaces per tab
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments
  = note: `#[warn(clippy::tabs_in_doc_comments)]` on by default

warning: `clippy-repro` (lib) generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s

I expected to see this happen:
Clippy should not have linted that line.

Version
rustc 1.75.0 (82e1608df 2023-12-21)
binary: rustc
commit-hash: 82e1608dfa6e0b5569232559e3d385fea5a93112
commit-date: 2023-12-21
host: x86_64-unknown-linux-gnu
release: 1.75.0
LLVM version: 17.0.6
Additional Labels

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the tabs_in_doc_comments lint and the provided doctest reproducer, then compare its behavior with cargo doc and rustfmt's handling of doctest indentation. Done means tab-indented code inside the documented doctest no longer triggers this lint, while the reported reproduction can still be checked.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.