From 236ac630f6ffc403257d4c77e6187819432956cf Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Mon, 6 Apr 2020 17:24:08 +0200 Subject: Fix Chalk panic 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 | 3 ++- crates/ra_hir_ty/src/tests/traits.rs | 25 +++++++++++++++++++++++++ crates/ra_hir_ty/src/traits/chalk.rs | 7 ++++++- 3 files changed, 33 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_ty/src') diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs index 9d61bba40..717399b6d 100644 --- a/crates/ra_hir_ty/src/lib.rs +++ b/crates/ra_hir_ty/src/lib.rs @@ -860,7 +860,8 @@ pub trait TypeWalk { ); 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, diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index 081aa943a..22ae6ca90 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -2021,3 +2021,28 @@ fn main() { "### ); } + +#[test] +fn dyn_trait_through_chalk() { + let t = type_at( + r#" +//- /main.rs +struct Box {} +#[lang = "deref"] +trait Deref { + type Target; +} +impl Deref for Box { + type Target = T; +} +trait Trait { + fn foo(&self); +} + +fn test(x: Box) { + x.foo()<|>; +} +"#, + ); + assert_eq!(t, "()"); +} diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs index 53ce362ea..1bc0f0713 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs @@ -427,7 +427,12 @@ impl ToChalk for GenericPredicate { db: &dyn HirDatabase, where_clause: chalk_ir::QuantifiedWhereClause, ) -> 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)) } -- cgit v1.2.3