mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 23:20:39 +00:00
option_option test case #4298
This commit is contained in:
parent
1831385ff0
commit
29d043683e
2 changed files with 32 additions and 1 deletions
|
@ -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"))))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue