-
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
redundant_closure_call false positive in macros #1553
Comments
I've ran into the same problem. I use a closure in a macro to work around macro hygiene and pass variables to an expression provided by the macro caller.
|
I think it would be fine to simply not trigger the lint inside macros. Note that you can write this without closures, by passing in the names of |
Hit this right now. Yes the macro could be rewritten to do it differently but I believe that passing a closure to macro is the most readable way to write it. This problem can be bypassed by writing |
So would this be something like: macro_rules! mymacro {
( $s:ident, $d:ident, $fix:expr ) => {
…
for ($s, $d) in src.iter().zip(dst.iter_mut()) {
$fix;
}
…
};
} where $fix (which as a closure might have been
I agree, this: mymacro!(..., (|s, d| s + d)) is easier to read than: mymacro!(..., s, d, s + d) (especially as the
This worked for me, except because |
@jpmckinney That's not the only way to refactor the macro. It could be rewritten to (scalably) take |
@kupiakos note that if you rewrite the macro to always take closure syntax then you can't pass in function pointers. Allowing any callable expression is best and the lint should be fixed. |
Fixed FP in `redundant_closure_call` when closures are passed to macros There are cases where the closure call is needed in some macros, this in particular occurs when the closure has parameters. To handle this case, we allow the lint when there are no parameters in the closure, or the closure is outside a macro invocation. fixes: #11274 #1553 changelog: FP: [`redundant_closure_call`] when closures with parameters are passed in macros.
Fixed through #12082 |
Is there a better way to delegate the body of a method to a parameter?
The text was updated successfully, but these errors were encountered: