Skip to content

Commit 5cc7eb6

Browse files
committed
Adding extra tests for question_mark
1 parent 7854830 commit 5cc7eb6

File tree

3 files changed

+106
-1
lines changed

3 files changed

+106
-1
lines changed

tests/ui/question_mark.fixed

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,24 @@ fn issue12412(foo: &Foo, bar: &Bar) -> Option<()> {
373373
let v = bar.foo.owned.clone()?;
374374
Some(())
375375
}
376+
377+
mod issue13626 {
378+
fn basic_test(x: Option<u32>) -> Option<u32> {
379+
let x = x?;
380+
dbg!(x);
381+
Some(x * 2)
382+
}
383+
384+
fn mut_ref_test(mut x: Option<u32>) -> Option<u32> {
385+
let x = x.as_mut()?;
386+
dbg!(*x);
387+
Some(*x * 2)
388+
}
389+
390+
#[allow(clippy::needless_return)]
391+
fn explicit_return_test(x: Option<u32>) -> Option<u32> {
392+
let x = x?;
393+
dbg!(x);
394+
return Some(x * 2);
395+
}
396+
}

tests/ui/question_mark.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,3 +430,33 @@ fn issue12412(foo: &Foo, bar: &Bar) -> Option<()> {
430430
};
431431
Some(())
432432
}
433+
434+
mod issue13626 {
435+
fn basic_test(x: Option<u32>) -> Option<u32> {
436+
if let Some(x) = x {
437+
dbg!(x);
438+
Some(x * 2)
439+
} else {
440+
None
441+
}
442+
}
443+
444+
fn mut_ref_test(mut x: Option<u32>) -> Option<u32> {
445+
if let Some(ref mut x) = x {
446+
dbg!(*x);
447+
Some(*x * 2)
448+
} else {
449+
None
450+
}
451+
}
452+
453+
#[allow(clippy::needless_return)]
454+
fn explicit_return_test(x: Option<u32>) -> Option<u32> {
455+
if let Some(x) = x {
456+
dbg!(x);
457+
return Some(x * 2);
458+
} else {
459+
return None;
460+
}
461+
}
462+
}

tests/ui/question_mark.stderr

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,5 +196,59 @@ LL | | return None;
196196
LL | | };
197197
| |______^ help: replace it with: `let v = bar.foo.owned.clone()?;`
198198

199-
error: aborting due to 22 previous errors
199+
error: this block may be rewritten with the `?` operator
200+
--> tests/ui/question_mark.rs:436:9
201+
|
202+
LL | / if let Some(x) = x {
203+
LL | | dbg!(x);
204+
LL | | Some(x * 2)
205+
LL | | } else {
206+
LL | | None
207+
LL | | }
208+
| |_________^
209+
|
210+
help: replace it with
211+
|
212+
LL ~ let x = x?;
213+
LL + dbg!(x);
214+
LL + Some(x * 2)
215+
|
216+
217+
error: this block may be rewritten with the `?` operator
218+
--> tests/ui/question_mark.rs:445:9
219+
|
220+
LL | / if let Some(ref mut x) = x {
221+
LL | | dbg!(*x);
222+
LL | | Some(*x * 2)
223+
LL | | } else {
224+
LL | | None
225+
LL | | }
226+
| |_________^
227+
|
228+
help: replace it with
229+
|
230+
LL ~ let x = x.as_mut()?;
231+
LL + dbg!(*x);
232+
LL + Some(*x * 2)
233+
|
234+
235+
error: this block may be rewritten with the `?` operator
236+
--> tests/ui/question_mark.rs:455:9
237+
|
238+
LL | / if let Some(x) = x {
239+
LL | | dbg!(x);
240+
LL | | return Some(x * 2);
241+
LL | | } else {
242+
LL | | return None;
243+
LL | | }
244+
| |_________^
245+
|
246+
help: replace it with
247+
|
248+
LL ~ let x = x?;
249+
LL + dbg!(x);
250+
LL + return Some(x * 2);
251+
|
252+
253+
error: aborting due to 25 previous errors
200254

0 commit comments

Comments
 (0)