Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If-same-then-else bug for unequal const generic argument #8680

Closed
CurryPseudo opened this issue Apr 11, 2022 · 3 comments
Closed

If-same-then-else bug for unequal const generic argument #8680

CurryPseudo opened this issue Apr 11, 2022 · 3 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@CurryPseudo
Copy link

CurryPseudo commented Apr 11, 2022

Summary

Unequal const generic argument trigger if-same-then-else lint.

Lint Name

If-same-then-else

Reproducer

Given

pub struct Foo<const I: i32> {}
impl<const I: i32> Foo<I> {
    pub const Y: i32 = I;
}

pub fn bar<const A: i32, const B: i32>() {
    let i = 0;
    let a = if i > 1 { Foo::<A>::Y } else { Foo::<B>::Y };
    println!("{}", a);
}

Got

    Checking playground v0.1.0 (/root/playground)
error: this `if` has identical blocks
 --> src/lib.rs:8:22
  |
8 |     let a = if i > 1 { Foo::<A>::Y } else { Foo::<B>::Y };
  |                      ^^^^^^^^^^^^^^^
  |
  = note: `#[deny(clippy::if_same_then_else)]` on by default
note: same as this
 --> src/lib.rs:8:43
  |
8 |     let a = if i > 1 { Foo::<A>::Y } else { Foo::<B>::Y };
  |                                           ^^^^^^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_same_then_else

error: could not compile `playground` due to previous error
warning: build failed, waiting for other jobs to finish...
error: build failed

Version

rustc 1.60.0 (7737e0b5c 2022-04-04)
binary: rustc
commit-hash: 7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c
commit-date: 2022-04-04
host: x86_64-unknown-linux-gnu
release: 1.60.0
LLVM version: 14.0.0

Additional Labels

No response

@CurryPseudo CurryPseudo added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Apr 11, 2022
@J-ZhengLi
Copy link
Member

@rustbot claim

@Jarcho
Copy link
Contributor

Jarcho commented Apr 11, 2022

This should have been fixed with #8673. The root cause is the same.

@J-ZhengLi
Copy link
Member

This should have been fixed with #8673. The root cause is the same.

Oh yes you're correct~ this just got fixed! 🎉

@J-ZhengLi J-ZhengLi removed their assignment Apr 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

4 participants