Skip to content

Commit 5eb51c1

Browse files
Merge #4106
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 <[email protected]>
2 parents e833e03 + 0c01b4e commit 5eb51c1

File tree

2 files changed

+42
-1
lines changed

2 files changed

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

0 commit comments

Comments
 (0)