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

Clippy errros with "casting usize to u8 may truncate the value" #713

Open
cmichi opened this issue Mar 7, 2025 · 0 comments · May be fixed by #715
Open

Clippy errros with "casting usize to u8 may truncate the value" #713

cmichi opened this issue Mar 7, 2025 · 0 comments · May be fixed by #715

Comments

@cmichi
Copy link

cmichi commented Mar 7, 2025

IIRC there was a compilation error about the usize to u8 cast a while ago, the release was yanked at the time, and it was fixed. Clippy still errors because of it though:

main.rs:

use parity_scale_codec::{
    Decode,
    Encode,
};

#[derive(Encode, Decode)]
pub enum Foo {
    Bar,
}

fn main() { }

Cargo.toml:

[package]
name = "foobar"
edition = "2024"

[dependencies]
parity-scale-codec = { version = "=3.7.4", features = ["derive"] }

[workspace]

The following errors appear for clippy:

$ cargo +1.85 clippy -- -Dclippy::cast_possible_truncation  
    Checking foobar v0.0.0 (/tmp/foobar)
error: casting `usize` to `u8` may truncate the value
 --> src/main.rs:8:5
  |
8 |     Bar,
  |     ^^^
  |
  = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_truncation
  = note: requested on the command line with `-D clippy::cast-possible-truncation`
help: ... or use `try_from` and handle the error accordingly
  |
8 |     Bar::try_from(Encode),
  |     ~~~~~~~~~~~~~~~~~~~~~

error: casting `usize` to `u8` may truncate the value
 --> src/main.rs:8:5
  |
8 |     Bar,
  |     ^^^
  |
  = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_truncation
help: ... or use `try_from` and handle the error accordingly
  |
8 |     Bar::try_from(Encode),
  |     ~~~~~~~~~~~~~~~~~~~~~

error: casting `usize` to `u8` may truncate the value
 --> src/main.rs:8:5
  |
8 |     Bar,
  |     ^^^
  |
  = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_truncation
help: ... or use `try_from` and handle the error accordingly
  |
8 |     Bar::try_from(Decode),
  |     ~~~~~~~~~~~~~~~~~~~~~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant