Skip to content

Commit 79cf412

Browse files
committed
Imrpove unwrap_or_else_default
1 parent 9ae4043 commit 79cf412

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

clippy_lints/src/methods/unwrap_or_else_default.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
33
use super::UNWRAP_OR_ELSE_DEFAULT;
44
use clippy_utils::{
5-
diagnostics::span_lint_and_sugg, is_trait_item, source::snippet_with_applicability, ty::is_type_diagnostic_item,
5+
diagnostics::span_lint_and_sugg, is_default_equivalent, is_trait_item, source::snippet_with_applicability,
6+
ty::is_type_diagnostic_item,
67
};
78
use rustc_errors::Applicability;
89
use rustc_hir as hir;
@@ -24,7 +25,7 @@ pub(super) fn check<'tcx>(
2425

2526
if_chain! {
2627
if is_option || is_result;
27-
if is_trait_item(cx, u_arg, sym::Default);
28+
if is_trait_item(cx, u_arg, sym::Default) || is_default_equivalent(cx, u_arg);
2829
then {
2930
let mut applicability = Applicability::MachineApplicable;
3031

tests/ui/unwrap_or_else_default.fixed

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ fn unwrap_or_else_default() {
6666

6767
let with_default_type = Some(1);
6868
with_default_type.unwrap_or_default();
69+
70+
let with_default_type: Option<Vec<u64>> = None;
71+
with_default_type.unwrap_or_default();
6972
}
7073

7174
fn main() {}

tests/ui/unwrap_or_else_default.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ fn unwrap_or_else_default() {
6666

6767
let with_default_type = Some(1);
6868
with_default_type.unwrap_or_else(u64::default);
69+
70+
let with_default_type: Option<Vec<u64>> = None;
71+
with_default_type.unwrap_or_else(Vec::new);
6972
}
7073

7174
fn main() {}

0 commit comments

Comments
 (0)