Commit e4923c2
committed
Auto merge of rust-lang#10120 - smoelius:or_insert_with, r=blyxyas
`unwrap_or_else_default` -> `unwrap_or_default` and improve resulting lint
Resolves rust-lang#10080 (though it doesn't implement exactly what's described there)
This PR does the following:
1. Merges `unwrap_or_else_default.rs`'s code into `or_fun_call.rs`
2. Extracts the code to handle `unwrap_or(/* default value */)` and similar, and moves it into `unwrap_or_else_default`
3. Implements the missing functionality from rust-lang#9342, e.g.,, to handle `or_insert_with(Default::default)`
4. Renames `unwrap_or_else_default` to `unwrap_or_default` (since the "new" lint handles both `unwrap_or` and `unwrap_or_else`, it seemed sensible to use the shortened name)
This PR is currently two commits. The first implements 1-3, the second implements 4.
A word about 2: the `or_fun_call` lint currently produces warnings like the following:
```
error: use of `unwrap_or` followed by a call to `new`
--> $DIR/or_fun_call.rs:56:14
|
LL | with_new.unwrap_or(Vec::new());
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
```
To me, such warnings look like they should come from `unwrap_or_else_default`, not `or_fun_call`, especially since `or_fun_call` is [in the nursery](rust-lang/rust-clippy#9829).
---
changelog: Move: Renamed `unwrap_or_else_default` to [`unwrap_or_default`]
[rust-lang#10120](rust-lang/rust-clippy#10120)
changelog: Enhancement: [`unwrap_or_default`]: Now handles more functions, like `or_insert_with`
[rust-lang#10120](rust-lang/rust-clippy#10120)
<!-- changelog_checked-->File tree
15 files changed
+429
-266
lines changed- clippy_lints/src
- methods
- tests/ui
15 files changed
+429
-266
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5370 | 5370 | | |
5371 | 5371 | | |
5372 | 5372 | | |
| 5373 | + | |
5373 | 5374 | | |
5374 | 5375 | | |
5375 | 5376 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
425 | 425 | | |
426 | 426 | | |
427 | 427 | | |
428 | | - | |
| 428 | + | |
429 | 429 | | |
430 | 430 | | |
431 | 431 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
107 | 106 | | |
108 | 107 | | |
109 | 108 | | |
| |||
476 | 475 | | |
477 | 476 | | |
478 | 477 | | |
479 | | - | |
480 | | - | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
481 | 484 | | |
482 | 485 | | |
483 | | - | |
484 | | - | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
485 | 492 | | |
486 | 493 | | |
487 | 494 | | |
488 | 495 | | |
489 | | - | |
490 | | - | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
491 | 499 | | |
492 | 500 | | |
493 | 501 | | |
494 | 502 | | |
495 | 503 | | |
| 504 | + | |
496 | 505 | | |
| 506 | + | |
497 | 507 | | |
498 | 508 | | |
499 | | - | |
| 509 | + | |
500 | 510 | | |
501 | | - | |
| 511 | + | |
502 | 512 | | |
503 | 513 | | |
504 | 514 | | |
| |||
3495 | 3505 | | |
3496 | 3506 | | |
3497 | 3507 | | |
3498 | | - | |
| 3508 | + | |
3499 | 3509 | | |
3500 | 3510 | | |
3501 | 3511 | | |
| |||
3756 | 3766 | | |
3757 | 3767 | | |
3758 | 3768 | | |
3759 | | - | |
3760 | | - | |
| 3769 | + | |
3761 | 3770 | | |
3762 | 3771 | | |
3763 | 3772 | | |
| |||
3774 | 3783 | | |
3775 | 3784 | | |
3776 | 3785 | | |
3777 | | - | |
3778 | | - | |
| 3786 | + | |
3779 | 3787 | | |
3780 | 3788 | | |
3781 | 3789 | | |
| |||
4134 | 4142 | | |
4135 | 4143 | | |
4136 | 4144 | | |
4137 | | - | |
4138 | 4145 | | |
4139 | 4146 | | |
4140 | 4147 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
| 4 | + | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | 8 | | |
| 9 | + | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
| 12 | + | |
12 | 13 | | |
13 | | - | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| 28 | + | |
| 29 | + | |
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
30 | 33 | | |
| 34 | + | |
31 | 35 | | |
32 | | - | |
33 | | - | |
| 36 | + | |
34 | 37 | | |
35 | 38 | | |
36 | 39 | | |
37 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
38 | 43 | | |
39 | | - | |
40 | | - | |
41 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
42 | 51 | | |
43 | 52 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
71 | 62 | | |
72 | 63 | | |
73 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
74 | 94 | | |
75 | 95 | | |
76 | 96 | | |
| |||
168 | 188 | | |
169 | 189 | | |
170 | 190 | | |
171 | | - | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
172 | 194 | | |
173 | 195 | | |
174 | 196 | | |
175 | 197 | | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
176 | 201 | | |
177 | 202 | | |
178 | 203 | | |
| |||
189 | 214 | | |
190 | 215 | | |
191 | 216 | | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
0 commit comments