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