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

invalid_upcast_comparisons: false positive on implicit wrapping #7648

Open
toku-sa-n opened this issue Sep 9, 2021 · 1 comment
Open

invalid_upcast_comparisons: false positive on implicit wrapping #7648

toku-sa-n opened this issue Sep 9, 2021 · 1 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

Comments

@toku-sa-n
Copy link

Lint name: invalid_upcast_comparisons

I tried this code:

#![warn(clippy::invalid_upcast_comparisons)]
fn main() {
    let a = -1;
    let b = a as u64;

    println!("{}", (b as i32) < 0);
}

I expected to see this happen: Clippy says nothing.
Instead, this happened:

warning: because of the numeric bounds on `b` prior to casting, this expression is always false
 --> src/main.rs:6:20
  |
6 |     println!("{}", (b as i32) < 0);
  |                    ^^^^^^^^^^^^^^
  |
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![warn(clippy::invalid_upcast_comparisons)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#invalid_upcast_comparisons

Meta

Rust version (rustc -Vv):

rustc 1.57.0-nightly (97032a6df 2021-09-08)
binary: rustc
commit-hash: 97032a6dfacdd3548e4bff98c90a6b3875a14077
commit-date: 2021-09-08
host: x86_64-unknown-linux-gnu
release: 1.57.0-nightly
LLVM version: 13.0.0

Clippy complained nothing if I change u64 to u32.
Related: #886

@toku-sa-n toku-sa-n 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 Sep 9, 2021
@rustbot

This comment has been minimized.

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

2 participants