Skip to content

[rustdoc] Suggest trailing \ instead of two spaces for hard line break #12163

@Marcono1234

Description

@Marcono1234

What it does

When a rustdoc comment contains two trailing spaces for a Markdown hard line break, the lint should suggest using a trailing backslash (\) instead.

rustdoc uses CommonMark, and it allows using \ for hard line breaks, see the specification.

Advantage

A trailing \ makes the intention for a hard line break clearer than two trailing spaces, which can be difficult to notice in Git diffs, and might be removed accidentally during refactoring.

Drawbacks

  • The choice whether to use two spaces or a \ is subjective
    (this could be solved by adding the lint to clippy::pedantic)
  • If there is not actually a need for a hard line break (e.g. if a > ... follows), then the \ might be shown literally (CommonMark example)

Example

/// First line··
/// Second line
fn foo() {}

(· indicating a space)

Could be written as:

/// First line\
/// Second line
fn foo() {}

Metadata

Metadata

Assignees

Labels

A-lintArea: New lints

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions