@@ -1330,16 +1330,23 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
1330
1330
self ,
1331
1331
def_id : Self :: TraitId ,
1332
1332
) -> EarlyBinder < Self , impl IntoIterator < Item = ( Self :: Clause , Self :: Span ) > > {
1333
+ let is_self = |ty : Ty < ' db > | match ty. kind ( ) {
1334
+ rustc_type_ir:: TyKind :: Param ( param) => param. index == 0 ,
1335
+ _ => false ,
1336
+ } ;
1337
+
1333
1338
let predicates: Vec < ( Clause < ' db > , Span ) > = self
1334
1339
. db ( )
1335
1340
. generic_predicates_ns ( def_id. 0 . into ( ) )
1336
1341
. iter ( )
1337
1342
. filter ( |p| match p. kind ( ) . skip_binder ( ) {
1338
- rustc_type_ir:: ClauseKind :: Trait ( tr) => match tr. self_ty ( ) . kind ( ) {
1339
- rustc_type_ir:: TyKind :: Param ( param) => param. index == 0 ,
1340
- _ => false ,
1341
- } ,
1342
- _ => true ,
1343
+ // rustc has the following assertion:
1344
+ // https://github.com/rust-lang/rust/blob/52618eb338609df44978b0ca4451ab7941fd1c7a/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs#L525-L608
1345
+ rustc_type_ir:: ClauseKind :: Trait ( it) => is_self ( it. self_ty ( ) ) ,
1346
+ rustc_type_ir:: ClauseKind :: TypeOutlives ( it) => is_self ( it. 0 ) ,
1347
+ rustc_type_ir:: ClauseKind :: Projection ( it) => is_self ( it. self_ty ( ) ) ,
1348
+ rustc_type_ir:: ClauseKind :: HostEffect ( it) => is_self ( it. self_ty ( ) ) ,
1349
+ _ => false ,
1343
1350
} )
1344
1351
. cloned ( )
1345
1352
. map ( |p| ( p, Span :: dummy ( ) ) )
@@ -1367,7 +1374,14 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
1367
1374
. generic_predicates_ns ( def_id. try_into ( ) . unwrap ( ) )
1368
1375
. iter ( )
1369
1376
. filter ( |p| match p. kind ( ) . skip_binder ( ) {
1370
- rustc_type_ir:: ClauseKind :: Trait ( tr) => is_self_or_assoc ( tr. self_ty ( ) ) ,
1377
+ rustc_type_ir:: ClauseKind :: Trait ( it) => is_self_or_assoc ( it. self_ty ( ) ) ,
1378
+ rustc_type_ir:: ClauseKind :: TypeOutlives ( it) => is_self_or_assoc ( it. 0 ) ,
1379
+ rustc_type_ir:: ClauseKind :: Projection ( it) => is_self_or_assoc ( it. self_ty ( ) ) ,
1380
+ rustc_type_ir:: ClauseKind :: HostEffect ( it) => is_self_or_assoc ( it. self_ty ( ) ) ,
1381
+ // FIXME: Not sure is this correct to allow other clauses but we might replace
1382
+ // `generic_predicates_ns` query here with something closer to rustc's
1383
+ // `implied_bounds_with_filter`, which is more granular lowering than this
1384
+ // "lower at once and then filter" implementation.
1371
1385
_ => true ,
1372
1386
} )
1373
1387
. cloned ( )
0 commit comments