Skip to content

Commit a91ec59

Browse files
committed
Update question_mark expected test output
1 parent a1a399d commit a91ec59

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

tests/ui/question_mark.fixed

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
#![allow(unreachable_code)]
33
#![allow(clippy::unnecessary_wraps)]
44

5+
use std::env;
6+
use std::path::PathBuf;
7+
58
fn some_func(a: Option<u32>) -> Option<u32> {
69
a?;
710

@@ -104,18 +107,34 @@ fn func() -> Option<i32> {
104107
Some(0)
105108
}
106109

107-
fn result_func(x: Result<i32, &str>) -> Result<i32, &str> {
110+
fn func_returning_result() -> Result<i32, String> {
111+
Ok(1)
112+
}
113+
114+
fn result_func(x: Result<i32, String>) -> Result<i32, String> {
108115
let _ = x?;
109116

110-
x?;
117+
x.as_ref()?;
111118

112119
// No warning
113120
let y = if let Ok(x) = x {
114121
x
115122
} else {
116-
return Err("some error");
123+
return Err("some error".to_string());
117124
};
118125

126+
// issue #7859
127+
// no warning
128+
let _ = if let Ok(x) = func_returning_result() {
129+
x
130+
} else {
131+
return Err("some error".to_string());
132+
};
133+
134+
if func_returning_result().is_err() {
135+
return func_returning_result();
136+
}
137+
119138
Ok(y)
120139
}
121140

tests/ui/question_mark.stderr

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this block may be rewritten with the `?` operator
2-
--> $DIR/question_mark.rs:6:5
2+
--> $DIR/question_mark.rs:9:5
33
|
44
LL | / if a.is_none() {
55
LL | | return None;
@@ -9,23 +9,23 @@ LL | | }
99
= note: `-D clippy::question-mark` implied by `-D warnings`
1010

1111
error: this block may be rewritten with the `?` operator
12-
--> $DIR/question_mark.rs:51:9
12+
--> $DIR/question_mark.rs:54:9
1313
|
1414
LL | / if (self.opt).is_none() {
1515
LL | | return None;
1616
LL | | }
1717
| |_________^ help: replace it with: `(self.opt)?;`
1818

1919
error: this block may be rewritten with the `?` operator
20-
--> $DIR/question_mark.rs:55:9
20+
--> $DIR/question_mark.rs:58:9
2121
|
2222
LL | / if self.opt.is_none() {
2323
LL | | return None
2424
LL | | }
2525
| |_________^ help: replace it with: `self.opt?;`
2626

2727
error: this block may be rewritten with the `?` operator
28-
--> $DIR/question_mark.rs:59:17
28+
--> $DIR/question_mark.rs:62:17
2929
|
3030
LL | let _ = if self.opt.is_none() {
3131
| _________________^
@@ -36,7 +36,7 @@ LL | | };
3636
| |_________^ help: replace it with: `Some(self.opt?)`
3737

3838
error: this if-let-else may be rewritten with the `?` operator
39-
--> $DIR/question_mark.rs:65:17
39+
--> $DIR/question_mark.rs:68:17
4040
|
4141
LL | let _ = if let Some(x) = self.opt {
4242
| _________________^
@@ -47,31 +47,31 @@ LL | | };
4747
| |_________^ help: replace it with: `self.opt?`
4848

4949
error: this block may be rewritten with the `?` operator
50-
--> $DIR/question_mark.rs:82:9
50+
--> $DIR/question_mark.rs:85:9
5151
|
5252
LL | / if self.opt.is_none() {
5353
LL | | return None;
5454
LL | | }
5555
| |_________^ help: replace it with: `self.opt.as_ref()?;`
5656

5757
error: this block may be rewritten with the `?` operator
58-
--> $DIR/question_mark.rs:90:9
58+
--> $DIR/question_mark.rs:93:9
5959
|
6060
LL | / if self.opt.is_none() {
6161
LL | | return None;
6262
LL | | }
6363
| |_________^ help: replace it with: `self.opt.as_ref()?;`
6464

6565
error: this block may be rewritten with the `?` operator
66-
--> $DIR/question_mark.rs:98:9
66+
--> $DIR/question_mark.rs:101:9
6767
|
6868
LL | / if self.opt.is_none() {
6969
LL | | return None;
7070
LL | | }
7171
| |_________^ help: replace it with: `self.opt.as_ref()?;`
7272

7373
error: this if-let-else may be rewritten with the `?` operator
74-
--> $DIR/question_mark.rs:105:26
74+
--> $DIR/question_mark.rs:108:26
7575
|
7676
LL | let v: &Vec<_> = if let Some(ref v) = self.opt {
7777
| __________________________^
@@ -82,7 +82,7 @@ LL | | };
8282
| |_________^ help: replace it with: `self.opt.as_ref()?`
8383

8484
error: this if-let-else may be rewritten with the `?` operator
85-
--> $DIR/question_mark.rs:115:17
85+
--> $DIR/question_mark.rs:118:17
8686
|
8787
LL | let v = if let Some(v) = self.opt {
8888
| _________________^
@@ -93,26 +93,26 @@ LL | | };
9393
| |_________^ help: replace it with: `self.opt?`
9494

9595
error: this block may be rewritten with the `?` operator
96-
--> $DIR/question_mark.rs:130:5
96+
--> $DIR/question_mark.rs:133:5
9797
|
9898
LL | / if f().is_none() {
9999
LL | | return None;
100100
LL | | }
101101
| |_____^ help: replace it with: `f()?;`
102102

103103
error: this if-let-else may be rewritten with the `?` operator
104-
--> $DIR/question_mark.rs:138:13
104+
--> $DIR/question_mark.rs:145:13
105105
|
106106
LL | let _ = if let Ok(x) = x { x } else { return x };
107107
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `x?`
108108

109109
error: this block may be rewritten with the `?` operator
110-
--> $DIR/question_mark.rs:140:5
110+
--> $DIR/question_mark.rs:147:5
111111
|
112112
LL | / if x.is_err() {
113113
LL | | return x;
114114
LL | | }
115-
| |_____^ help: replace it with: `x?;`
115+
| |_____^ help: replace it with: `x.as_ref()?;`
116116

117117
error: aborting due to 13 previous errors
118118

0 commit comments

Comments
 (0)