summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/question_mark.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/clippy/tests/ui/question_mark.rs')
-rw-r--r--src/tools/clippy/tests/ui/question_mark.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/question_mark.rs b/src/tools/clippy/tests/ui/question_mark.rs
index a90eae50e..69451c17e 100644
--- a/src/tools/clippy/tests/ui/question_mark.rs
+++ b/src/tools/clippy/tests/ui/question_mark.rs
@@ -1,4 +1,5 @@
//@run-rustfix
+#![feature(try_blocks)]
#![allow(unreachable_code)]
#![allow(dead_code)]
#![allow(clippy::unnecessary_wraps)]
@@ -263,6 +264,31 @@ fn pattern() -> Result<(), PatternedError> {
fn main() {}
+// `?` is not the same as `return None;` if inside of a try block
+fn issue8628(a: Option<u32>) -> Option<u32> {
+ let b: Option<u32> = try {
+ if a.is_none() {
+ return None;
+ }
+ 32
+ };
+ b.or(Some(128))
+}
+
+fn issue6828_nested_body() -> Option<u32> {
+ try {
+ fn f2(a: Option<i32>) -> Option<i32> {
+ if a.is_none() {
+ return None;
+ // do lint here, the outer `try` is not relevant here
+ // https://github.com/rust-lang/rust-clippy/pull/11001#issuecomment-1610636867
+ }
+ Some(32)
+ }
+ 123
+ }
+}
+
// should not lint, `?` operator not available in const context
const fn issue9175(option: Option<()>) -> Option<()> {
if option.is_none() {