Skip to content

List item in doc comment starting with escaped [ makes clippy calculate indent wrong #13705

@maia-s

Description

@maia-s

Summary

If a list item in a doc comment starts with \[ (to stop rustdoc from making a link), clippy calculates the expected indent for the rest of the lines of the list item incorrecly, suggesting to add additional indentation. A \] triggers this bug also, but e.g. \x doesn't.

This is both a false positive and a false negative bc clippy expects the wrong indentation

Playground

Reproducer

I tried this code:

/// - \[text in square brackets\] with a long following description
///   that goes over multiple lines
pub fn item() {}

I expected to see this happen:
No warning

Instead, this happened:
Clippy warns:

warning: doc list item without indentation
 --> src/lib.rs:2:5
  |
2 | ///   that goes over multiple lines
  |     ^^
  |
  = help: if this is supposed to be its own paragraph, add a blank line
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation
  = note: `#[warn(clippy::doc_lazy_continuation)]` on by default
help: indent this line
  |
2 | ///    that goes over multiple lines
  |       +

warning: `playground` (lib) generated 1 warning

Version

rustc 1.84.0-nightly (798fb83f7 2024-10-16)
binary: rustc
commit-hash: 798fb83f7d24e31b16acca113496f39ff168c143
commit-date: 2024-10-16
host: aarch64-apple-darwin
release: 1.84.0-nightly
LLVM version: 19.1.1

Additional Labels

@rustbot label +I-false-positive +I-false-negative

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions