about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-05-25 19:22:08 +0000
committerbors <bors@rust-lang.org>2020-05-25 19:22:08 +0000
commit6de17b043dfdf942963f1b4e83dec4f8e4e2e06c (patch)
tree79db4d4b77b3343cf06384feb5d6227f9e521bcb /tests
parentc41916d9bd2ca98c9291d07a095503d9e934da60 (diff)
parent29d043683e6f70b22ae34596b4cb9ae07274c28b (diff)
downloadrust-6de17b043dfdf942963f1b4e83dec4f8e4e2e06c.tar.gz
rust-6de17b043dfdf942963f1b4e83dec4f8e4e2e06c.zip
Auto merge of #5635 - montrivo:bugfix/option_option_test_case, r=flip1995
option_option test case #4298

Adds regression test case for #4298.

The bug seems still present although rust Playground said otherwise.

changelog: none
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/option_option.rs25
-rw-r--r--tests/ui/option_option.stderr8
2 files changed, 32 insertions, 1 deletions
diff --git a/tests/ui/option_option.rs b/tests/ui/option_option.rs
index 904c50e1403..a2617a13eca 100644
--- a/tests/ui/option_option.rs
+++ b/tests/ui/option_option.rs
@@ -60,3 +60,28 @@ fn main() {
     // The lint allows this
     let expr = Some(Some(true));
 }
+
+extern crate serde;
+mod issue_4298 {
+    use serde::{Deserialize, Deserializer, Serialize};
+    use std::borrow::Cow;
+
+    #[derive(Serialize, Deserialize)]
+    struct Foo<'a> {
+        #[serde(deserialize_with = "func")]
+        #[serde(skip_serializing_if = "Option::is_none")]
+        #[serde(default)]
+        #[serde(borrow)]
+        // FIXME: should not lint here
+        #[allow(clippy::option_option)]
+        foo: Option<Option<Cow<'a, str>>>,
+    }
+
+    #[allow(clippy::option_option)]
+    fn func<'a, D>(_: D) -> Result<Option<Option<Cow<'a, str>>>, D::Error>
+    where
+        D: Deserializer<'a>,
+    {
+        Ok(Some(Some(Cow::Borrowed("hi"))))
+    }
+}
diff --git a/tests/ui/option_option.stderr b/tests/ui/option_option.stderr
index 79db186d7ea..0cd4c96eb4f 100644
--- a/tests/ui/option_option.stderr
+++ b/tests/ui/option_option.stderr
@@ -58,5 +58,11 @@ error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enu
 LL |     Struct { x: Option<Option<u8>> },
    |                 ^^^^^^^^^^^^^^^^^^
 
-error: aborting due to 9 previous errors
+error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
+  --> $DIR/option_option.rs:77:14
+   |
+LL |         foo: Option<Option<Cow<'a, str>>>,
+   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 10 previous errors