]> git.lizzy.rs Git - rust.git/commitdiff
Fix Chalk panic
authorFlorian Diebold <florian.diebold@freiheit.com>
Mon, 6 Apr 2020 15:24:08 +0000 (17:24 +0200)
committerFlorian Diebold <florian.diebold@freiheit.com>
Mon, 6 Apr 2020 15:26:26 +0000 (17:26 +0200)
Fixes #3865. Basically I forgot to shift 'back' when we got `dyn Trait`s back
from Chalk, so after going through Chalk a few times, the panic happened.

crates/ra_hir_ty/src/lib.rs
crates/ra_hir_ty/src/tests/traits.rs
crates/ra_hir_ty/src/traits/chalk.rs

index 9d61bba402cf75aa992799e1ea69d9c80266d505..717399b6de587e66701d9c0339905758de5b9e50 100644 (file)
@@ -860,7 +860,8 @@ fn subst_bound_vars_at_depth(mut self, substs: &Substs, depth: DebruijnIndex) ->
         );
         self
     }
-    // /// Shifts up debruijn indices of `Ty::Bound` vars by `n`.
+
+    /// Shifts up debruijn indices of `Ty::Bound` vars by `n`.
     fn shift_bound_vars(self, n: DebruijnIndex) -> Self
     where
         Self: Sized,
index 081aa943a4e9f6a13731409b69a3f305178b971b..22ae6ca90922eb5c7cfc4a2ce0c6b9f29e382a06 100644 (file)
@@ -2021,3 +2021,28 @@ fn main() {
     "###
     );
 }
+
+#[test]
+fn dyn_trait_through_chalk() {
+    let t = type_at(
+        r#"
+//- /main.rs
+struct Box<T> {}
+#[lang = "deref"]
+trait Deref {
+    type Target;
+}
+impl<T> Deref for Box<T> {
+    type Target = T;
+}
+trait Trait {
+    fn foo(&self);
+}
+
+fn test(x: Box<dyn Trait>) {
+    x.foo()<|>;
+}
+"#,
+    );
+    assert_eq!(t, "()");
+}
index 53ce362ea20fd00234ff19780b306ace8b5aedde..1bc0f07135812312062e788aca119ea848b8039c 100644 (file)
@@ -427,7 +427,12 @@ fn from_chalk(
         db: &dyn HirDatabase,
         where_clause: chalk_ir::QuantifiedWhereClause<Interner>,
     ) -> GenericPredicate {
-        match where_clause.value {
+        // we don't produce any where clauses with binders and can't currently deal with them
+        match where_clause
+            .value
+            .shifted_out(&Interner)
+            .expect("unexpected bound vars in where clause")
+        {
             chalk_ir::WhereClause::Implemented(tr) => {
                 GenericPredicate::Implemented(from_chalk(db, tr))
             }