Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Enet4 opened this issue Feb 23, 2022 · 0 comments
Labels
A-lint Area: New lints

Comments

@Enet4
Copy link
Contributor

Enet4 commented Feb 23, 2022

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) {}
@Enet4 Enet4 added the A-lint Area: New lints label Feb 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

No branches or pull requests

1 participant