Skip to content

Commit

Permalink
finish clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Withsan committed Oct 5, 2023
1 parent 306b90e commit 9af7680
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
4 changes: 2 additions & 2 deletions exercises/clippy/clippy1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

// I AM NOT DONE

use std::f32;
use std::f32::consts;

fn main() {
let pi = 3.14f32;
let pi = consts::PI;
let radius = 5.00f32;

let area = pi * f32::powi(radius, 2);
Expand Down
4 changes: 2 additions & 2 deletions exercises/clippy/clippy2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// clippy2.rs
//
//
// Execute `rustlings hint clippy2` or use the `hint` watch subcommand for a
// hint.

Expand All @@ -8,7 +8,7 @@
fn main() {
let mut res = 42;
let option = Some(12);
for x in option {
if let Some(x) = option {
res += x;
}
println!("{}", res);
Expand Down
20 changes: 8 additions & 12 deletions exercises/clippy/clippy3.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
// clippy3.rs
//
//
// Here's a couple more easy Clippy fixes, so you can see its utility.
// No hints.

// I AM NOT DONE

#[allow(unused_variables, unused_assignments)]
fn main() {
let my_option: Option<()> = None;
if my_option.is_none() {
my_option.unwrap();
let my_option: Option<()> = Some(());
if let Some(x) = my_option {
println!("fuck");
}

let my_arr = &[
-1, -2, -3
-4, -5, -6
];
let my_arr = &[-1, -2, -3, -4, -5, -6];
println!("My array! Here it is: {:?}", my_arr);

let my_empty_vec = vec![1, 2, 3, 4, 5].resize(0, 5);
let my_empty_vec = vec![1, 2, 3, 4, 5];
println!("This Vec is empty, see? {:?}", my_empty_vec);

let mut value_a = 45;
let mut value_b = 66;
// Let's swap these two!
value_a = value_b;
value_b = value_a;
std::mem::swap(&mut value_a, &mut value_b);

println!("value a: {}; value b: {}", value_a, value_b);
}

0 comments on commit 9af7680

Please sign in to comment.