-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Is it possible to disable a lint for all macro invocations? #11472
Comments
You can have it expand to #[allow(clippy::zero_prefixed_literal)]
{
(actual code)
} However, it's worth noting that this lint already checks if it's in an external macro (i.e., macro outside the current crate) and doesn't lint if so. So this will only come up for chrono in particular. |
The literals aren't coming from an expansion so it'd still be linted in other crates |
Thank you for the help, but as you say the literals are in the other crate. |
I don't think so, but there is a trick to get rid of an indentation level for the allow attribute. Since the tail expression of a block can have attributes you can do ($y:literal-$m:literal-$d:literal) => {{
#[allow(clippy::zero_prefixed_literal)]
match $crate::NaiveDate::from_ymd_opt($y, $m, $d) {
Some(d) => d,
None => panic!("invalid calendar date"),
}
}}; |
This is perfect, thank you very much! |
Description
Is there a way to suppress a lint (
zero_prefixed_literal
in my case) for all invocations of a macro?For chrono (chronotope/chrono#1270) I am trying to write macros that can be used as
But that generates warnings (https://github.com/chronotope/chrono/actions/runs/6119764599/job/16610345590?pr=1270)
I am looking for a solution that doesn't require users to disable the lint. Maybe it can be solved by adjusting the macro, I just don't know enough about this part of Rust yet.
Version
No response
Additional Labels
No response
The text was updated successfully, but these errors were encountered: