Rust: Fixed cargo clippy on non-generated code (#5485)

* Cargo clippy lints

* more lints

* more lints

* Restored a doc comment

* Comment on float eps-eq and adjusted casting
This commit is contained in:
Casper
2019-09-09 13:02:43 -07:00
committed by Wouter van Oortmerssen
parent 4b870aca98
commit c0282873fb
7 changed files with 29 additions and 31 deletions

View File

@@ -106,10 +106,13 @@ fn main() {
assert_eq!("MyMonster", m.name());
let pos = m.pos().unwrap();
assert_eq!(pos.x(), 1.0f32);
assert_eq!(pos.y(), 2.0f32);
assert_eq!(pos.z(), 3.0f32);
assert_eq!(pos.test1(), 3.0f64);
// We know the bits should be exactly equal here but compilers may
// optimize floats in subtle ways so we're playing it safe and using
// epsilon comparison
assert!((pos.x() - 1.0f32).abs() < std::f32::EPSILON);
assert!((pos.y() - 2.0f32).abs() < std::f32::EPSILON);
assert!((pos.z() - 3.0f32).abs() < std::f32::EPSILON);
assert!((pos.test1() - 3.0f64).abs() < std::f64::EPSILON);
assert_eq!(pos.test2(), my_game::example::Color::Green);
let pos_test3 = pos.test3();
assert_eq!(pos_test3.a(), 5i16);
@@ -126,8 +129,8 @@ fn main() {
let test4 = m.test4().unwrap();
assert_eq!(test4.len(), 2);
assert_eq!(test4[0].a() as i32 + test4[0].b() as i32 +
test4[1].a() as i32 + test4[1].b() as i32, 100);
assert_eq!(i32::from(test4[0].a()) + i32::from(test4[1].a()) +
i32::from(test4[0].b()) + i32::from(test4[1].b()), 100);
let testarrayofstring = m.testarrayofstring().unwrap();
assert_eq!(testarrayofstring.len(), 2);