Auto merge of #13117 - GuillaumeGomez:fix-single_element_loop-suggestion, r=Alexendoo

Fix wrong suggestion for `single_element_loop` where parens were missing

Fixes https://github.com/rust-lang/rust-clippy/issues/12782.

changelog: Fix missing parens in `single_element_loop` suggestion
This commit is contained in:
bors 2024-07-18 12:53:59 +00:00
commit bc2feea519
4 changed files with 37 additions and 3 deletions

View file

@ -57,4 +57,12 @@ fn main() {
}
};
}
// Should lint with correct suggestion (issue #12782)
let res_void: Result<bool, bool> = Ok(true);
{
let (Ok(mut _x) | Err(mut _x)) = res_void;
let ptr: *const bool = std::ptr::null();
}
}

View file

@ -54,4 +54,11 @@ fn main() {
}
};
}
// Should lint with correct suggestion (issue #12782)
let res_void: Result<bool, bool> = Ok(true);
for (Ok(mut _x) | Err(mut _x)) in [res_void] {
let ptr: *const bool = std::ptr::null();
}
}

View file

@ -83,5 +83,21 @@ LL + };
LL + }
|
error: aborting due to 7 previous errors
error: for loop over a single element
--> tests/ui/single_element_loop.rs:61:5
|
LL | / for (Ok(mut _x) | Err(mut _x)) in [res_void] {
LL | | let ptr: *const bool = std::ptr::null();
LL | | }
| |_____^
|
help: try
|
LL ~ {
LL + let (Ok(mut _x) | Err(mut _x)) = res_void;
LL + let ptr: *const bool = std::ptr::null();
LL + }
|
error: aborting due to 8 previous errors