-
Notifications
You must be signed in to change notification settings - Fork 1.6k
False positive useless_vec when vec argument is used twice in a macro #11861
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
@rustbot claim |
After diving into this for a bit, I wasn't able to figure out how to implement a fix. Could someone with more experience come advise? Thanks. I know that clippy is run after macro expansion, and that during macro expansion, both the @rustbot label +E-help-wanted |
There might be a better way but maybe we could have a map in the lint pass that maps
Then, in In the example in the OP, we would first see the expression Another way I can think of would be to get the enclosing block/body/item/parent of the macro and run a visitor through it to look for duplicate |
@y21 Thanks for the detailed explanation on how to approach this. I have changed the lint to call By the way, I've pushed my code to my fork at commit 0f306ac |
Right, if lint emission gets delayed to |
this fixes issue rust-lang#11861 by adding an extra map to keep track of which spans are ok to lint
Summary
If a
Vec
is passed to a macro that uses its argument more than once and one usage could indeed be replaced with an array but the other could not, theuseless_vec
lint triggers a false positive.Link to the playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=e6a7db5f00b948def8a3a836f98ad071
Lint Name
useless_vec
Reproducer
I tried this code:
I saw this happen:
I expected to see this happen:
Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: