Skip to content

Commit f5bb062

Browse files
committed
Fix wrong substitution code
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).
1 parent 29bc218 commit f5bb062

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

crates/ra_hir_ty/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ pub trait TypeWalk {
863863
&mut |ty, binders| {
864864
if let &mut Ty::Bound(bound) = ty {
865865
if bound.debruijn >= binders {
866-
*ty = substs.0[bound.index].clone();
866+
*ty = substs.0[bound.index].clone().shift_bound_vars(binders);
867867
}
868868
}
869869
},

crates/ra_hir_ty/src/tests/regression.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,3 +533,45 @@ fn foo(b: Bar) {
533533
"###
534534
);
535535
}
536+
537+
#[test]
538+
fn issue_4053_diesel_where_clauses() {
539+
std::env::set_var("CHALK_DEBUG", "1");
540+
assert_snapshot!(
541+
infer(r#"
542+
trait BoxedDsl<DB> {
543+
type Output;
544+
fn internal_into_boxed(self) -> Self::Output;
545+
}
546+
547+
struct SelectStatement<From, Select, Distinct, Where, Order, LimitOffset, GroupBy, Locking> {
548+
order: Order,
549+
}
550+
551+
trait QueryFragment<DB: Backend> {}
552+
553+
trait Into<T> { fn into(self) -> T; }
554+
555+
impl<F, S, D, W, O, LOf, DB> BoxedDsl<DB>
556+
for SelectStatement<F, S, D, W, O, LOf, G>
557+
where
558+
O: Into<dyn QueryFragment<DB>>,
559+
{
560+
type Output = XXX;
561+
562+
fn internal_into_boxed(self) -> Self::Output {
563+
self.order.into();
564+
}
565+
}
566+
"#),
567+
@r###"
568+
[66; 70) 'self': Self
569+
[268; 272) 'self': Self
570+
[467; 471) 'self': SelectStatement<F, S, D, W, O, LOf, {unknown}, {unknown}>
571+
[489; 523) '{ ... }': ()
572+
[499; 503) 'self': SelectStatement<F, S, D, W, O, LOf, {unknown}, {unknown}>
573+
[499; 509) 'self.order': O
574+
[499; 516) 'self.o...into()': dyn QueryFragment<DB>
575+
"###
576+
);
577+
}

0 commit comments

Comments
 (0)