Skip to content

Wrong if_same_then_else lint error when having two different integer #11213

@YouKnow-sys

Description

@YouKnow-sys

Summary

if we call a trait method on two different integer type in a if else condition and specify the types like 0_u8, 0u16 and... this lint will give us a error about both if and else are the same, when they're not...

Lint Name

if_same_then_else

Reproducer

I tried this code:

let test = if true { 0_u16.is_power_of_two() } else { 0_u8.is_power_of_two() };

I saw this happen:

error: this `if` has identical blocks
  --> src.rs:44:28
   |
44 |         let test = if true { 0_u16.is_power_of_two() } else { 0_u8.is_power_of_two() };
   |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: same as this
  --> src.rs:44:61
   |
44 |         let test = if true { 0_u16.is_power_of_two() } else { 0_u8.is_power_of_two() };
   |                                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                           

I didn't expected to see any lint error here because I'm calling this trait method on two different type.

Version

rustc 1.71.0 (8ede3aae2 2023-07-12)
binary: rustc
commit-hash: 8ede3aae28fe6e4d52b38157d7bfe0d3bceef225
commit-date: 2023-07-12
host: x86_64-pc-windows-msvc
release: 1.71.0
LLVM version: 16.0.5

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    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