Skip to content

indexing_slicing ignores match for length #17399

Description

@eirnym

Summary

lint ignores context of match slice.len(). Sister of #17398, reported one per lint.

Lint Name

indexing_slicing

Reproducer

I tried this code:

// supported: &[u8] is a function parameter, value from enum variant or provided in any other way
// to compile this code u8 can be replaced with anything implementing Display, or Debug (in that case add `:?` to format string)

match supported.len() {
    0 => {}
    1 => println!("{}", supported[0]),
    _ => println!("{} or {}", supported[0], supported[1]),
}

I saw this happen:

supported[0]
supported[0], supported[1]

indexing may panic

I expected to see this happen:
as `usize is not negative and value 0 was explicitly checked, lint should never fire.

Version

rustc 1.96.0 (ac68faa20 2026-05-25)
binary: rustc
commit-hash: ac68faa20c58cbccd01ee7208bf3b6e93a7d7f96
commit-date: 2026-05-25
host: aarch64-apple-darwin
release: 1.96.0
LLVM version: 22.1.2

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

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions