@@ -637,7 +637,7 @@ pub fn can_mut_borrow_both(cx: &LateContext<'_>, e1: &Expr<'_>, e2: &Expr<'_>) -
637
637
638
638
/// Returns true if the `def_id` associated with the `path` is recognized as a "default-equivalent"
639
639
/// constructor from the std library
640
- pub fn is_default_equivalent_ctor ( cx : & LateContext < ' _ > , def_id : DefId , path : & QPath < ' _ > ) -> bool {
640
+ fn is_default_equivalent_ctor ( cx : & LateContext < ' _ > , def_id : DefId , path : & QPath < ' _ > ) -> bool {
641
641
let std_types_symbols = & [
642
642
sym:: String ,
643
643
sym:: Vec ,
@@ -664,6 +664,22 @@ pub fn is_default_equivalent_ctor(cx: &LateContext<'_>, def_id: DefId, path: &QP
664
664
false
665
665
}
666
666
667
+ /// Return true if the expr is equal to `Default::default` when evaluated.
668
+ pub fn is_default_equivalent_call ( cx : & LateContext < ' _ > , repl_func : & Expr < ' _ > ) -> bool {
669
+ if_chain ! {
670
+ if let hir:: ExprKind :: Path ( ref repl_func_qpath) = repl_func. kind;
671
+ if let Some ( repl_def_id) = cx. qpath_res( repl_func_qpath, repl_func. hir_id) . opt_def_id( ) ;
672
+ if is_diag_trait_item( cx, repl_def_id, sym:: Default )
673
+ || is_default_equivalent_ctor( cx, repl_def_id, repl_func_qpath) ;
674
+ then {
675
+ true
676
+ }
677
+ else {
678
+ false
679
+ }
680
+ }
681
+ }
682
+
667
683
/// Returns true if the expr is equal to `Default::default()` of it's type when evaluated.
668
684
/// It doesn't cover all cases, for example indirect function calls (some of std
669
685
/// functions are supported) but it is the best we have.
@@ -686,18 +702,7 @@ pub fn is_default_equivalent(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
686
702
false
687
703
}
688
704
} ,
689
- ExprKind :: Call ( repl_func, _) => if_chain ! {
690
- if let ExprKind :: Path ( ref repl_func_qpath) = repl_func. kind;
691
- if let Some ( repl_def_id) = cx. qpath_res( repl_func_qpath, repl_func. hir_id) . opt_def_id( ) ;
692
- if is_diag_trait_item( cx, repl_def_id, sym:: Default )
693
- || is_default_equivalent_ctor( cx, repl_def_id, repl_func_qpath) ;
694
- then {
695
- true
696
- }
697
- else {
698
- false
699
- }
700
- } ,
705
+ ExprKind :: Call ( repl_func, _) => is_default_equivalent_call ( cx, repl_func) ,
701
706
ExprKind :: Path ( qpath) => is_lang_ctor ( cx, qpath, OptionNone ) ,
702
707
ExprKind :: AddrOf ( rustc_hir:: BorrowKind :: Ref , _, expr) => matches ! ( expr. kind, ExprKind :: Array ( [ ] ) ) ,
703
708
_ => false ,
0 commit comments