]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/needless_question_mark.rs
fix `needless_question_mark` not considering async fn
[rust.git] / tests / ui / needless_question_mark.rs
index 1ea4ba0d83fd76da23c3ac13bb4dcb3caf9cc801..3a6523e8fe872a94b172c851d1c997f9a1ed9350 100644 (file)
@@ -94,6 +94,11 @@ fn false_positive_test<U, T>(x: Result<(), U>) -> Result<(), T>
     Ok(x?)
 }
 
+// not quite needless
+fn deref_ref(s: Option<&String>) -> Option<&str> {
+    Some(s?)
+}
+
 fn main() {}
 
 // #6921 if a macro wraps an expr in Some(  ) and the ? is in the macro use,
@@ -120,3 +125,16 @@ pub fn test2() {
     let x = Some(3);
     let _x = some_and_qmark_in_macro!(x?);
 }
+
+async fn async_option_bad(to: TO) -> Option<usize> {
+    let _ = Some(3);
+    Some(to.magic?)
+}
+
+async fn async_deref_ref(s: Option<&String>) -> Option<&str> {
+    Some(s?)
+}
+
+async fn async_result_bad(s: TR) -> Result<usize, bool> {
+    Ok(s.magic?)
+}