Imrpove unwrap_or_else_default

This commit is contained in:
Piotr Mikulski 2021-12-23 19:13:57 -08:00
parent 9ae40436d2
commit 79cf41297a
3 changed files with 9 additions and 2 deletions

View file

@ -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;

View file

@ -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() {}

View file

@ -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() {}