manual_slice_fill: initializer must not reference the iterator

```rust
let mut tmp = vec![1, 2, 3];
for b in &mut tmp {
    *b = !*b;
}
```

must not suggest the invalid `tmp.fill(!*b)`.
This commit is contained in:
Samuel Tardieu 2025-02-10 18:05:11 +01:00
parent 35ad69c124
commit 44aa75fd2a
3 changed files with 18 additions and 0 deletions

View file

@ -76,6 +76,8 @@ pub(super) fn check<'tcx>(
&& local == pat.hir_id
&& !assignval.span.from_expansion()
&& switch_to_eager_eval(cx, assignval)
// `assignval` must not reference the iterator
&& !is_local_used(cx, assignval, local)
// The `fill` method cannot be used if the slice's element type does not implement the `Clone` trait.
&& let Some(clone_trait) = cx.tcx.lang_items().clone_trait()
&& implements_trait(cx, cx.typeck_results().expr_ty(recv), clone_trait, &[])