-
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
let_unit_value false warning on for _ in std::sync::mpsc::Receiver::iter() #1964
Comments
Oh... this is inside the expansion of the for loop. Apparently |
Just to clarify, the following snippet does not trigger any warnings, even with let v = vec![0, 1, 2];
let mut count = 0;
for _ in &v {
count += 1;
}
assert_eq!(count, 3); I might be interested in taking a further look on why this happens and see if it's something I could possibly fix... |
The issue is with iterating over units: let v = vec![(), (), ()];
let mut count = 0;
for _ in v {
count += 1;
}
assert_eq!(count, 3);
Rustc removes Inside the expansion of the To debug this you can do one or multiple of the following
|
Ok.. I'll start looking how to integrate this into the test suite. I think it needs to be as an "ui-test", Interesting find: I accidentially reproduced the code sample you mentioned (with let v = vec![(), (), ()];
let mut count = 0;
for _ in &v { // <--
count += 1;
}
assert_eq!(count, 3); The above does not trigger a warning. With Thanks for your tips. I'll try continue looking... |
It does not trigger the warnings, because the |
Ah yes. :) It looks like modifying the utility
will remove the warning from my case. I concluded this by inspecting the I have no idea if this will match too much but nothing is caught by the existing test cases, at least running from linux. Any tips on how to continue from here? Should I package this diff as an PR or can you think of something getting broken by this change? |
It basically looks good to me. Can you add all that you learned about this as comments before each of the two
yes that would be great. Include some of the examples in this issue as unit tests to show that they aren't triggering. Also add an example that would have triggered if the first |
Playground example with the main point being this:
Todays playground and the clippy version I have installed (0.0.150) both report:
I don't think there is duplicate of this reported.
let_unit_value
related found:let _: () = ...
but not in for loopMy real use case for using
Receiver<()>
is to provide a way for a worker thread to sleep with notifications. I guess this could be implemented in other ways but this was a quick solution that seems to work.std::thread::Thread
might even provide a better way for this viapark()
andunpark()
.The text was updated successfully, but these errors were encountered: