4106: Fix wrong substitution code r=matklad a=flodiebold

We need to shift in when we're substituting inside a binder.

This should fix #4053 (it doesn't fix the occasional overflow that also occurs on the Diesel codebase though).

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
This commit is contained in:
bors[bot] 2020-04-23 21:58:52 +00:00 committed by GitHub
commit 5eb51c1e60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 1 deletions

View File

@ -863,7 +863,7 @@ fn subst_bound_vars_at_depth(mut self, substs: &Substs, depth: DebruijnIndex) ->
&mut |ty, binders| {
if let &mut Ty::Bound(bound) = ty {
if bound.debruijn >= binders {
*ty = substs.0[bound.index].clone();
*ty = substs.0[bound.index].clone().shift_bound_vars(binders);
}
}
},

View File

@ -533,3 +533,44 @@ fn foo(b: Bar) {
"###
);
}
#[test]
fn issue_4053_diesel_where_clauses() {
assert_snapshot!(
infer(r#"
trait BoxedDsl<DB> {
type Output;
fn internal_into_boxed(self) -> Self::Output;
}
struct SelectStatement<From, Select, Distinct, Where, Order, LimitOffset, GroupBy, Locking> {
order: Order,
}
trait QueryFragment<DB: Backend> {}
trait Into<T> { fn into(self) -> T; }
impl<F, S, D, W, O, LOf, DB> BoxedDsl<DB>
for SelectStatement<F, S, D, W, O, LOf, G>
where
O: Into<dyn QueryFragment<DB>>,
{
type Output = XXX;
fn internal_into_boxed(self) -> Self::Output {
self.order.into();
}
}
"#),
@r###"
[66; 70) 'self': Self
[268; 272) 'self': Self
[467; 471) 'self': SelectStatement<F, S, D, W, O, LOf, {unknown}, {unknown}>
[489; 523) '{ ... }': ()
[499; 503) 'self': SelectStatement<F, S, D, W, O, LOf, {unknown}, {unknown}>
[499; 509) 'self.order': O
[499; 516) 'self.o...into()': dyn QueryFragment<DB>
"###
);
}