-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Move unused_doc_comment lint to a later pass to after proc macro expansion #67838
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
Comments
@QuietMisdreavus has told me to cc @GuillaumeGomez |
Could you provide a code sample alongside please? |
@GuillaumeGomez here is a minimal example of spandoc in action https://github.com/yaahc/spandoc-example/blob/master/src/lib.rs#L1-L5 When I comment out the spandoc attribute and expand it you'll see that it generates a doc attribute and outputs the lint as expected.
and when I uncomment the spandoc attribute so that it transforms the doc attribute into a span you'll see that it does not have a doc attribute in the final output but it still produces the lint.
|
Split non macro portion of unused_doc_comment from macro part into two passes/lints ## Motivation This change is motivated by the needs of the [spandoc library](https://github.com/yaahc/spandoc). The specific use case is that my macro is removing doc comments when an attribute is applied to a fn with doc comments, but I would like the lint to still appear when I forget to add the `#[spandoc]` attribute to a fn, so I don't want to have to silence the lint globally. ## Approach This change splits the `unused _doc_comment` lint into two lints, `unused_macro_doc_comment` and `unused_doc_comment`. The non macro portion is moved into an `early_lint_pass` rather than a pre_expansion_pass. This allows proc macros to silence `unused_doc_comment` warnings by either adding an attribute to silence it or by removing the doc comment before the early_pass runs. The `unused_macro_doc_comment` lint however will still be impossible for proc-macros to silence, but the only alternative that I can see is to remove this lint entirely, which I don't think is acceptable / is a decision I'm not comfortable making personally, so instead I opted to split the macro portion of the check into a separate lint so that it can be silenced globally with an attribute if necessary without needing to globally silence the `unused_doc_comment` lint as well, which is still desireable. fixes #67838
I'm currently writing a crate where I'd like to use doc comments as attributes for a proc macro that generates context directives for errors and log messages via
tracing
.https://github.com/yaahc/spandoc/blob/master/src/lib.rs
I had originally assumed that if my proc macro stripped out the doc attribute after converting it to a span then the compiler would not lint on the doc comments that actually got used as code, but when I tested this it still lints which implies to me that the unused doc comment lint happens in an earlier pass than proc-macro expansion does.
I'd like to be able to avoid using
#[allow(unused_doc_comments)]
on either the whole function or file because I want the lints to help me find doc comments that I add, expecting them to turn into spans, but which my proc macro does not handle and therefore leaves in as doc comments.The text was updated successfully, but these errors were encountered: