mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-25 00:00:05 +03:00
clippy2 solution
This commit is contained in:
parent
78728d5238
commit
a0e810b471
|
@ -1,8 +1,10 @@
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut res = 42;
|
let mut res = 42;
|
||||||
let option = Some(12);
|
let option = Some(12);
|
||||||
|
// TODO: Fix the Clippy lint.
|
||||||
for x in option {
|
for x in option {
|
||||||
res += x;
|
res += x;
|
||||||
}
|
}
|
||||||
println!("{}", res);
|
|
||||||
|
println!("{res}");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1151,7 +1151,8 @@ dir = "22_clippy"
|
||||||
test = false
|
test = false
|
||||||
strict_clippy = true
|
strict_clippy = true
|
||||||
hint = """
|
hint = """
|
||||||
`for` loops over `Option` values are more clearly expressed as an `if let`"""
|
`for` loops over `Option` values are more clearly expressed as an `if-let`
|
||||||
|
statement."""
|
||||||
|
|
||||||
[[exercises]]
|
[[exercises]]
|
||||||
name = "clippy3"
|
name = "clippy3"
|
||||||
|
|
|
@ -1 +1,10 @@
|
||||||
// Solutions will be available before the stable release. Thank you for testing the beta version 🥰
|
fn main() {
|
||||||
|
let mut res = 42;
|
||||||
|
let option = Some(12);
|
||||||
|
// Use `if-let` instead of iteration.
|
||||||
|
if let Some(x) = option {
|
||||||
|
res += x;
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("{res}");
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue