Skip to content

Commit bdd76a9

Browse files
committed
clippy_lint: Allow 'ref_option_ref' for 'option_if_let_else'
1 parent c1f3bab commit bdd76a9

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

tests/ui/option_if_let_else.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// run-rustfix
22
#![warn(clippy::option_if_let_else)]
33
#![allow(clippy::redundant_closure)]
4+
#![allow(clippy::ref_option_ref)]
45

56
fn bad1(string: Option<&str>) -> (bool, &str) {
67
string.map_or((false, "hello"), |x| (true, x))

tests/ui/option_if_let_else.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// run-rustfix
22
#![warn(clippy::option_if_let_else)]
33
#![allow(clippy::redundant_closure)]
4+
#![allow(clippy::ref_option_ref)]
45

56
fn bad1(string: Option<&str>) -> (bool, &str) {
67
if let Some(x) = string {

tests/ui/option_if_let_else.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: use Option::map_or instead of an if let/else
2-
--> $DIR/option_if_let_else.rs:6:5
2+
--> $DIR/option_if_let_else.rs:7:5
33
|
44
LL | / if let Some(x) = string {
55
LL | | (true, x)
@@ -11,7 +11,7 @@ LL | | }
1111
= note: `-D clippy::option-if-let-else` implied by `-D warnings`
1212

1313
error: use Option::map_or instead of an if let/else
14-
--> $DIR/option_if_let_else.rs:16:12
14+
--> $DIR/option_if_let_else.rs:17:12
1515
|
1616
LL | } else if let Some(x) = string {
1717
| ____________^
@@ -22,19 +22,19 @@ LL | | }
2222
| |_____^ help: try: `{ string.map_or(Some((false, "")), |x| Some((true, x))) }`
2323

2424
error: use Option::map_or instead of an if let/else
25-
--> $DIR/option_if_let_else.rs:24:13
25+
--> $DIR/option_if_let_else.rs:25:13
2626
|
2727
LL | let _ = if let Some(s) = *string { s.len() } else { 0 };
2828
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `string.map_or(0, |s| s.len())`
2929

3030
error: use Option::map_or instead of an if let/else
31-
--> $DIR/option_if_let_else.rs:25:13
31+
--> $DIR/option_if_let_else.rs:26:13
3232
|
3333
LL | let _ = if let Some(s) = &num { s } else { &0 };
3434
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)`
3535

3636
error: use Option::map_or instead of an if let/else
37-
--> $DIR/option_if_let_else.rs:26:13
37+
--> $DIR/option_if_let_else.rs:27:13
3838
|
3939
LL | let _ = if let Some(s) = &mut num {
4040
| _____________^
@@ -54,13 +54,13 @@ LL | });
5454
|
5555

5656
error: use Option::map_or instead of an if let/else
57-
--> $DIR/option_if_let_else.rs:32:13
57+
--> $DIR/option_if_let_else.rs:33:13
5858
|
5959
LL | let _ = if let Some(ref s) = num { s } else { &0 };
6060
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)`
6161

6262
error: use Option::map_or instead of an if let/else
63-
--> $DIR/option_if_let_else.rs:33:13
63+
--> $DIR/option_if_let_else.rs:34:13
6464
|
6565
LL | let _ = if let Some(mut s) = num {
6666
| _____________^
@@ -80,7 +80,7 @@ LL | });
8080
|
8181

8282
error: use Option::map_or instead of an if let/else
83-
--> $DIR/option_if_let_else.rs:39:13
83+
--> $DIR/option_if_let_else.rs:40:13
8484
|
8585
LL | let _ = if let Some(ref mut s) = num {
8686
| _____________^
@@ -100,7 +100,7 @@ LL | });
100100
|
101101

102102
error: use Option::map_or instead of an if let/else
103-
--> $DIR/option_if_let_else.rs:48:5
103+
--> $DIR/option_if_let_else.rs:49:5
104104
|
105105
LL | / if let Some(x) = arg {
106106
LL | | let y = x * x;
@@ -119,7 +119,7 @@ LL | })
119119
|
120120

121121
error: use Option::map_or_else instead of an if let/else
122-
--> $DIR/option_if_let_else.rs:61:13
122+
--> $DIR/option_if_let_else.rs:62:13
123123
|
124124
LL | let _ = if let Some(x) = arg {
125125
| _____________^
@@ -131,7 +131,7 @@ LL | | };
131131
| |_____^ help: try: `arg.map_or_else(|| side_effect(), |x| x)`
132132

133133
error: use Option::map_or_else instead of an if let/else
134-
--> $DIR/option_if_let_else.rs:70:13
134+
--> $DIR/option_if_let_else.rs:71:13
135135
|
136136
LL | let _ = if let Some(x) = arg {
137137
| _____________^
@@ -154,7 +154,7 @@ LL | }, |x| x * x * x * x);
154154
|
155155

156156
error: use Option::map_or instead of an if let/else
157-
--> $DIR/option_if_let_else.rs:99:13
157+
--> $DIR/option_if_let_else.rs:100:13
158158
|
159159
LL | let _ = if let Some(x) = optional { x + 2 } else { 5 };
160160
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `optional.map_or(5, |x| x + 2)`

0 commit comments

Comments
 (0)