From 4a08fff2b83c624a7bbc77c95131afba660eb3f9 Mon Sep 17 00:00:00 2001 From: seth <yesifan66@gmail.com> Date: Fri, 25 Jun 2021 15:22:02 +0800 Subject: [PATCH] complete: clippy --- exercises/clippy/clippy1.rs | 5 ++--- exercises/clippy/clippy2.rs | 4 +--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/exercises/clippy/clippy1.rs b/exercises/clippy/clippy1.rs index bdb5dd2..c5ceee4 100644 --- a/exercises/clippy/clippy1.rs +++ b/exercises/clippy/clippy1.rs @@ -6,12 +6,11 @@ // check clippy's suggestions from the output to solve the exercise. // Execute `rustlings hint clippy1` for hints :) -// I AM NOT DONE - fn main() { + let error_margin = f64::EPSILON; let x = 1.2331f64; let y = 1.2332f64; - if y != x { + if (y - x).abs() > error_margin { println!("Success!"); } } diff --git a/exercises/clippy/clippy2.rs b/exercises/clippy/clippy2.rs index 37af9ed..4cdfbe7 100644 --- a/exercises/clippy/clippy2.rs +++ b/exercises/clippy/clippy2.rs @@ -1,12 +1,10 @@ // clippy2.rs // Make me compile! Execute `rustlings hint clippy2` for hints :) -// I AM NOT DONE - fn main() { let mut res = 42; let option = Some(12); - for x in option { + if let Some(x) = option { res += x; } println!("{}", res);