]> git.lizzy.rs Git - rust.git/commitdiff
Fix wrong substitution code
authorFlorian Diebold <flodiebold@gmail.com>
Thu, 23 Apr 2020 18:50:14 +0000 (20:50 +0200)
committerFlorian Diebold <flodiebold@gmail.com>
Thu, 23 Apr 2020 21:53:08 +0000 (23:53 +0200)
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).

crates/ra_hir_ty/src/lib.rs
crates/ra_hir_ty/src/tests/regression.rs

index a4b8d66837ccd10c528a6707914d438857b43445..279c06d65d197e2ed8bc97e4a50e691fb850964c 100644 (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);
                     }
                 }
             },
index 61284d67220d50176eea2cddcaed4cfad4c96598..61a6801fc645c0cb9a8579d06bc1c78338c8de66 100644 (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>
+    "###
+    );
+}