Skip to main content

Lint clippy::bool_to_int_with_if

warning clippy::bool_to_int_with_if §

boolean to int conversion using if

tests/integration.rs:273:13

Clippy · Category: pedantic · cargo-clippy-html

Official Clippy documentation

Targets (1)
  • integration (test)

Primary: tests/integration.rs:273:13

            if html.contains("id=\"back\"") { 0 } else { 1 }

note: `!html.contains("id=\"back\"") as usize` or `(!html.contains("id=\"back\"")).into()` can also be valid options

help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#bool_to_int_with_if

note: `-W clippy::bool-to-int-with-if` implied by `-W clippy::pedantic`

help: to override `-W clippy::pedantic` add `#[allow(clippy::bool_to_int_with_if)]`

help: replace with from

Suggestion: replace with from

MachineApplicable

--- "a/tests/integration.rs"
+++ "b/tests/integration.rs"
@@ -270,7 +270,7 @@
                     .unwrap()
             )
             .count(),
-            if html.contains("id=\"back\"") { 0 } else { 1 }
+            usize::from(!html.contains("id=\"back\""))
         );
         assert!(
             doc.select(&Selector::parse("body[data-report-root]").unwrap())
Rendered diagnostic (text)
warning: boolean to int conversion using if
   --> tests/integration.rs:273:13
    |
273 |             if html.contains("id=\"back\"") { 0 } else { 1 }
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with from: `usize::from(!html.contains("id=\"back\""))`
    |
    = note: `!html.contains("id=\"back\"") as usize` or `(!html.contains("id=\"back\"")).into()` can also be valid options
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#bool_to_int_with_if
    = note: `-W clippy::bool-to-int-with-if` implied by `-W clippy::pedantic`
    = help: to override `-W clippy::pedantic` add `#[allow(clippy::bool_to_int_with_if)]`