热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

let_unit_valuefalsewarningonfor_instd::sync::mpsc::Receiver::iter()

Playgroundexamplewiththemainpointbeingthis:

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.

1
let_unit_value

related found:


  • 1502 in the context of
    1
    let _: () = ...

    but not in for loop



  • 164 mentions in context of derives

My real use case for using

1
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.

1
std::thread::Thread

might even provide a better way for this via

1
park()

and

1
unpark()

.

该提问来源于开源项目: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




1
if_let_chain

?

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

1
if_let_chain

were removed, so we don't have to hope dogfood will catch it but have an explicit test in the suite.


   



推荐阅读
author-avatar
书友40416624
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有