@@ -1712,6 +1712,7 @@ mod redundant_pattern_match {
1712
1712
use clippy_utils:: { is_lang_ctor, is_qpath_def_path, is_trait_method, paths} ;
1713
1713
use if_chain:: if_chain;
1714
1714
use rustc_ast:: ast:: LitKind ;
1715
+ use rustc_data_structures:: fx:: FxHashSet ;
1715
1716
use rustc_errors:: Applicability ;
1716
1717
use rustc_hir:: LangItem :: { OptionNone , OptionSome , PollPending , PollReady , ResultErr , ResultOk } ;
1717
1718
use rustc_hir:: {
@@ -1739,6 +1740,13 @@ mod redundant_pattern_match {
1739
1740
/// deallocate memory. For these types, and composites containing them, changing the drop order
1740
1741
/// won't result in any observable side effects.
1741
1742
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
+ }
1742
1750
if !ty. needs_drop ( cx. tcx , cx. param_env ) {
1743
1751
false
1744
1752
} else if !cx
@@ -1750,12 +1758,12 @@ mod redundant_pattern_match {
1750
1758
// This type doesn't implement drop, so no side effects here.
1751
1759
// Check if any component type has any.
1752
1760
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 ) ,
1755
1763
ty:: Adt ( adt, subs) => adt
1756
1764
. all_fields ( )
1757
1765
. 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 ) ) ,
1759
1767
_ => true ,
1760
1768
}
1761
1769
}
@@ -1772,7 +1780,7 @@ mod redundant_pattern_match {
1772
1780
{
1773
1781
// Check all of the generic arguments.
1774
1782
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 ) )
1776
1784
} else {
1777
1785
true
1778
1786
}
0 commit comments