Skip to content

Commit 81dde98

Browse files
notriddleblyxyas
andcommitted
Fix style nits
Co-authored-by: Alejandra González <[email protected]>
1 parent 6d713ce commit 81dde98

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

clippy_lints/src/matches/manual_unwrap_or.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ fn get_none<'tcx>(cx: &LateContext<'_>, arm: &Arm<'tcx>, allow_wildcard: bool) -
4848
&& cx.tcx.lang_items().get(LangItem::ResultErr) == Some(def_id)
4949
{
5050
Some(arm.body)
51-
} else if let (PatKind::Wild, true) = (arm.pat.kind, allow_wildcard) {
51+
} else if let PatKind::Wild = arm.pat.kind
52+
&& allow_wildcard
53+
{
5254
// We consider that the `Some` check will filter it out if it's not right.
5355
Some(arm.body)
5456
} else {
@@ -65,8 +67,8 @@ fn get_some_and_none_bodies<'tcx>(
6567
&& let Some(body_none) = get_none(cx, arm2, true)
6668
{
6769
Some(((arm1.body, binding_id), body_none))
68-
} else if let Some(binding_id) = get_some(cx, arm2.pat)
69-
&& let Some(body_none) = get_none(cx, arm1, false)
70+
} else if let Some(body_none) = get_none(cx, arm1, false)
71+
&& let Some(binding_id) = get_some(cx, arm2.pat)
7072
{
7173
Some(((arm2.body, binding_id), body_none))
7274
} else {

tests/ui/manual_unwrap_or_default.fixed

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ fn main() {
3434
x.unwrap_or_default();
3535

3636
// edge case
37+
// because the `Some(bizarro)` pattern is not actually reachable,
38+
// changing this match to `unwrap_or_default` would have side effects
3739
let bizarro = Some(String::new());
3840
match bizarro {
3941
_ => String::new(),

tests/ui/manual_unwrap_or_default.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ fn main() {
6666
};
6767

6868
// edge case
69+
// because the `Some(bizarro)` pattern is not actually reachable,
70+
// changing this match to `unwrap_or_default` would have side effects
6971
let bizarro = Some(String::new());
7072
match bizarro {
7173
_ => String::new(),

tests/ui/manual_unwrap_or_default.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ LL | | };
7676
| |_____^ help: replace it with: `x.unwrap_or_default()`
7777

7878
error: match can be simplified with `.unwrap_or_default()`
79-
--> tests/ui/manual_unwrap_or_default.rs:81:24
79+
--> tests/ui/manual_unwrap_or_default.rs:83:24
8080
|
8181
LL | Some(_) => match *b {
8282
| ________________________^
@@ -87,7 +87,7 @@ LL | | },
8787
| |_____________^ help: replace it with: `(*b).unwrap_or_default()`
8888

8989
error: if let can be simplified with `.unwrap_or_default()`
90-
--> tests/ui/manual_unwrap_or_default.rs:150:5
90+
--> tests/ui/manual_unwrap_or_default.rs:152:5
9191
|
9292
LL | / if let Some(x) = Some(42) {
9393
LL | |

0 commit comments

Comments
 (0)