make never_loop applicability more flexible

This commit is contained in:
lapla-cogito 2025-02-12 22:25:58 +09:00
parent 649cef0e81
commit 90dbc5bf94
No known key found for this signature in database
GPG key ID: A173204876C41CCC
6 changed files with 193 additions and 5 deletions

View file

@ -0,0 +1,35 @@
error: this loop never actually loops
--> tests/ui/never_loop_fixable.rs:4:5
|
LL | / for i in [1, 2, 3].iter() {
LL | |
LL | | return;
LL | | }
| |_____^
|
= note: `#[deny(clippy::never_loop)]` on by default
help: if you need the first element of the iterator, try writing
|
LL - for i in [1, 2, 3].iter() {
LL + if let Some(i) = [1, 2, 3].iter().next() {
|
error: this loop never actually loops
--> tests/ui/never_loop_fixable.rs:11:5
|
LL | / for i in [1, 2, 3].iter() {
LL | |
LL | | return;
LL | | loop {
... |
LL | | }
| |_____^
|
help: if you need the first element of the iterator, try writing
|
LL - for i in [1, 2, 3].iter() {
LL + if let Some(i) = [1, 2, 3].iter().next() {
|
error: aborting due to 2 previous errors