diff options
Diffstat (limited to 'crates/ra_hir_ty/src')
-rw-r--r-- | crates/ra_hir_ty/src/lib.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/traits.rs | 25 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/traits.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/traits/chalk.rs | 7 |
4 files changed, 39 insertions, 3 deletions
diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs index a9022dee7..717399b6d 100644 --- a/crates/ra_hir_ty/src/lib.rs +++ b/crates/ra_hir_ty/src/lib.rs | |||
@@ -1,6 +1,11 @@ | |||
1 | //! The type system. We currently use this to infer types for completion, hover | 1 | //! The type system. We currently use this to infer types for completion, hover |
2 | //! information and various assists. | 2 | //! information and various assists. |
3 | 3 | ||
4 | #[allow(unused)] | ||
5 | macro_rules! eprintln { | ||
6 | ($($tt:tt)*) => { stdx::eprintln!($($tt)*) }; | ||
7 | } | ||
8 | |||
4 | macro_rules! impl_froms { | 9 | macro_rules! impl_froms { |
5 | ($e:ident: $($v:ident $(($($sv:ident),*))?),*) => { | 10 | ($e:ident: $($v:ident $(($($sv:ident),*))?),*) => { |
6 | $( | 11 | $( |
@@ -855,7 +860,8 @@ pub trait TypeWalk { | |||
855 | ); | 860 | ); |
856 | self | 861 | self |
857 | } | 862 | } |
858 | // /// Shifts up debruijn indices of `Ty::Bound` vars by `n`. | 863 | |
864 | /// Shifts up debruijn indices of `Ty::Bound` vars by `n`. | ||
859 | fn shift_bound_vars(self, n: DebruijnIndex) -> Self | 865 | fn shift_bound_vars(self, n: DebruijnIndex) -> Self |
860 | where | 866 | where |
861 | Self: Sized, | 867 | 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() { | |||
2021 | "### | 2021 | "### |
2022 | ); | 2022 | ); |
2023 | } | 2023 | } |
2024 | |||
2025 | #[test] | ||
2026 | fn dyn_trait_through_chalk() { | ||
2027 | let t = type_at( | ||
2028 | r#" | ||
2029 | //- /main.rs | ||
2030 | struct Box<T> {} | ||
2031 | #[lang = "deref"] | ||
2032 | trait Deref { | ||
2033 | type Target; | ||
2034 | } | ||
2035 | impl<T> Deref for Box<T> { | ||
2036 | type Target = T; | ||
2037 | } | ||
2038 | trait Trait { | ||
2039 | fn foo(&self); | ||
2040 | } | ||
2041 | |||
2042 | fn test(x: Box<dyn Trait>) { | ||
2043 | x.foo()<|>; | ||
2044 | } | ||
2045 | "#, | ||
2046 | ); | ||
2047 | assert_eq!(t, "()"); | ||
2048 | } | ||
diff --git a/crates/ra_hir_ty/src/traits.rs b/crates/ra_hir_ty/src/traits.rs index 07854a062..5a1e12ce9 100644 --- a/crates/ra_hir_ty/src/traits.rs +++ b/crates/ra_hir_ty/src/traits.rs | |||
@@ -148,7 +148,7 @@ pub(crate) fn trait_solve_query( | |||
148 | Obligation::Trait(it) => db.trait_data(it.trait_).name.to_string(), | 148 | Obligation::Trait(it) => db.trait_data(it.trait_).name.to_string(), |
149 | Obligation::Projection(_) => "projection".to_string(), | 149 | Obligation::Projection(_) => "projection".to_string(), |
150 | }); | 150 | }); |
151 | eprintln!("trait_solve_query({})", goal.value.value.display(db)); | 151 | log::info!("trait_solve_query({})", goal.value.value.display(db)); |
152 | 152 | ||
153 | if let Obligation::Projection(pred) = &goal.value.value { | 153 | if let Obligation::Projection(pred) = &goal.value.value { |
154 | if let Ty::Bound(_) = &pred.projection_ty.parameters[0] { | 154 | if let Ty::Bound(_) = &pred.projection_ty.parameters[0] { |
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 { | |||
427 | db: &dyn HirDatabase, | 427 | db: &dyn HirDatabase, |
428 | where_clause: chalk_ir::QuantifiedWhereClause<Interner>, | 428 | where_clause: chalk_ir::QuantifiedWhereClause<Interner>, |
429 | ) -> GenericPredicate { | 429 | ) -> GenericPredicate { |
430 | match where_clause.value { | 430 | // we don't produce any where clauses with binders and can't currently deal with them |
431 | match where_clause | ||
432 | .value | ||
433 | .shifted_out(&Interner) | ||
434 | .expect("unexpected bound vars in where clause") | ||
435 | { | ||
431 | chalk_ir::WhereClause::Implemented(tr) => { | 436 | chalk_ir::WhereClause::Implemented(tr) => { |
432 | GenericPredicate::Implemented(from_chalk(db, tr)) | 437 | GenericPredicate::Implemented(from_chalk(db, tr)) |
433 | } | 438 | } |