Skip to content

ref_patterns shouldn't be triggered when sub slices are involved #16145

@c410-f3r

Description

@c410-f3r

The use of ref actually prevents a compilation error in the following scenario.

#![deny(clippy::ref_patterns)]

fn foo(bar: &[u8]) -> u8 {
    if let &[a, b, ref _rest @ .., c, d, e] = bar {
        a + b + c + d + e
    } else {
        0
    }
}

Of course, [a, b, _rest @ .., c, d, e] = bar is still possible but it is cumbersome to defer all those bytes.

#![deny(clippy::ref_patterns)]

fn foo(bar: &[u8]) -> u8 {
    if let [a, b, _rest @ .., c, d, e] = bar {
        *a + *b + *c + *d + *e
    } else {
        0
    }
}

In my particular use-case I deal with +30 individual bytes, which makes things even more cumbersome.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions