Skip to content

redundant-clone: doesn't see redundant clone #16096

@Paladynee

Description

@Paladynee

Summary

redundant-clone doesn't work through match arms or something

Reproducer

Code:

pub fn try_from_bytes(bytes: &[u8]) -> Option<Vec<Vec<u8>>> {
    let mut pipeline = Vec::new();
    let mut index = 0;
    while index < bytes.len() {
        let c = bytes[index];
        match c {
            0 => {
                let algo = vec![];
                pipeline.push(algo.clone());
            }
            1 => {
                let algo = vec![];
                pipeline.push(algo.clone());
                return Some(pipeline);
            }
            _ => {}
        }
        index += 1;
    }

    None
}

this is as small as i could get it, the clone in the 0 => { match arm isn't caught, while the one in the 1 => { arm does

Current output:
one of the clones aren't detected

Desired output:
both clones are detected

Version

rustc 1.93.0-nightly (2286e5d22 2025-11-13)
binary: rustc
commit-hash: 2286e5d224b3413484cf4f398a9f078487e7b49d
commit-date: 2025-11-13
host: x86_64-unknown-linux-gnu
release: 1.93.0-nightly
LLVM version: 21.1.5

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tL-nurseryLint: Currently in the nursery group

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions