-
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
Add {debug_,}assert{,-eq,-ne} to utils/higher.rs #4694
Comments
This comment has been minimized.
This comment has been minimized.
Error: Label good-first-issue can only be set by Rust team members Please let |
Error: Label T-macros can only be set by Rust team members Please let |
How am I supposed to add good first issues, which contains whitespaces, to rustbot?
True. Intentional? |
@hellow554 I would like to pick this up if no one else is currently working on it. |
Sure, go ahead. If you like take a look at #4680 where this issue comes from. |
@vss96 did you have time to look into it? How are you going? Any progression so far? Any questions? Something you need a second opinion on? |
@vss96 Sorry, I was caught up in other things for the past week and couldn't put in the time that i wanted to. I was trying to make sense of this code block in higher.rs. I was also trying to execute dummy code with vec! to see how these cases were being handled. If you take something like assert!, it can either have a single argument (the value is either true or false and you expect it to be true) or two arguments where you equate lhs and rhs. I think the part that I find difficult is the syntax around this code (need some time to get used Expr). If you could give a high level overview on what's happening here, that would be great.
|
I think looking at the rust-clippy/clippy_lints/src/mutable_debug_assertion.rs Lines 56 to 102 in e2104d1
This function now has to be generalized, so that it returns the array of expressions. So for A great extension of this would be to also return the |
@flip1995 That helps. Thank you :) |
@vss96 would you mind me snatching the issue or are you planning to work on it? |
I am a little bit stuck and would appreciate some help. As a part of solving this, I want to add an utils function that checks if the expr/stmt is the exact macro expansion (that is, the macro expanded precisely to this expr), so we can match on the contents fearlessly. My approach right now is to compare outer ExpnId's of the expr and its parent. If they match, then the expansion is bigger than my expr. The problem is that a built-in macro's (format_args) expansion has exprs whose outer expansion is not format_args (its the calling macro, assert_eq). Their parent node's outer expansion, on the other hand, is format_args, I compare them and get a false positive. Is there a way to fix this or maybe there is a better way to do this (or this function already exists and I can't search). |
I don't think you have to check the IDs of the expansions, but just match on the exact expansion structure. The hir expansion has an Also when matching the exact expansion your matching on code that probably no one would write that way in real code. |
utils/higher.rs already contains an extraction for
vec![]
arguments.It would be nice to add more macros
assert!
assert_eq!
assert_ne!
debug_assert!
debug_assert_eq!
debug_assert_ne!
The text was updated successfully, but these errors were encountered: