Sometimes, we might explicitly cast an element to a type that the compiler should cast automatically. This sometimes happens when we use traits, but it can also happen because we changed the type of an element to a new type and we didn't change the castings. To clean these kinds of behavior, we have the trivial_casts and trivial_numeric_casts lints. Let's see it as an example:
#![warn(trivial_casts, trivial_numeric_casts)]#[derive(Default, Debug)]struct MyStruct { a: i32, b: i32,}fn main() { let test = MyStruct::default(); println!("{:?}", (test as MyStruct).a as i32);}
In this case, we first cast test as a MyStruct, but it's already a MyStruct, so this is redundant and makes the code much less readable, and in ...