@@ -1712,6 +1712,7 @@ mod redundant_pattern_match {
17121712 use clippy_utils:: { is_lang_ctor, is_qpath_def_path, is_trait_method, paths} ;
17131713 use if_chain:: if_chain;
17141714 use rustc_ast:: ast:: LitKind ;
1715+ use rustc_data_structures:: fx:: FxHashSet ;
17151716 use rustc_errors:: Applicability ;
17161717 use rustc_hir:: LangItem :: { OptionNone , OptionSome , PollPending , PollReady , ResultErr , ResultOk } ;
17171718 use rustc_hir:: {
@@ -1739,6 +1740,13 @@ mod redundant_pattern_match {
17391740 /// deallocate memory. For these types, and composites containing them, changing the drop order
17401741 /// won't result in any observable side effects.
17411742 fn type_needs_ordered_drop ( cx : & LateContext < ' tcx > , ty : Ty < ' tcx > ) -> bool {
1743+ type_needs_ordered_drop_inner ( cx, ty, & mut FxHashSet :: default ( ) )
1744+ }
1745+
1746+ fn type_needs_ordered_drop_inner ( cx : & LateContext < ' tcx > , ty : Ty < ' tcx > , seen : & mut FxHashSet < Ty < ' tcx > > ) -> bool {
1747+ if !seen. insert ( ty) {
1748+ return false ;
1749+ }
17421750 if !ty. needs_drop ( cx. tcx , cx. param_env ) {
17431751 false
17441752 } else if !cx
@@ -1750,12 +1758,12 @@ mod redundant_pattern_match {
17501758 // This type doesn't implement drop, so no side effects here.
17511759 // Check if any component type has any.
17521760 match ty. kind ( ) {
1753- ty:: Tuple ( _) => ty. tuple_fields ( ) . any ( |ty| type_needs_ordered_drop ( cx, ty) ) ,
1754- ty:: Array ( ty, _) => type_needs_ordered_drop ( cx, ty) ,
1761+ ty:: Tuple ( _) => ty. tuple_fields ( ) . any ( |ty| type_needs_ordered_drop_inner ( cx, ty, seen ) ) ,
1762+ ty:: Array ( ty, _) => type_needs_ordered_drop_inner ( cx, ty, seen ) ,
17551763 ty:: Adt ( adt, subs) => adt
17561764 . all_fields ( )
17571765 . map ( |f| f. ty ( cx. tcx , subs) )
1758- . any ( |ty| type_needs_ordered_drop ( cx, ty) ) ,
1766+ . any ( |ty| type_needs_ordered_drop_inner ( cx, ty, seen ) ) ,
17591767 _ => true ,
17601768 }
17611769 }
@@ -1772,7 +1780,7 @@ mod redundant_pattern_match {
17721780 {
17731781 // Check all of the generic arguments.
17741782 if let ty:: Adt ( _, subs) = ty. kind ( ) {
1775- subs. types ( ) . any ( |ty| type_needs_ordered_drop ( cx, ty) )
1783+ subs. types ( ) . any ( |ty| type_needs_ordered_drop_inner ( cx, ty, seen ) )
17761784 } else {
17771785 true
17781786 }
0 commit comments