Skip to content

ilog(2) -> ilog2() and ilog(10) -> ilog10 #15084

Closed as duplicate of#12894
Closed as duplicate of#12894
@tgross35

Description

@tgross35

What it does

If calls to ilog or checked_ilog are made with a known constant 2 or 10, suggest replacing them with the fixed-base versions ilog2 or ilog10.

Advantage

The fixed-base versions produce more performant code https://rust.godbolt.org/z/ffjx1Gjh7

Drawbacks

No response

Example

let a = x.ilog(2)
let b = x.ilog(10);
let c = x.checked_ilog(2);
let d = x.checked_ilog(10);

Could be written as:

let a = x.ilog2()
let b = x.ilog10();
let c = x.checked_ilog2();
let d = x.checked_ilog10();

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