Skip to content

Commit 33f7ffe

Browse files
committed
fix: More precise clause filtering for explicit_*_predicates_of
1 parent e38a7b4 commit 33f7ffe

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

crates/hir-ty/src/next_solver/interner.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,16 +1330,23 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
13301330
self,
13311331
def_id: Self::TraitId,
13321332
) -> 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+
13331338
let predicates: Vec<(Clause<'db>, Span)> = self
13341339
.db()
13351340
.generic_predicates_ns(def_id.0.into())
13361341
.iter()
13371342
.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,
13431350
})
13441351
.cloned()
13451352
.map(|p| (p, Span::dummy()))
@@ -1367,7 +1374,14 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
13671374
.generic_predicates_ns(def_id.try_into().unwrap())
13681375
.iter()
13691376
.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.
13711385
_ => true,
13721386
})
13731387
.cloned()

0 commit comments

Comments
 (0)