Skip to content

New lint: Suggest using line doc comments for doc tests instead of doc block comments #8465

@Enet4

Description

@Enet4

What it does

This lint identifies the presence of a doc-test inside a doc block comment, and recommends using doc line comments instead.


This idea came about when I was running cargo test and to my surprise, my project had a doc-test which was ignored but suddenly became visible in the current beta toolchain (Enet4/dicom-rs#223). With this lint, one would have detected that the doc-test might not have been interpreted as such. If deemed sound, I can try to get some time to work on its implementation. I am not sure how well this would align with the component release cycle, since this lint is only useful if it can be combined with previous versions of the compiler.

Lint Name

doctest_in_block_comment

Category

suspicious

Advantage

Due to a regression in the compiler, leading * characters may be interpreted as being part of the actual comment text. This in turn makes doc-tests not be recognised as such, leading to ignored tests without any warning. By using doc line comments consistently, stumbling upon this regression is prevented entirely.

Drawbacks

This lint would be no longer needed once the compiler is patched (starting from version v1.60.0) and there is no interest within the project in supporting versions of the compiler with this regression.

Example

/** Foos a bar.
 *
 * # Example
 * ```
 * foo(5);
 * ```
 */
fn foo(bar: u32) {}

Could be written as:

/// Foos a bar.
///
/// # Example
/// ```
/// foo(5);
/// ```
fn foo(bar: u32) {}

Metadata

Metadata

Assignees

No one assigned

    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