rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

New Lint: disallowed_macro

Open JamesHinshelwood opened this issue 3 years ago • 5 comments

What it does

Disallows certain macros, as defined in clippy.toml. Equivalent to the disallowed_method lint, but for macros instead of methods.

Drawbacks

It may be cleaner to add support for macros to the existing disallowed_method lint.

Example

# clippy.toml

disallowed-macros = ["eyre::anyhow"]
...
let f = eyre::anyhow!("foobar");
...

results in a lint.

JamesHinshelwood avatar Oct 08 '21 18:10 JamesHinshelwood

@rustbot claim

aDotInTheVoid avatar Oct 08 '21 23:10 aDotInTheVoid

I can't figure out how to do this. With an EarlyLintPass the macro's have been resolved, but LateLintPass is after theyve been expanded, so I'm not sure if this is possible.

LMK if I've missed anything, and anyone wants to try this you might find my attempt usefull

aDotInTheVoid avatar Oct 10 '21 22:10 aDotInTheVoid

@aDotInTheVoid This should be possible with EarlyLintPass. The macros are expanded either way. You basically are just looking at the Span (like expr.span) to see if it is from an expanded macro. Here is an example.

camsteffen avatar Oct 12 '21 13:10 camsteffen

I would like to give this a go @rustbot claim

JamesHinshelwood avatar Oct 13 '21 19:10 JamesHinshelwood

Hi, apologies. Life has got in the way and I don't think I'll be able to work on this soon. Will unclaim in case someone else wants to.

@rustbot release-assignment

JamesHinshelwood avatar Jan 10 '22 09:01 JamesHinshelwood