Ok(x?)
}
-fn main() {}
-
-mod question_mark_none {
- #![clippy::msrv = "1.12.0"]
- fn needless_question_mark_option() -> Option<usize> {
- struct TO {
- magic: Option<usize>,
- }
- let to = TO { magic: None };
- Some(to.magic?) // should not be triggered
- }
-
- fn needless_question_mark_result() -> Result<usize, bool> {
- struct TO {
- magic: Result<usize, bool>,
- }
- let to = TO { magic: Ok(1_usize) };
- Ok(to.magic?) // should not be triggered
- }
-
- fn main() {
- needless_question_mark_option();
- needless_question_mark_result();
- }
-}
-
-mod question_mark_result {
- #![clippy::msrv = "1.21.0"]
- fn needless_question_mark_option() -> Option<usize> {
- struct TO {
- magic: Option<usize>,
- }
- let to = TO { magic: None };
- Some(to.magic?) // should not be triggered
- }
-
- fn needless_question_mark_result() -> Result<usize, bool> {
- struct TO {
- magic: Result<usize, bool>,
- }
- let to = TO { magic: Ok(1_usize) };
- Ok(to.magic?) // should be triggered
- }
-
- fn main() {
- needless_question_mark_option();
- needless_question_mark_result();
- }
+// not quite needless
+fn deref_ref(s: Option<&String>) -> Option<&str> {
+ Some(s?)
}
-mod question_mark_both {
- #![clippy::msrv = "1.22.0"]
- fn needless_question_mark_option() -> Option<usize> {
- struct TO {
- magic: Option<usize>,
- }
- let to = TO { magic: None };
- Some(to.magic?) // should be triggered
- }
-
- fn needless_question_mark_result() -> Result<usize, bool> {
- struct TO {
- magic: Result<usize, bool>,
- }
- let to = TO { magic: Ok(1_usize) };
- Ok(to.magic?) // should be triggered
- }
-
- fn main() {
- needless_question_mark_option();
- needless_question_mark_result();
- }
-}
+fn main() {}
// #6921 if a macro wraps an expr in Some( ) and the ? is in the macro use,
// the suggestion fails to apply; do not lint
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?)
+}