|
1 | 1 | // clippy3.rs |
2 | | -// |
| 2 | +// |
3 | 3 | // Here's a couple more easy Clippy fixes, so you can see its utility. |
4 | 4 | // |
5 | 5 | // Execute `rustlings hint clippy3` or use the `hint` watch subcommand for a hint. |
6 | 6 |
|
7 | | -// I AM NOT DONE |
8 | | - |
9 | 7 | #[allow(unused_variables, unused_assignments)] |
10 | 8 | fn main() { |
11 | 9 | let my_option: Option<()> = None; |
12 | | - if my_option.is_none() { |
13 | | - my_option.unwrap(); |
| 10 | + if let Some(x) = my_option { |
| 11 | + println!("This won't print: {x:?}"); |
14 | 12 | } |
15 | 13 |
|
16 | | - let my_arr = &[ |
17 | | - -1, -2, -3 |
18 | | - -4, -5, -6 |
19 | | - ]; |
20 | | - println!("My array! Here it is: {:?}", my_arr); |
| 14 | + let my_arr = &[-1, -2, -3, -4, -5, -6]; |
| 15 | + println!("My array! Here it is: {my_arr:?}"); |
21 | 16 |
|
22 | | - let my_empty_vec = vec![1, 2, 3, 4, 5].resize(0, 5); |
23 | | - println!("This Vec is empty, see? {:?}", my_empty_vec); |
| 17 | + let mut my_empty_vec = vec![1, 2, 3, 4, 5]; |
| 18 | + my_empty_vec.clear(); |
| 19 | + println!("This Vec is empty, see? {my_empty_vec:?}"); |
24 | 20 |
|
25 | 21 | let mut value_a = 45; |
26 | 22 | let mut value_b = 66; |
27 | 23 | // Let's swap these two! |
28 | | - value_a = value_b; |
29 | | - value_b = value_a; |
30 | | - println!("value a: {}; value b: {}", value_a, value_b); |
| 24 | + std::mem::swap(&mut value_a, &mut value_b); |
| 25 | + println!("value a: {value_a}; value b: {value_b}"); |
31 | 26 | } |
0 commit comments