mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-12 05:39:19 +00:00
clippy
This commit is contained in:
parent
6284d03eb1
commit
06a541ce38
@ -6,12 +6,10 @@
|
|||||||
// check clippy's suggestions from the output to solve the exercise.
|
// check clippy's suggestions from the output to solve the exercise.
|
||||||
// Execute `rustlings hint clippy1` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint clippy1` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
use std::f32;
|
use std::f32;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let pi = 3.14f32;
|
let pi = f32::consts::PI;
|
||||||
let radius = 5.00f32;
|
let radius = 5.00f32;
|
||||||
|
|
||||||
let area = pi * f32::powi(radius, 2);
|
let area = pi * f32::powi(radius, 2);
|
||||||
|
|||||||
@ -1,13 +1,11 @@
|
|||||||
// clippy2.rs
|
// clippy2.rs
|
||||||
// Execute `rustlings hint clippy2` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint clippy2` or use the `hint` watch subcommand for a 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 {
|
if let Some(x) = option {
|
||||||
res += x;
|
res += x
|
||||||
}
|
}
|
||||||
println!("{}", res);
|
println!("{}", res);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,28 +1,20 @@
|
|||||||
// clippy3.rs
|
// clippy3.rs
|
||||||
// Here's a couple more easy Clippy fixes, so you can see its utility.
|
// Here's a couple more easy Clippy fixes, so you can see its utility.
|
||||||
|
|
||||||
// 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() {
|
|
||||||
my_option.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
let my_arr = &[
|
let my_arr = &[-1, -2, -3, -4, -5, -6];
|
||||||
-1, -2, -3
|
|
||||||
-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;
|
std::mem::swap(&mut value_a, &mut value_b);
|
||||||
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