Skip to content

int_plus_one adversely affects codegen because of underflow #14365

Description

@ArhanChaudhary

Summary

int_plus_one can produce inefficient code because the - 1 is used for bounds checking optimizations. The way to address this is issue unclear, but this should at least be mentioned in documentation.

Reproducer

In short: https://godbolt.org/z/fabdj4TsE

Related issue: #9268

Version

rustc 1.85.0 (4d91de4e4 2025-02-17)
binary: rustc
commit-hash: 4d91de4e48198da2e33413efdcd9cd2cc0c46688
commit-date: 2025-02-17
host: x86_64-unknown-linux-gnu
release: 1.85.0
LLVM version: 19.1.7

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions