]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/partialeq_to_none.txt
Rollup merge of #102470 - est31:stabilize_const_char_convert, r=joshtriplett
[rust.git] / src / tools / clippy / src / docs / partialeq_to_none.txt
1 ### What it does
2
3 Checks for binary comparisons to a literal `Option::None`.
4
5 ### Why is this bad?
6
7 A programmer checking if some `foo` is `None` via a comparison `foo == None`
8 is usually inspired from other programming languages (e.g. `foo is None`
9 in Python).
10 Checking if a value of type `Option<T>` is (not) equal to `None` in that
11 way relies on `T: PartialEq` to do the comparison, which is unneeded.
12
13 ### Example
14 ```
15 fn foo(f: Option<u32>) -> &'static str {
16     if f != None { "yay" } else { "nay" }
17 }
18 ```
19 Use instead:
20 ```
21 fn foo(f: Option<u32>) -> &'static str {
22     if f.is_some() { "yay" } else { "nay" }
23 }
24 ```