//@compile-flags: -Zdeduplicate-diagnostics=yes #![deny(clippy::option_option)] #![allow(clippy::unnecessary_wraps)] const C: Option> = None; //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum if static S: Option> = None; //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum if fn input(_: Option>) {} //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum if fn output() -> Option> { //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum if None } fn output_nested() -> Vec>> { //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum if vec![None] } // The lint only generates one warning for this fn output_nested_nested() -> Option>> { //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum if None } struct Struct { x: Option>, //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum } impl Struct { fn struct_fn() -> Option> { //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum None } } trait Trait { fn trait_fn() -> Option>; //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum } enum Enum { Tuple(Option>), //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum Struct { x: Option> }, //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum } // The lint allows this type OptionOption = Option>; // The lint allows this fn output_type_alias() -> OptionOption { None } // The line allows this impl Trait for Struct { fn trait_fn() -> Option> { None } } fn main() { input(None); output(); output_nested(); // The lint allows this let local: Option> = None; // 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)] foo: Option>>, //~^ ERROR: consider using `Option` instead of `Option>` or a custom } #[allow(clippy::option_option)] fn func<'a, D>(_: D) -> Result>>, D::Error> where D: Deserializer<'a>, { Ok(Some(Some(Cow::Borrowed("hi")))) } }