@@ -16,7 +16,7 @@ use rustc_type_ir::{
16
16
use smallvec:: SmallVec ;
17
17
18
18
use crate :: {
19
- ImplTraitId , all_super_traits ,
19
+ ImplTraitId ,
20
20
db:: { HirDatabase , InternedOpaqueTyId } ,
21
21
lower_nextsolver:: associated_ty_item_bounds,
22
22
next_solver:: {
@@ -53,13 +53,22 @@ pub fn dyn_compatibility(
53
53
db : & dyn HirDatabase ,
54
54
trait_ : TraitId ,
55
55
) -> 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
+ } ;
59
68
}
60
69
}
61
70
62
- db . dyn_compatibility_of_trait ( trait_ )
71
+ None
63
72
}
64
73
65
74
pub fn dyn_compatibility_with_callback < F > (
@@ -70,7 +79,13 @@ pub fn dyn_compatibility_with_callback<F>(
70
79
where
71
80
F : FnMut ( DynCompatibilityViolation ) -> ControlFlow < ( ) > ,
72
81
{
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
+ } ;
74
89
if db. dyn_compatibility_of_trait ( super_trait) . is_some ( ) {
75
90
cb ( DynCompatibilityViolation :: HasNonCompatibleSuperTrait ( trait_) ) ?;
76
91
}
@@ -225,6 +240,7 @@ fn contains_illegal_self_type_reference<'db, T: rustc_type_ir::TypeVisitable<DbI
225
240
& mut self ,
226
241
ty : <DbInterner < ' db > as rustc_type_ir:: Interner >:: Ty ,
227
242
) -> Self :: Result {
243
+ let interner = DbInterner :: new_with ( self . db , None , None ) ;
228
244
match ty. kind ( ) {
229
245
rustc_type_ir:: TyKind :: Param ( param) if param. index == 0 => ControlFlow :: Break ( ( ) ) ,
230
246
rustc_type_ir:: TyKind :: Param ( _) => ControlFlow :: Continue ( ( ) ) ,
@@ -238,7 +254,17 @@ fn contains_illegal_self_type_reference<'db, T: rustc_type_ir::TypeVisitable<DbI
238
254
_ => unreachable ! ( ) ,
239
255
} ;
240
256
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
+ )
242
268
}
243
269
if self . super_traits . as_ref ( ) . is_some_and ( |s| s. contains ( & trait_) ) {
244
270
ControlFlow :: Continue ( ( ) )
0 commit comments