@@ -16,7 +16,7 @@ use rustc_type_ir::{
1616use smallvec:: SmallVec ;
1717
1818use crate :: {
19- ImplTraitId , all_super_traits ,
19+ ImplTraitId ,
2020 db:: { HirDatabase , InternedOpaqueTyId } ,
2121 lower_nextsolver:: associated_ty_item_bounds,
2222 next_solver:: {
@@ -53,13 +53,22 @@ pub fn dyn_compatibility(
5353 db : & dyn HirDatabase ,
5454 trait_ : TraitId ,
5555) -> Option < DynCompatibilityViolation > {
56- for super_trait in all_super_traits ( db, trait_) . into_iter ( ) . skip ( 1 ) . rev ( ) {
57- if db. dyn_compatibility_of_trait ( super_trait) . is_some ( ) {
58- return Some ( DynCompatibilityViolation :: HasNonCompatibleSuperTrait ( super_trait) ) ;
56+ let interner = DbInterner :: new_with ( db, Some ( trait_. krate ( db) ) , None ) ;
57+ for super_trait in elaborate:: supertrait_def_ids ( interner, SolverDefId :: TraitId ( trait_) ) {
58+ let super_trait = match super_trait {
59+ SolverDefId :: TraitId ( id) => id,
60+ _ => unreachable ! ( ) ,
61+ } ;
62+ if let Some ( v) = db. dyn_compatibility_of_trait ( super_trait) {
63+ return if super_trait == trait_ {
64+ Some ( v)
65+ } else {
66+ Some ( DynCompatibilityViolation :: HasNonCompatibleSuperTrait ( super_trait) )
67+ } ;
5968 }
6069 }
6170
62- db . dyn_compatibility_of_trait ( trait_ )
71+ None
6372}
6473
6574pub fn dyn_compatibility_with_callback < F > (
@@ -70,7 +79,13 @@ pub fn dyn_compatibility_with_callback<F>(
7079where
7180 F : FnMut ( DynCompatibilityViolation ) -> ControlFlow < ( ) > ,
7281{
73- for super_trait in all_super_traits ( db, trait_) . into_iter ( ) . skip ( 1 ) . rev ( ) {
82+ let interner = DbInterner :: new_with ( db, Some ( trait_. krate ( db) ) , None ) ;
83+ for super_trait in elaborate:: supertrait_def_ids ( interner, SolverDefId :: TraitId ( trait_) ) . skip ( 1 )
84+ {
85+ let super_trait = match super_trait {
86+ SolverDefId :: TraitId ( id) => id,
87+ _ => unreachable ! ( ) ,
88+ } ;
7489 if db. dyn_compatibility_of_trait ( super_trait) . is_some ( ) {
7590 cb ( DynCompatibilityViolation :: HasNonCompatibleSuperTrait ( trait_) ) ?;
7691 }
@@ -225,6 +240,7 @@ fn contains_illegal_self_type_reference<'db, T: rustc_type_ir::TypeVisitable<DbI
225240 & mut self ,
226241 ty : <DbInterner < ' db > as rustc_type_ir:: Interner >:: Ty ,
227242 ) -> Self :: Result {
243+ let interner = DbInterner :: new_with ( self . db , None , None ) ;
228244 match ty. kind ( ) {
229245 rustc_type_ir:: TyKind :: Param ( param) if param. index == 0 => ControlFlow :: Break ( ( ) ) ,
230246 rustc_type_ir:: TyKind :: Param ( _) => ControlFlow :: Continue ( ( ) ) ,
@@ -238,7 +254,17 @@ fn contains_illegal_self_type_reference<'db, T: rustc_type_ir::TypeVisitable<DbI
238254 _ => unreachable ! ( ) ,
239255 } ;
240256 if self . super_traits . is_none ( ) {
241- self . super_traits = Some ( all_super_traits ( self . db , self . trait_ ) ) ;
257+ self . super_traits = Some (
258+ elaborate:: supertrait_def_ids (
259+ interner,
260+ SolverDefId :: TraitId ( self . trait_ ) ,
261+ )
262+ . map ( |super_trait| match super_trait {
263+ SolverDefId :: TraitId ( id) => id,
264+ _ => unreachable ! ( ) ,
265+ } )
266+ . collect ( ) ,
267+ )
242268 }
243269 if self . super_traits . as_ref ( ) . is_some_and ( |s| s. contains ( & trait_) ) {
244270 ControlFlow :: Continue ( ( ) )
0 commit comments