Skip to content

Commit 38016cb

Browse files
committed
clippy3: Make the intent more clear
1 parent e6cb104 commit 38016cb

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

exercises/22_clippy/clippy3.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
#[rustfmt::skip]
55
#[allow(unused_variables, unused_assignments)]
66
fn main() {
7-
let my_option: Option<()> = None;
7+
let my_option: Option<&str> = None;
8+
// Assume that you don't know the value of `my_option`.
9+
// In the case of `Some`, we want to print its value.
810
if my_option.is_none() {
9-
println!("{:?}", my_option.unwrap());
11+
println!("{}", my_option.unwrap());
1012
}
1113

1214
let my_arr = &[

solutions/22_clippy/clippy3.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ use std::mem;
33
#[rustfmt::skip]
44
#[allow(unused_variables, unused_assignments)]
55
fn main() {
6-
let my_option: Option<()> = None;
6+
let my_option: Option<&str> = None;
77
// `unwrap` of an `Option` after checking if it is `None` will panic.
88
// Use `if-let` instead.
99
if let Some(value) = my_option {
10-
println!("{value:?}");
10+
println!("{value}");
1111
}
1212

1313
// A comma was missing.

0 commit comments

Comments
 (0)