Skip to content

Commit dc524eb

Browse files
committed
Correctly instantiate where clauses on GAT impl values
1 parent fcd7fe2 commit dc524eb

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/rules.rs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use cast::{Cast, Caster};
22
use fold::shift::Shift;
3+
use fold::Subst;
34
use ir::{self, ToParameter};
45
use std::iter;
56

@@ -192,20 +193,35 @@ impl ir::AssociatedTyValue {
192193
.cloned()
193194
.collect();
194195

196+
let impl_trait_ref = impl_datum.binders
197+
.value
198+
.trait_ref
199+
.trait_ref()
200+
.up_shift(self.value.len());
201+
202+
let all_parameters: Vec<_> =
203+
self.value.binders
204+
.iter()
205+
.zip(0..)
206+
.map(|p| p.to_parameter())
207+
.chain(impl_trait_ref.parameters.iter().cloned())
208+
.collect();
209+
195210
// Assemble the full list of conditions for projection to be valid.
196211
// This comes in two parts, marked as (1) and (2) in example above:
197212
//
198213
// 1. require that the trait is implemented
199214
// 2. any where-clauses from the `type` declaration in the impl
200-
let impl_trait_ref = impl_datum
201-
.binders
202-
.value
203-
.trait_ref
204-
.trait_ref()
205-
.up_shift(self.value.len());
215+
let where_clauses =
216+
associated_ty.where_clauses
217+
.iter()
218+
.map(|wc| Subst::apply(&all_parameters, wc))
219+
.casted();
220+
206221
let conditions: Vec<ir::Goal> =
207-
iter::once(impl_trait_ref.clone().cast())
208-
.chain(associated_ty.where_clauses.iter().cloned().casted()).collect();
222+
where_clauses
223+
.chain(Some(impl_trait_ref.clone().cast()))
224+
.collect();
209225

210226
// Bound parameters + `Self` type of the trait-ref
211227
let parameters: Vec<_> = {

0 commit comments

Comments
 (0)