Skip to content

Commit 29d0436

Browse files
committed
option_option test case #4298
1 parent 1831385 commit 29d0436

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

tests/ui/option_option.rs

+25
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,28 @@ fn main() {
6060
// The lint allows this
6161
let expr = Some(Some(true));
6262
}
63+
64+
extern crate serde;
65+
mod issue_4298 {
66+
use serde::{Deserialize, Deserializer, Serialize};
67+
use std::borrow::Cow;
68+
69+
#[derive(Serialize, Deserialize)]
70+
struct Foo<'a> {
71+
#[serde(deserialize_with = "func")]
72+
#[serde(skip_serializing_if = "Option::is_none")]
73+
#[serde(default)]
74+
#[serde(borrow)]
75+
// FIXME: should not lint here
76+
#[allow(clippy::option_option)]
77+
foo: Option<Option<Cow<'a, str>>>,
78+
}
79+
80+
#[allow(clippy::option_option)]
81+
fn func<'a, D>(_: D) -> Result<Option<Option<Cow<'a, str>>>, D::Error>
82+
where
83+
D: Deserializer<'a>,
84+
{
85+
Ok(Some(Some(Cow::Borrowed("hi"))))
86+
}
87+
}

tests/ui/option_option.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,11 @@ error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enu
5858
LL | Struct { x: Option<Option<u8>> },
5959
| ^^^^^^^^^^^^^^^^^^
6060

61-
error: aborting due to 9 previous errors
61+
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
62+
--> $DIR/option_option.rs:77:14
63+
|
64+
LL | foo: Option<Option<Cow<'a, str>>>,
65+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66+
67+
error: aborting due to 10 previous errors
6268

0 commit comments

Comments
 (0)