Skip to content

Suggest casting bool to int instead of using if statement. #8131

Closed
@cwhakes

Description

@cwhakes

What it does

Instead of using an if statement to convert a bool to an int, this lint suggests using a coercion or a from() function.

Lint Name

bool_to_int_with_if

Category

style

Advantage

  • Makes code more concise
  • Makes this conversion more discoverable

Drawbacks

  • None

Example

if condition {
    1_i64
} else {
    0
}

Could be written as:

i64::from(condition)

or

condition as i64

Metadata

Metadata

Assignees

Labels

A-lintArea: New lintsgood first issueThese issues are a good way to get started with Clippy

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions