Skip to content

Commit eedf38d

Browse files
04101932
1 parent 6408eb2 commit eedf38d

File tree

6 files changed

+10
-29
lines changed

6 files changed

+10
-29
lines changed

exercises/clippy/clippy1.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@
99
// Execute `rustlings hint clippy1` or use the `hint` watch subcommand for a
1010
// hint.
1111

12-
// I AM NOT DONE
13-
1412
use std::f32;
1513

1614
fn main() {
17-
let pi = 3.14f32;
1815
let radius = 5.00f32;
1916

20-
let area = pi * f32::powi(radius, 2);
17+
let area = f32::consts::PI * f32::powi(radius, 2);
2118

2219
println!(
2320
"The area of a circle with radius {:.2} is {:.5}!",

exercises/clippy/clippy2.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
// clippy2.rs
2-
//
2+
//
33
// Execute `rustlings hint clippy2` or use the `hint` watch subcommand for a
44
// hint.
55

6-
// I AM NOT DONE
7-
86
fn main() {
97
let mut res = 42;
108
let option = Some(12);
11-
for x in option {
9+
if let Some(x) = option {
1210
res += x;
1311
}
1412
println!("{}", res);

exercises/clippy/clippy3.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,22 @@
11
// clippy3.rs
2-
//
2+
//
33
// Here's a couple more easy Clippy fixes, so you can see its utility.
44
//
55
// Execute `rustlings hint clippy3` or use the `hint` watch subcommand for a hint.
66

7-
// I AM NOT DONE
8-
97
#[allow(unused_variables, unused_assignments)]
108
fn main() {
119
let my_option: Option<()> = None;
12-
if my_option.is_none() {
13-
my_option.unwrap();
14-
}
1510

16-
let my_arr = &[
17-
-1, -2, -3
18-
-4, -5, -6
19-
];
11+
let my_arr = &[-1, -2, -3 - 4, -5, -6];
2012
println!("My array! Here it is: {:?}", my_arr);
2113

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

2517
let mut value_a = 45;
2618
let mut value_b = 66;
2719
// Let's swap these two!
28-
value_a = value_b;
29-
value_b = value_a;
20+
std::mem::swap(&mut value_a, &mut value_b);
3021
println!("value a: {}; value b: {}", value_a, value_b);
3122
}

exercises/macros/macros2.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// Execute `rustlings hint macros2` or use the `hint` watch subcommand for a
44
// hint.
55

6-
// I AM NOT DONE
7-
86
macro_rules! my_macro {
97
() => {
108
println!("Check out my macro!");

exercises/macros/macros3.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
// Execute `rustlings hint macros3` or use the `hint` watch subcommand for a
66
// hint.
77

8-
// I AM NOT DONE
9-
8+
#[macro_use]
109
mod macros {
1110
macro_rules! my_macro {
1211
() => {

exercises/macros/macros4.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
// Execute `rustlings hint macros4` or use the `hint` watch subcommand for a
44
// hint.
55

6-
// I AM NOT DONE
7-
86
#[rustfmt::skip]
97
macro_rules! my_macro {
108
() => {
119
println!("Check out my macro!");
12-
}
10+
};
1311
($val:expr) => {
1412
println!("Look at this other macro: {}", $val);
1513
}

0 commit comments

Comments
 (0)