-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
needless_doctest_main yields false positive with proc macros #4698
Comments
Okay this was a bit more annoying than I thought. The fact that I had the issue on crate level documentation prevented me from using In the end I found out that the check is a rather simple one: rust-clippy/clippy_lints/src/doc.rs Lines 347 to 351 in 850ad52
My workaround involves turning the main function into Edit: I wanted to document this in the doctest itself so I wouldn't wonder why I'd include the |
Yeah the check is at the moment just text-based. And detecting proc macros that expand to items is somewhat harder. A simple trick that would work is
|
Use syn in needless_doctest_main lint changelog: none This fixes #4698 by only linting non-empty `fn main()`s. This is not a perfect solution, but I don't want to omit linting if any macro call or attribute is detected, as that would result in many false negatives.
Clippy version: 0.0.212 (e979eb4 2019-10-17)
Clippy warns that the
fn main() {}
is not needed in the following doctest:https://github.com/Rantanen/intercom/blob/45837a4d77c340c9cb8cf45142843198a80a82b6/intercom/src/lib.rs#L12-L36
However removing that will end up with doctest wrapping the whole thing in a function, which results in the
com_library!(Calculator);
becoming a statement - something that is not allowed for (at least that) proc macro.I feel like this is enough of a niche case that there's no real need to fix it. A note could be added to the Known problems section of the lint.
The text was updated successfully, but these errors were encountered: