作者:书友40416624 | 来源:互联网 | 2023-09-01 19:25
Playground example with the main point being this:
1 2 3 4 5
| let rx: ::std::sync::mpsc::Receiver = rx;
for _ in rx.iter() {
// anything
} |
Todays playground and the clippy version I have installed (0.0.150) both report:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| warning: this let-binding has unit value. Consider omitting `let for _ in rx.iter() {
count += 1;
} =`
--> src/main.rs:10:9
|
10 | / for _ in rx.iter() {
11 | | count += 1;
12 | | }
| |_________^
|
= note: #[warn(let_unit_value)] on by default
= help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#let_unit_value
warning: this let-binding has unit value. Consider omitting `let _ =`
--> src/main.rs:10:9
|
10 | / for _ in rx.iter() {
11 | | count += 1;
12 | | }
| |_________^
|
= help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#let_unit_value |
I don't think there is duplicate of this reported.
related found:
1502 in the context of
but not in for loop
164 mentions in context of derives
My real use case for using
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.
might even provide a better way for this via
and
.
该提问来源于开源项目:rust-lang/rust-clippy
It basically looks good to me. Can you add all that you learned about this as comments before each of the two
?
Should I package this diff as an PR
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
were removed, so we don't have to hope dogfood will catch it but have an explicit test in the suite.