Open
Description
similar to #2728 however, the value was not a constant in my original code, instead I protected against negative values with an assert()
.
clippy 0.0.212
#[cfg_attr(feature = "cargo-clippy", warn(cast_sign_loss))]
fn main() {
let x = get_some_number();
assert!(x > 0);
let y = "hi".to_string().repeat(x as usize);
println!("{}", y);
}
pub fn get_some_number() -> i32 {
5
}
warning: casting i32 to usize may lose the sign of the value
--> src/main.rs:6:37
|
6 | let y = "hi".to_string().repeat(x as usize);
| ^^^^^^^^^^
|
note: lint level defined here
--> src/main.rs:1:43
|
1 | #[cfg_attr(feature = "cargo-clippy", warn(cast_sign_loss))]
| ^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#cast_sign_loss
Metadata
Metadata
Assignees
Labels
No labels