blob: 540739fd45fae05eafd471984a483ce5e991ee08 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
### What it does
Suggests alternatives for useless applications of `?` in terminating expressions
### Why is this bad?
There's no reason to use `?` to short-circuit when execution of the body will end there anyway.
### Example
```
struct TO {
magic: Option<usize>,
}
fn f(to: TO) -> Option<usize> {
Some(to.magic?)
}
struct TR {
magic: Result<usize, bool>,
}
fn g(tr: Result<TR, bool>) -> Result<usize, bool> {
tr.and_then(|t| Ok(t.magic?))
}
```
Use instead:
```
struct TO {
magic: Option<usize>,
}
fn f(to: TO) -> Option<usize> {
to.magic
}
struct TR {
magic: Result<usize, bool>,
}
fn g(tr: Result<TR, bool>) -> Result<usize, bool> {
tr.and_then(|t| t.magic)
}
```
|