]> git.lizzy.rs Git - rust.git/blob - src/docs/zero_sized_map_values.txt
Auto merge of #9421 - xphoniex:fix-#9420, r=giraffate
[rust.git] / src / docs / zero_sized_map_values.txt
1 ### What it does
2 Checks for maps with zero-sized value types anywhere in the code.
3
4 ### Why is this bad?
5 Since there is only a single value for a zero-sized type, a map
6 containing zero sized values is effectively a set. Using a set in that case improves
7 readability and communicates intent more clearly.
8
9 ### Known problems
10 * A zero-sized type cannot be recovered later if it contains private fields.
11 * This lints the signature of public items
12
13 ### Example
14 ```
15 fn unique_words(text: &str) -> HashMap<&str, ()> {
16     todo!();
17 }
18 ```
19 Use instead:
20 ```
21 fn unique_words(text: &str) -> HashSet<&str> {
22     todo!();
23 }
24 ```