Skip to content

new lint: find length comparisons after access by index in ANDded if-chains #5785

Open
@matthiaskrgr

Description

@matthiaskrgr

What it does

Check for code like

fn a(v1: Vec<_>, v2: Vec<_>, x: usize) {
  if v1[x] == v2[x] &&
     v1.len() == v2.len() {}
}

The length-check is probably intended to guard against index-out-of-bounds access however it was (most likely mistakenly) placed AFTER the access by index. It should be at the front.

Categories (optional)

  • Kind: correctness

Inspired by #5780 and #5784

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions