Skip to content

Commit be9f62a

Browse files
committed
Add binders to OpaqueTyDatumBound bounds
1 parent 202d803 commit be9f62a

File tree

3 files changed

+55
-43
lines changed

3 files changed

+55
-43
lines changed

chalk-integration/src/lowering.rs

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use chalk_ir::cast::{Cast, Caster};
22
use chalk_ir::interner::ChalkIr;
33
use chalk_ir::{
4-
self, AssocTypeId, Binders, BoundVar, ClausePriority, DebruijnIndex, ImplId, OpaqueTyId,
4+
self, AssocTypeId, BoundVar, ClausePriority, DebruijnIndex, ImplId, OpaqueTyId,
55
QuantifiedWhereClauses, StructId, Substitution, TraitId,
66
};
77
use chalk_parse::ast::*;
88
use chalk_rust_ir as rust_ir;
99
use chalk_rust_ir::{
10-
Anonymize, AssociatedTyValueId, IntoWhereClauses, OpaqueTyBound, OpaqueTyDatum, ToParameter,
10+
Anonymize, AssociatedTyValueId, IntoWhereClauses, OpaqueTyDatum, OpaqueTyDatumBound,
11+
ToParameter,
1112
};
1213
use lalrpop_intern::intern;
1314
use std::collections::BTreeMap;
@@ -390,25 +391,30 @@ impl LowerProgram for Program {
390391
let binders = empty_env.in_binders(parameter_kinds, |env| {
391392
let hidden_ty = opaque_ty.ty.lower(&env)?;
392393

393-
let hidden_ty_bounds: Binders<Vec<Binders<_>>> = env.in_binders(
394-
Some(chalk_ir::ParameterKind::Ty(intern(FIXME_SELF))),
395-
|env1| {
396-
let interner = env1.interner();
397-
Ok(opaque_ty
398-
.bounds
399-
.lower(&env1)?
400-
.iter()
401-
.flat_map(|qil| {
402-
qil.into_where_clauses(interner, hidden_ty.clone())
403-
})
404-
.collect())
405-
},
406-
)?;
407-
408-
Ok(OpaqueTyBound {
409-
hidden_ty,
410-
bounds: hidden_ty_bounds.skip_binders().clone(),
411-
})
394+
let bounds: chalk_ir::Binders<Vec<chalk_ir::Binders<_>>> = env
395+
.in_binders(
396+
Some(chalk_ir::ParameterKind::Ty(intern(FIXME_SELF))),
397+
|env1| {
398+
let interner = env1.interner();
399+
Ok(opaque_ty
400+
.bounds
401+
.lower(&env1)?
402+
.iter()
403+
.flat_map(|qil| {
404+
qil.into_where_clauses(
405+
interner,
406+
chalk_ir::TyData::BoundVar(BoundVar::new(
407+
DebruijnIndex::INNERMOST,
408+
0,
409+
))
410+
.intern(interner),
411+
)
412+
})
413+
.collect())
414+
},
415+
)?;
416+
417+
Ok(OpaqueTyDatumBound { hidden_ty, bounds })
412418
})?;
413419

414420
opaque_ty_data.insert(

chalk-rust-ir/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,16 +517,16 @@ pub struct OpaqueTyDatum<I: Interner> {
517517
pub opaque_ty_id: OpaqueTyId<I>,
518518

519519
/// The type bound to when revealed.
520-
pub bound: Binders<OpaqueTyBound<I>>,
520+
pub bound: Binders<OpaqueTyDatumBound<I>>,
521521
}
522522

523523
#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, HasInterner)]
524-
pub struct OpaqueTyBound<I: Interner> {
524+
pub struct OpaqueTyDatumBound<I: Interner> {
525525
/// The value for the "hidden type" for `opaque type Foo = ...`
526526
pub hidden_ty: Ty<I>,
527527

528528
/// Trait bounds for the opaque type.
529-
pub bounds: Vec<QuantifiedWhereClause<I>>,
529+
pub bounds: Binders<Vec<QuantifiedWhereClause<I>>>,
530530
}
531531

532532
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]

chalk-solve/src/clauses/program_clauses.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -166,27 +166,33 @@ impl<I: Interner> ToProgramClauses<I> for OpaqueTyDatum<I> {
166166
}
167167
.cast(interner),
168168
));
169-
});
170169

171-
let opaque_ty_bound = &self.bound.skip_binders();
172-
for bound in &opaque_ty_bound.bounds {
173-
// Implemented(!T<..>: Bound).
174-
builder.push_fact(bound.skip_binders().clone().into_well_formed_goal(interner));
175-
}
170+
for bound in &opaque_ty_bound.bounds {
171+
// Implemented(!T<..>: Bound).
172+
builder.push_binders(&bound, |builder, bound| {
173+
builder.push_binders(&bound, |builder, bound| {
174+
builder.push_fact(bound.into_well_formed_goal(interner));
175+
});
176+
});
177+
}
176178

177-
for auto_trait_id in builder.db.auto_traits() {
178-
// Implemented(!T<..>: AutoTrait) :- Implemented(HiddenTy: AutoTrait).
179-
builder.push_clause(
180-
TraitRef {
181-
trait_id: auto_trait_id,
182-
substitution: Substitution::from1(interner, alias_ty.clone()),
183-
},
184-
iter::once(TraitRef {
185-
trait_id: auto_trait_id,
186-
substitution: Substitution::from1(interner, opaque_ty_bound.hidden_ty.clone()),
187-
}),
188-
);
189-
}
179+
for auto_trait_id in builder.db.auto_traits() {
180+
// Implemented(!T<..>: AutoTrait) :- Implemented(HiddenTy: AutoTrait).
181+
builder.push_clause(
182+
TraitRef {
183+
trait_id: auto_trait_id,
184+
substitution: Substitution::from1(interner, alias_ty.clone()),
185+
},
186+
iter::once(TraitRef {
187+
trait_id: auto_trait_id,
188+
substitution: Substitution::from1(
189+
interner,
190+
opaque_ty_bound.hidden_ty.clone(),
191+
),
192+
}),
193+
);
194+
}
195+
});
190196
}
191197
}
192198

0 commit comments

Comments
 (0)