mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-10 12:49:18 +00:00
clippy
This commit is contained in:
parent
0c8944006f
commit
0c72fc9936
@ -9,12 +9,10 @@
|
|||||||
// Execute `rustlings hint clippy1` or use the `hint` watch subcommand for a
|
// Execute `rustlings hint clippy1` or use the `hint` watch subcommand for a
|
||||||
// hint.
|
// hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
use std::f32::{self, consts::PI};
|
||||||
|
|
||||||
use std::f32;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let pi = 3.14f32;
|
let pi = PI; // changed to the consts value
|
||||||
let radius = 5.00f32;
|
let radius = 5.00f32;
|
||||||
|
|
||||||
let area = pi * f32::powi(radius, 2);
|
let area = pi * f32::powi(radius, 2);
|
||||||
|
|||||||
@ -3,13 +3,12 @@
|
|||||||
// Execute `rustlings hint clippy2` or use the `hint` watch subcommand for a
|
// Execute `rustlings hint clippy2` or use the `hint` watch subcommand for a
|
||||||
// hint.
|
// hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut res = 42;
|
let mut res = 42;
|
||||||
let option = Some(12);
|
let option = Some(12);
|
||||||
for x in option {
|
// switching to if let ...
|
||||||
res += x;
|
if let Some(n) = option {
|
||||||
|
res += n;
|
||||||
}
|
}
|
||||||
println!("{}", res);
|
println!("{}", res);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,28 +4,28 @@
|
|||||||
//
|
//
|
||||||
// Execute `rustlings hint clippy3` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint clippy3` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
#[allow(unused_variables, unused_assignments)]
|
#[allow(unused_variables, unused_assignments)]
|
||||||
fn main() {
|
fn main() {
|
||||||
let my_option: Option<()> = None;
|
let my_option: Option<()> = None;
|
||||||
if my_option.is_none() {
|
// if my_option.is_none() {
|
||||||
my_option.unwrap();
|
// my_option.unwrap();
|
||||||
}
|
// }
|
||||||
|
|
||||||
let my_arr = &[
|
let my_arr = &[
|
||||||
-1, -2, -3
|
-1, -2, -3,
|
||||||
-4, -5, -6
|
-4, -5, -6,
|
||||||
];
|
];
|
||||||
println!("My array! Here it is: {:?}", my_arr);
|
println!("My array! Here it is: {:?}", my_arr);
|
||||||
|
|
||||||
let my_empty_vec = vec![1, 2, 3, 4, 5].resize(0, 5);
|
let mut my_empty_vec = vec![1, 2, 3, 4, 5];
|
||||||
|
my_empty_vec.clear();
|
||||||
println!("This Vec is empty, see? {:?}", my_empty_vec);
|
println!("This Vec is empty, see? {:?}", my_empty_vec);
|
||||||
|
|
||||||
let mut value_a = 45;
|
let mut value_a = 45;
|
||||||
let mut value_b = 66;
|
let mut value_b = 66;
|
||||||
// Let's swap these two!
|
// Let's swap these two!
|
||||||
value_a = value_b;
|
// value_a = value_b;
|
||||||
value_b = value_a;
|
// value_b = value_a;
|
||||||
|
value_a = std::mem::replace(&mut value_b, value_a);
|
||||||
println!("value a: {}; value b: {}", value_a, value_b);
|
println!("value a: {}; value b: {}", value_a, value_b);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user