Skip to content

repeat_once triggers when the parameter is a constant #7306

@frantisekhanzlikbl

Description

@frantisekhanzlikbl

Lint name: repeat_once

I tried this code:

fn main() {
    const REPEAT_COUNT: usize = 1;
    
    "x".repeat(REPEAT_COUNT);
}

I expected to see this happen: the lint is not triggered because if I used a constant as a parameter I probably intend to allow changing the constant value to something else in the future.

Instead, this happened: the lint triggers

Meta

  • cargo clippy -V: clippy 0.1.54 (1c6868a 2021-05-27
  • rustc -Vv:
    rustc 1.54.0-nightly (1c6868aa2 2021-05-27)
    binary: rustc
    commit-hash: 1c6868aa21981b37cbd3fc95828ee3b0ac22d494
    commit-date: 2021-05-27
    host: x86_64-unknown-linux-gnu
    release: 1.54.0-nightly
    LLVM version: 12.0.1
    

Metadata

Metadata

Assignees

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