2024-03-07 10:19:29 -06:00
|
|
|
//@compile-flags: -Zdeduplicate-diagnostics=yes
|
|
|
|
|
2020-04-01 14:15:21 -05:00
|
|
|
#![deny(clippy::option_option)]
|
2020-11-23 06:51:04 -06:00
|
|
|
#![allow(clippy::unnecessary_wraps)]
|
2020-04-01 14:15:21 -05:00
|
|
|
|
2021-04-08 10:50:13 -05:00
|
|
|
const C: Option<Option<i32>> = None;
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if
|
2021-04-08 10:50:13 -05:00
|
|
|
static S: Option<Option<i32>> = None;
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if
|
2021-04-08 10:50:13 -05:00
|
|
|
|
2018-12-09 16:26:16 -06:00
|
|
|
fn input(_: Option<Option<u8>>) {}
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if
|
2017-12-25 23:25:13 -06:00
|
|
|
|
|
|
|
fn output() -> Option<Option<u8>> {
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if
|
2017-12-25 23:25:13 -06:00
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
fn output_nested() -> Vec<Option<Option<u8>>> {
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if
|
2017-12-25 23:25:13 -06:00
|
|
|
vec![None]
|
|
|
|
}
|
|
|
|
|
|
|
|
// The lint only generates one warning for this
|
|
|
|
fn output_nested_nested() -> Option<Option<Option<u8>>> {
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if
|
2017-12-25 23:25:13 -06:00
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Struct {
|
|
|
|
x: Option<Option<u8>>,
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum
|
2017-12-25 23:25:13 -06:00
|
|
|
}
|
|
|
|
|
2018-01-19 00:10:09 -06:00
|
|
|
impl Struct {
|
|
|
|
fn struct_fn() -> Option<Option<u8>> {
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum
|
2018-01-19 00:10:09 -06:00
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trait Trait {
|
|
|
|
fn trait_fn() -> Option<Option<u8>>;
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum
|
2018-01-19 00:10:09 -06:00
|
|
|
}
|
|
|
|
|
2017-12-25 23:25:13 -06:00
|
|
|
enum Enum {
|
|
|
|
Tuple(Option<Option<u8>>),
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum
|
2018-12-09 16:26:16 -06:00
|
|
|
Struct { x: Option<Option<u8>> },
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum
|
2017-12-25 23:25:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// The lint allows this
|
|
|
|
type OptionOption = Option<Option<u32>>;
|
|
|
|
|
|
|
|
// The lint allows this
|
|
|
|
fn output_type_alias() -> OptionOption {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
2018-01-19 00:10:09 -06:00
|
|
|
// The line allows this
|
|
|
|
impl Trait for Struct {
|
|
|
|
fn trait_fn() -> Option<Option<u8>> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-25 23:25:13 -06:00
|
|
|
fn main() {
|
|
|
|
input(None);
|
|
|
|
output();
|
|
|
|
output_nested();
|
|
|
|
|
|
|
|
// The lint allows this
|
|
|
|
let local: Option<Option<u8>> = None;
|
|
|
|
|
|
|
|
// The lint allows this
|
|
|
|
let expr = Some(Some(true));
|
|
|
|
}
|
2020-05-28 08:45:24 -05:00
|
|
|
|
|
|
|
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<Option<Cow<'a, str>>>,
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: consider using `Option<T>` instead of `Option<Option<T>>` or a custom
|
2020-05-28 08:45:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[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"))))
|
|
|
|
}
|
|
|
|
}
|