-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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 Ability for Closure to Allow Argument But Never Use It #4077
Comments
You can write a closure with an argument it doesn't use, so that the compiler doesn't warn about it:
Names beginning with an underscore are exempt from unused-variable warnings. You can also write a closure with no arguments:
where
Is either of those what you're looking for? |
Awesome! |
No problem! It's always ok to ask questions like this on IRC, too (see https://github.com/mozilla/rust/wiki/Note-development-policy#Communication ). |
…ntinue`, recursively fixes: rust-lang#4077
…curisvely (rust-lang#13891) fixes: rust-lang#4077 Continuation of rust-lang#11546. r? @y21 if you don't mind? changelog: [`needless_continue`] lint if the last stmt in loop is `continue` recurisvely
I'm not sure how to phrase this properly, but basically I believe it'd be nice to see the following possible in rust.
A closure that takes in an argument, but never actually binds that argument to a name.
The reason being that in a loop, sometimes we don't actually need to know which iteration we are in. We just need to repeat a certain action for an arbitrary number of times.
For example,
Essentially, argument wise, the closure will treat its argument the same way as the following C/C++ function.
In C++, we could use the above function for something like this.
Alternatively, perhaps we could enhance the
loop
expression and allow it to take an argument to specify the number of iterations we want.For example,
The text was updated successfully, but these errors were encountered: