Skip to content

Commit

Permalink
option_option test case rust-lang#4298
Browse files Browse the repository at this point in the history
  • Loading branch information
tnielens committed May 22, 2020
1 parent 1831385 commit a9b2cfa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
25 changes: 25 additions & 0 deletions tests/ui/option_option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))))
}
}
8 changes: 7 additions & 1 deletion tests/ui/option_option.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a9b2cfa

Please sign in to comment.