diff options
| author | Piotr Mikulski <piotr@near.org> | 2021-12-23 19:13:57 -0800 |
|---|---|---|
| committer | Piotr Mikulski <piotr@near.org> | 2021-12-23 19:16:05 -0800 |
| commit | 79cf41297af69b2e46be6ad77986ebe2a41a4667 (patch) | |
| tree | 65b2b921c8b6a06948838bf40c22d88c12387e19 | |
| parent | 9ae40436d2218f4b9dbdf231565f2732f1511c99 (diff) | |
| download | rust-79cf41297af69b2e46be6ad77986ebe2a41a4667.tar.gz rust-79cf41297af69b2e46be6ad77986ebe2a41a4667.zip | |
Imrpove `unwrap_or_else_default`
| -rw-r--r-- | clippy_lints/src/methods/unwrap_or_else_default.rs | 5 | ||||
| -rw-r--r-- | tests/ui/unwrap_or_else_default.fixed | 3 | ||||
| -rw-r--r-- | tests/ui/unwrap_or_else_default.rs | 3 |
3 files changed, 9 insertions, 2 deletions
diff --git a/clippy_lints/src/methods/unwrap_or_else_default.rs b/clippy_lints/src/methods/unwrap_or_else_default.rs index 276467b1dfd..4811048439c 100644 --- a/clippy_lints/src/methods/unwrap_or_else_default.rs +++ b/clippy_lints/src/methods/unwrap_or_else_default.rs @@ -2,7 +2,8 @@ use super::UNWRAP_OR_ELSE_DEFAULT; use clippy_utils::{ - diagnostics::span_lint_and_sugg, is_trait_item, source::snippet_with_applicability, ty::is_type_diagnostic_item, + diagnostics::span_lint_and_sugg, is_default_equivalent, is_trait_item, source::snippet_with_applicability, + ty::is_type_diagnostic_item, }; use rustc_errors::Applicability; use rustc_hir as hir; @@ -24,7 +25,7 @@ pub(super) fn check<'tcx>( if_chain! { if is_option || is_result; - if is_trait_item(cx, u_arg, sym::Default); + if is_trait_item(cx, u_arg, sym::Default) || is_default_equivalent(cx, u_arg); then { let mut applicability = Applicability::MachineApplicable; diff --git a/tests/ui/unwrap_or_else_default.fixed b/tests/ui/unwrap_or_else_default.fixed index 7ac3f426c97..5849dc4cebb 100644 --- a/tests/ui/unwrap_or_else_default.fixed +++ b/tests/ui/unwrap_or_else_default.fixed @@ -66,6 +66,9 @@ fn unwrap_or_else_default() { let with_default_type = Some(1); with_default_type.unwrap_or_default(); + + let with_default_type: Option<Vec<u64>> = None; + with_default_type.unwrap_or_default(); } fn main() {} diff --git a/tests/ui/unwrap_or_else_default.rs b/tests/ui/unwrap_or_else_default.rs index 82b727a039e..d55664990ae 100644 --- a/tests/ui/unwrap_or_else_default.rs +++ b/tests/ui/unwrap_or_else_default.rs @@ -66,6 +66,9 @@ fn unwrap_or_else_default() { let with_default_type = Some(1); with_default_type.unwrap_or_else(u64::default); + + let with_default_type: Option<Vec<u64>> = None; + with_default_type.unwrap_or_else(Vec::new); } fn main() {} |
