From db3423f46a4e54f0f5aef16da2e263fee29770b5 Mon Sep 17 00:00:00 2001 From: Simon Farnsworth Date: Thu, 2 Apr 2020 10:03:15 +0100 Subject: [PATCH 1/4] Improve docs for option_option Hint about using tri-state enums to replace legitimate uses of `Option>` --- clippy_lints/src/types.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index b21c373926591..6b63f2b1f0a22 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -99,14 +99,32 @@ declare_clippy_lint! { /// represents an optional optional value which is logically the same thing as an optional /// value but has an unneeded extra level of wrapping. /// + /// If you have a case where `Some(Some(_))`, `Some(None)` and `None` are distinct cases, + /// consider a custom `enum` instead, with clear names for each case. + /// /// **Known problems:** None. /// /// **Example** - /// ```rust - /// fn x() -> Option> { + /// ```rust,ignore + /// fn get_node_data(n: Node) -> Option> { /// None /// } /// ``` + /// + /// Better: + /// + /// ```rust,ignore + /// pub enum Contents { + /// Data(Vec), // Was Some(Some(Vec)) + /// NotYetFetched, // Was Some(None) + /// None, // Was None + /// } + /// + /// fn get_node_data(n: Node) -> Contents { + /// Contents::None + /// } + /// ``` + /// pub OPTION_OPTION, pedantic, "usage of `Option>`" From f3f1babc1b226bc0083f5941468025f5008f428b Mon Sep 17 00:00:00 2001 From: Simon Farnsworth Date: Thu, 2 Apr 2020 14:28:25 +0100 Subject: [PATCH 2/4] Update types.rs --- clippy_lints/src/types.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 6b63f2b1f0a22..2ec58c04cd625 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -106,7 +106,7 @@ declare_clippy_lint! { /// /// **Example** /// ```rust,ignore - /// fn get_node_data(n: Node) -> Option> { + /// fn get_data() -> Option> { /// None /// } /// ``` @@ -120,7 +120,7 @@ declare_clippy_lint! { /// None, // Was None /// } /// - /// fn get_node_data(n: Node) -> Contents { + /// fn get_data() -> Contents { /// Contents::None /// } /// ``` From 50ecc1254130d0d69a968f99c1aa8b150bf1662e Mon Sep 17 00:00:00 2001 From: Simon Farnsworth Date: Thu, 2 Apr 2020 14:29:08 +0100 Subject: [PATCH 3/4] Update types.rs --- clippy_lints/src/types.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 2ec58c04cd625..50a64516e4bd5 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -105,7 +105,7 @@ declare_clippy_lint! { /// **Known problems:** None. /// /// **Example** - /// ```rust,ignore + /// ```rust /// fn get_data() -> Option> { /// None /// } @@ -113,7 +113,7 @@ declare_clippy_lint! { /// /// Better: /// - /// ```rust,ignore + /// ```rust /// pub enum Contents { /// Data(Vec), // Was Some(Some(Vec)) /// NotYetFetched, // Was Some(None) From 5f8b696e2e76374fe600ee0f0e444e94215239b6 Mon Sep 17 00:00:00 2001 From: Simon Farnsworth Date: Thu, 2 Apr 2020 14:30:13 +0100 Subject: [PATCH 4/4] Update clippy_lints/src/types.rs Co-Authored-By: Philipp Krones --- clippy_lints/src/types.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 50a64516e4bd5..8c151f2277c1b 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -124,7 +124,6 @@ declare_clippy_lint! { /// Contents::None /// } /// ``` - /// pub OPTION_OPTION, pedantic, "usage of `Option>`"