@@ -215,7 +215,8 @@ mod iterator {
215215 if filter. self_type_filter . allow_self_ty ( ct. self_ty . type_at ( 0 ) )
216216 && filter
217217 . polarity_filter
218- . allow_polarity ( ClausePolarity :: Positive ) =>
218+ . allow_polarity ( ClausePolarity :: Positive )
219+ && filter. trait_filter . allow_any_compressed_trait_ref ( ct. compressed_trait_refs ) =>
219220 {
220221 self . decompression_in_progress = ct. compressed_trait_refs ;
221222 self . self_ty = Some ( ct. self_ty ) ;
@@ -602,11 +603,19 @@ mod trait_filter {
602603 I : Interner ,
603604 {
604605 fn allow_clause ( & self , clause : TraitClause < I > ) -> bool ;
606+ /// Returns the defid of the trait if this filter allows the given `trait_ref`.
607+ /// Note that `trait_ref` should have only a single bit set.
605608 fn allow_compressed_trait_ref_single_bit (
606609 & self ,
607610 cx : I ,
608611 trait_ref : CompressedTraitRefs ,
609612 ) -> Option < I :: TraitId > ;
613+ /// returns true if this trait filter *might* allow any
614+ /// of the traits in `trait_ref` to match.
615+ fn allow_any_compressed_trait_ref (
616+ & self ,
617+ trait_ref : CompressedTraitRefs ,
618+ ) -> bool ;
610619 }
611620
612621 impl < I > TraitFilter < I > for ( )
@@ -626,9 +635,15 @@ mod trait_filter {
626635 ) -> Option < I :: TraitId > {
627636 Some ( cx. require_trait_lang_item ( trait_ref. lang_item_from_single_bit ( ) ) )
628637 }
638+
639+ fn allow_any_compressed_trait_ref (
640+ & self ,
641+ _trait_ref : CompressedTraitRefs ,
642+ ) -> bool {
643+ true
644+ }
629645 }
630646
631- // TODO: use bit operations to test an entire compressed clause against a single filter.
632647 pub struct TargetTrait < I >
633648 where
634649 I : Interner ,
@@ -668,6 +683,21 @@ mod trait_filter {
668683 None
669684 }
670685 }
686+
687+ fn allow_any_compressed_trait_ref (
688+ & self ,
689+ trait_ref : CompressedTraitRefs ,
690+ ) -> bool {
691+ if let Some ( target) = self . lang_item_compressed {
692+ // only if the given `trait_ref` has the bit set that corresponds to `target`, do we
693+ // return true. Otherwise we can skip this compressed trait instantly.
694+ trait_ref. contains ( target)
695+ } else {
696+ // When looking for a normal trait, any compressed clause can never match so we
697+ // return false unconditionally.
698+ false
699+ }
700+ }
671701 }
672702}
673703
0 commit comments