Rustlings: clippy3.rs #Issue86 — Clippy in Rust
Rustlings Challenge: clippy3.rs Solution Walkthrough

This is the Eighty-sixth (86th) issue of the Rustlings series. In this issue, we provide solutions to Rustlings exercises along with detailed explanations. In this issue we will solve the challenge on clippy3.rs.
Previous challenge #Issue 85
The Clippy tool is a collection of lints to analyze your code so you can catch common mistakes and improve your Rust code.
Challenge:
// 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_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);
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;
println!("value a: {}; value b: {}", value_a, value_b);
}Solution:
#[allow(unused_variables, unused_assignments)]
fn main() {
let my_option: Option<()> = None;
if let Some(x) = my_option {}
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].clear();
println!("This Vec is empty, see? {:?}", my_empty_vec);
let mut value_a = 45;
let mut value_b = 66;
// Let's swap these two!
// Alternatively you can use std::mem::swap(&mut value_a, &mut value_b);
let swap_a = value_a;
value_a = value_b;
value_b = swap_a;
println!("value a: {}; value b: {}", value_a, value_b);
// My array! Here it is: [-1, -2, -7, -5, -6]
// This Vec is empty, see? ()
// value a: 66; value b: 45
}You can experiment with the code on Rust Playground.
Resources
Before you go
Thank you for taking the time to read through this challenge. We invite you to share your knowledge of Rust as well. If you found this article valuable, please don’t hesitate to share it with others. Don’t forget to follow the publication and give the article some claps 👏.
Thank you, and we look forward to seeing you for the next challenges!





