Commit ac85692
committed
Auto merge of rust-lang#5301 - JarredAllen:option_if_let_else, r=flip1995
Suggest `Option::map_or`(_else) for `if let Some { y } else { x }`
Fixes rust-lang#5203
There are two issues with this code that I have noticed:
- Use of `Option::map_or` causes it to always evaluate the code in the else block. If that block is computationally expensive or if it updates some state (such as getting the next value from an iterator), then this change would cause the code to behave differently. In either of those circumstances, it should suggest Option::map_or_else, which takes both cases as a closure and runs one. However, I don't know how to check if the expression would change some state, so I left the lint's applicability as MaybeIncorrect.
- There are lints which can trigger on specific sub-cases of this lint (`if_let_some_result`, `question_mark`, and `while_let_loop`) and suggest different changes (usually better ones because they're more specific). Is this acceptable for clippy to give multiple suggestions, or should I have the code check if those other lints trigger and then not trigger this lint if they do?
changelog: Add lint [`option_if_let_else`]File tree
26 files changed
+760
-228
lines changed- clippy_lints/src
- methods
- utils
- src/lintlist
- tests
- ui
26 files changed
+760
-228
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1577 | 1577 | | |
1578 | 1578 | | |
1579 | 1579 | | |
| 1580 | + | |
1580 | 1581 | | |
1581 | 1582 | | |
1582 | 1583 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
481 | 481 | | |
482 | 482 | | |
483 | 483 | | |
484 | | - | |
485 | | - | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
486 | 487 | | |
487 | 488 | | |
488 | 489 | | |
489 | | - | |
490 | | - | |
491 | | - | |
492 | | - | |
| 490 | + | |
| 491 | + | |
493 | 492 | | |
494 | 493 | | |
495 | 494 | | |
| |||
499 | 498 | | |
500 | 499 | | |
501 | 500 | | |
502 | | - | |
503 | | - | |
504 | | - | |
505 | | - | |
506 | | - | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
507 | 505 | | |
508 | 506 | | |
509 | 507 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
138 | | - | |
| 138 | + | |
139 | 139 | | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
| 140 | + | |
| 141 | + | |
145 | 142 | | |
146 | 143 | | |
147 | 144 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
315 | 311 | | |
316 | 312 | | |
317 | 313 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
264 | 264 | | |
265 | 265 | | |
266 | 266 | | |
| 267 | + | |
267 | 268 | | |
268 | 269 | | |
269 | 270 | | |
| |||
734 | 735 | | |
735 | 736 | | |
736 | 737 | | |
| 738 | + | |
737 | 739 | | |
738 | 740 | | |
739 | 741 | | |
| |||
1052 | 1054 | | |
1053 | 1055 | | |
1054 | 1056 | | |
| 1057 | + | |
1055 | 1058 | | |
1056 | 1059 | | |
1057 | 1060 | | |
| |||
1158 | 1161 | | |
1159 | 1162 | | |
1160 | 1163 | | |
| 1164 | + | |
1161 | 1165 | | |
1162 | 1166 | | |
1163 | 1167 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
264 | 264 | | |
265 | 265 | | |
266 | 266 | | |
267 | | - | |
268 | | - | |
269 | 267 | | |
270 | | - | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
271 | 274 | | |
272 | 275 | | |
273 | 276 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
686 | 686 | | |
687 | 687 | | |
688 | 688 | | |
689 | | - | |
690 | | - | |
691 | | - | |
692 | | - | |
693 | | - | |
694 | | - | |
695 | | - | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
696 | 692 | | |
697 | 693 | | |
698 | 694 | | |
| |||
1881 | 1877 | | |
1882 | 1878 | | |
1883 | 1879 | | |
1884 | | - | |
1885 | | - | |
1886 | | - | |
1887 | | - | |
1888 | | - | |
1889 | | - | |
1890 | | - | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
1891 | 1883 | | |
1892 | 1884 | | |
1893 | 1885 | | |
| |||
1899 | 1891 | | |
1900 | 1892 | | |
1901 | 1893 | | |
1902 | | - | |
1903 | | - | |
1904 | | - | |
1905 | | - | |
1906 | | - | |
| 1894 | + | |
1907 | 1895 | | |
1908 | 1896 | | |
1909 | 1897 | | |
| |||
2023 | 2011 | | |
2024 | 2012 | | |
2025 | 2013 | | |
2026 | | - | |
| 2014 | + | |
2027 | 2015 | | |
2028 | 2016 | | |
2029 | 2017 | | |
2030 | 2018 | | |
2031 | 2019 | | |
2032 | | - | |
2033 | | - | |
2034 | | - | |
| 2020 | + | |
2035 | 2021 | | |
2036 | 2022 | | |
2037 | 2023 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2460 | 2460 | | |
2461 | 2461 | | |
2462 | 2462 | | |
2463 | | - | |
2464 | | - | |
2465 | | - | |
2466 | | - | |
2467 | | - | |
2468 | | - | |
2469 | | - | |
| 2463 | + | |
| 2464 | + | |
| 2465 | + | |
2470 | 2466 | | |
2471 | 2467 | | |
2472 | 2468 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
87 | 84 | | |
88 | 85 | | |
89 | 86 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
| 56 | + | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
101 | 100 | | |
0 commit comments