简体   繁体   中英

What optimizations does the Rust compiler make with `loop` versus `while true`?

除了可以推断loop体内设置的未初始化值这一事实之外,还有其他令人信服的理由存在loop吗?

Other than you state your intention, there is no difference. All loops are the same once normalization has happened in the compiler.

See an example of a loop in the Rust playground and the same example with a while true . The assembly generated is exactly the same. The compiler gives a warning for the while true -example to use loop instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM