Skip to content

manual_slice_fill shouldn't apply when the fill is variable #14189

@kornelski

Description

@kornelski

Summary

For fill() to be a replacement for a loop, the value being filled must not change inside the loop.

Lint Name

manual_slice_fill

Reproducer

    let mut tmp = vec![1];
    for b in &mut tmp {
        *b = !*b;
    }
manually filling a slice
…
^ help: try: `tmp.fill(!*b);`

Version

rustc 1.86.0-nightly (a9e7b3048 2025-02-07)
binary: rustc
commit-hash: a9e7b30487235621751cc628f170c0f15fb215c4
commit-date: 2025-02-07
host: aarch64-apple-darwin
release: 1.86.0-nightly
LLVM version: 19.1.7

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions