diff options
Diffstat (limited to 'crates/hir_ty')
-rw-r--r-- | crates/hir_ty/src/chalk_ext.rs | 14 | ||||
-rw-r--r-- | crates/hir_ty/src/display.rs | 46 | ||||
-rw-r--r-- | crates/hir_ty/src/infer.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/coerce.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/pat.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/path.rs | 3 | ||||
-rw-r--r-- | crates/hir_ty/src/lib.rs | 30 | ||||
-rw-r--r-- | crates/hir_ty/src/lower.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/method_resolution.rs | 6 | ||||
-rw-r--r-- | crates/hir_ty/src/traits.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk/mapping.rs | 10 | ||||
-rw-r--r-- | crates/hir_ty/src/types.rs | 14 | ||||
-rw-r--r-- | crates/hir_ty/src/utils.rs | 4 |
14 files changed, 73 insertions, 66 deletions
diff --git a/crates/hir_ty/src/chalk_ext.rs b/crates/hir_ty/src/chalk_ext.rs index 6a353423a..28ed3aac6 100644 --- a/crates/hir_ty/src/chalk_ext.rs +++ b/crates/hir_ty/src/chalk_ext.rs | |||
@@ -202,12 +202,12 @@ impl TyExt for Ty { | |||
202 | .map(|pred| pred.clone().substitute(&Interner, &substs)) | 202 | .map(|pred| pred.clone().substitute(&Interner, &substs)) |
203 | .filter(|wc| match &wc.skip_binders() { | 203 | .filter(|wc| match &wc.skip_binders() { |
204 | WhereClause::Implemented(tr) => { | 204 | WhereClause::Implemented(tr) => { |
205 | tr.self_type_parameter(&Interner) == self | 205 | &tr.self_type_parameter(&Interner) == self |
206 | } | 206 | } |
207 | WhereClause::AliasEq(AliasEq { | 207 | WhereClause::AliasEq(AliasEq { |
208 | alias: AliasTy::Projection(proj), | 208 | alias: AliasTy::Projection(proj), |
209 | ty: _, | 209 | ty: _, |
210 | }) => proj.self_type_parameter(&Interner) == self, | 210 | }) => &proj.self_type_parameter(&Interner) == self, |
211 | _ => false, | 211 | _ => false, |
212 | }) | 212 | }) |
213 | .collect::<Vec<_>>(); | 213 | .collect::<Vec<_>>(); |
@@ -293,3 +293,13 @@ impl ProjectionTyExt for ProjectionTy { | |||
293 | } | 293 | } |
294 | } | 294 | } |
295 | } | 295 | } |
296 | |||
297 | pub trait TraitRefExt { | ||
298 | fn hir_trait_id(&self) -> TraitId; | ||
299 | } | ||
300 | |||
301 | impl TraitRefExt for TraitRef { | ||
302 | fn hir_trait_id(&self) -> TraitId { | ||
303 | from_chalk_trait_id(self.trait_id) | ||
304 | } | ||
305 | } | ||
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index 9e6bbcdf1..e0ca96c6d 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs | |||
@@ -24,7 +24,7 @@ use crate::{ | |||
24 | traits::chalk::from_chalk, utils::generics, AdtId, AliasEq, AliasTy, CallableDefId, | 24 | traits::chalk::from_chalk, utils::generics, AdtId, AliasEq, AliasTy, CallableDefId, |
25 | CallableSig, Const, ConstValue, DomainGoal, GenericArg, ImplTraitId, Interner, Lifetime, | 25 | CallableSig, Const, ConstValue, DomainGoal, GenericArg, ImplTraitId, Interner, Lifetime, |
26 | LifetimeData, LifetimeOutlives, Mutability, OpaqueTy, ProjectionTy, ProjectionTyExt, | 26 | LifetimeData, LifetimeOutlives, Mutability, OpaqueTy, ProjectionTy, ProjectionTyExt, |
27 | QuantifiedWhereClause, Scalar, TraitRef, Ty, TyExt, TyKind, WhereClause, | 27 | QuantifiedWhereClause, Scalar, TraitRef, TraitRefExt, Ty, TyExt, TyKind, WhereClause, |
28 | }; | 28 | }; |
29 | 29 | ||
30 | pub struct HirFormatter<'a> { | 30 | pub struct HirFormatter<'a> { |
@@ -616,12 +616,12 @@ impl HirDisplay for Ty { | |||
616 | .map(|pred| pred.clone().substitute(&Interner, &substs)) | 616 | .map(|pred| pred.clone().substitute(&Interner, &substs)) |
617 | .filter(|wc| match &wc.skip_binders() { | 617 | .filter(|wc| match &wc.skip_binders() { |
618 | WhereClause::Implemented(tr) => { | 618 | WhereClause::Implemented(tr) => { |
619 | tr.self_type_parameter(&Interner) == self | 619 | &tr.self_type_parameter(&Interner) == self |
620 | } | 620 | } |
621 | WhereClause::AliasEq(AliasEq { | 621 | WhereClause::AliasEq(AliasEq { |
622 | alias: AliasTy::Projection(proj), | 622 | alias: AliasTy::Projection(proj), |
623 | ty: _, | 623 | ty: _, |
624 | }) => proj.self_type_parameter(&Interner) == self, | 624 | }) => &proj.self_type_parameter(&Interner) == self, |
625 | _ => false, | 625 | _ => false, |
626 | }) | 626 | }) |
627 | .collect::<Vec<_>>(); | 627 | .collect::<Vec<_>>(); |
@@ -745,7 +745,7 @@ fn write_bounds_like_dyn_trait( | |||
745 | // existential) here, which is the only thing that's | 745 | // existential) here, which is the only thing that's |
746 | // possible in actual Rust, and hence don't print it | 746 | // possible in actual Rust, and hence don't print it |
747 | write!(f, "{}", f.db.trait_data(trait_).name)?; | 747 | write!(f, "{}", f.db.trait_data(trait_).name)?; |
748 | if let [_, params @ ..] = &*trait_ref.substitution.interned() { | 748 | if let [_, params @ ..] = &*trait_ref.substitution.interned().as_slice() { |
749 | if is_fn_trait { | 749 | if is_fn_trait { |
750 | if let Some(args) = | 750 | if let Some(args) = |
751 | params.first().and_then(|it| it.assert_ty_ref(&Interner).as_tuple()) | 751 | params.first().and_then(|it| it.assert_ty_ref(&Interner).as_tuple()) |
@@ -792,31 +792,29 @@ fn write_bounds_like_dyn_trait( | |||
792 | Ok(()) | 792 | Ok(()) |
793 | } | 793 | } |
794 | 794 | ||
795 | impl TraitRef { | 795 | fn fmt_trait_ref(tr: &TraitRef, f: &mut HirFormatter, use_as: bool) -> Result<(), HirDisplayError> { |
796 | fn hir_fmt_ext(&self, f: &mut HirFormatter, use_as: bool) -> Result<(), HirDisplayError> { | 796 | if f.should_truncate() { |
797 | if f.should_truncate() { | 797 | return write!(f, "{}", TYPE_HINT_TRUNCATION); |
798 | return write!(f, "{}", TYPE_HINT_TRUNCATION); | 798 | } |
799 | } | ||
800 | 799 | ||
801 | self.self_type_parameter(&Interner).hir_fmt(f)?; | 800 | tr.self_type_parameter(&Interner).hir_fmt(f)?; |
802 | if use_as { | 801 | if use_as { |
803 | write!(f, " as ")?; | 802 | write!(f, " as ")?; |
804 | } else { | 803 | } else { |
805 | write!(f, ": ")?; | 804 | write!(f, ": ")?; |
806 | } | ||
807 | write!(f, "{}", f.db.trait_data(self.hir_trait_id()).name)?; | ||
808 | if self.substitution.len(&Interner) > 1 { | ||
809 | write!(f, "<")?; | ||
810 | f.write_joined(&self.substitution.interned()[1..], ", ")?; | ||
811 | write!(f, ">")?; | ||
812 | } | ||
813 | Ok(()) | ||
814 | } | 805 | } |
806 | write!(f, "{}", f.db.trait_data(tr.hir_trait_id()).name)?; | ||
807 | if tr.substitution.len(&Interner) > 1 { | ||
808 | write!(f, "<")?; | ||
809 | f.write_joined(&tr.substitution.interned()[1..], ", ")?; | ||
810 | write!(f, ">")?; | ||
811 | } | ||
812 | Ok(()) | ||
815 | } | 813 | } |
816 | 814 | ||
817 | impl HirDisplay for TraitRef { | 815 | impl HirDisplay for TraitRef { |
818 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | 816 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { |
819 | self.hir_fmt_ext(f, false) | 817 | fmt_trait_ref(self, f, false) |
820 | } | 818 | } |
821 | } | 819 | } |
822 | 820 | ||
@@ -830,7 +828,7 @@ impl HirDisplay for WhereClause { | |||
830 | WhereClause::Implemented(trait_ref) => trait_ref.hir_fmt(f)?, | 828 | WhereClause::Implemented(trait_ref) => trait_ref.hir_fmt(f)?, |
831 | WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => { | 829 | WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => { |
832 | write!(f, "<")?; | 830 | write!(f, "<")?; |
833 | projection_ty.trait_ref(f.db).hir_fmt_ext(f, true)?; | 831 | fmt_trait_ref(&projection_ty.trait_ref(f.db), f, true)?; |
834 | write!( | 832 | write!( |
835 | f, | 833 | f, |
836 | ">::{} = ", | 834 | ">::{} = ", |
diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs index 6af0c59b8..531159e54 100644 --- a/crates/hir_ty/src/infer.rs +++ b/crates/hir_ty/src/infer.rs | |||
@@ -336,7 +336,7 @@ impl<'a> InferenceContext<'a> { | |||
336 | self.last_obligations_check = Some(self.table.revision); | 336 | self.last_obligations_check = Some(self.table.revision); |
337 | let obligations = mem::replace(&mut self.obligations, Vec::new()); | 337 | let obligations = mem::replace(&mut self.obligations, Vec::new()); |
338 | for obligation in obligations { | 338 | for obligation in obligations { |
339 | let in_env = InEnvironment::new(self.trait_env.env.clone(), obligation.clone()); | 339 | let in_env = InEnvironment::new(&self.trait_env.env, obligation.clone()); |
340 | let canonicalized = self.canonicalizer().canonicalize_obligation(in_env); | 340 | let canonicalized = self.canonicalizer().canonicalize_obligation(in_env); |
341 | let solution = | 341 | let solution = |
342 | self.db.trait_solve(self.resolver.krate().unwrap(), canonicalized.value.clone()); | 342 | self.db.trait_solve(self.resolver.krate().unwrap(), canonicalized.value.clone()); |
diff --git a/crates/hir_ty/src/infer/coerce.rs b/crates/hir_ty/src/infer/coerce.rs index f1af2a0bd..fd679f444 100644 --- a/crates/hir_ty/src/infer/coerce.rs +++ b/crates/hir_ty/src/infer/coerce.rs | |||
@@ -139,7 +139,7 @@ impl<'a> InferenceContext<'a> { | |||
139 | b.push(from_ty.clone()).push(to_ty.clone()).build() | 139 | b.push(from_ty.clone()).push(to_ty.clone()).build() |
140 | }; | 140 | }; |
141 | 141 | ||
142 | let goal = InEnvironment::new(self.trait_env.env.clone(), trait_ref.cast(&Interner)); | 142 | let goal = InEnvironment::new(&self.trait_env.env, trait_ref.cast(&Interner)); |
143 | 143 | ||
144 | let canonicalizer = self.canonicalizer(); | 144 | let canonicalizer = self.canonicalizer(); |
145 | let canonicalized = canonicalizer.canonicalize_obligation(goal); | 145 | let canonicalized = canonicalizer.canonicalize_obligation(goal); |
diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs index f88d5c5d3..a41e8e116 100644 --- a/crates/hir_ty/src/infer/pat.rs +++ b/crates/hir_ty/src/infer/pat.rs | |||
@@ -122,7 +122,7 @@ impl<'a> InferenceContext<'a> { | |||
122 | let ty = match &body[pat] { | 122 | let ty = match &body[pat] { |
123 | &Pat::Tuple { ref args, ellipsis } => { | 123 | &Pat::Tuple { ref args, ellipsis } => { |
124 | let expectations = match expected.as_tuple() { | 124 | let expectations = match expected.as_tuple() { |
125 | Some(parameters) => &*parameters.interned(), | 125 | Some(parameters) => &*parameters.interned().as_slice(), |
126 | _ => &[], | 126 | _ => &[], |
127 | }; | 127 | }; |
128 | 128 | ||
diff --git a/crates/hir_ty/src/infer/path.rs b/crates/hir_ty/src/infer/path.rs index b19d67bb1..f8955aa32 100644 --- a/crates/hir_ty/src/infer/path.rs +++ b/crates/hir_ty/src/infer/path.rs | |||
@@ -11,7 +11,8 @@ use hir_def::{ | |||
11 | use hir_expand::name::Name; | 11 | use hir_expand::name::Name; |
12 | 12 | ||
13 | use crate::{ | 13 | use crate::{ |
14 | method_resolution, Interner, Substitution, Ty, TyBuilder, TyExt, TyKind, ValueTyDefId, | 14 | method_resolution, Interner, Substitution, TraitRefExt, Ty, TyBuilder, TyExt, TyKind, |
15 | ValueTyDefId, | ||
15 | }; | 16 | }; |
16 | 17 | ||
17 | use super::{ExprOrPatId, InferenceContext, TraitRef}; | 18 | use super::{ExprOrPatId, InferenceContext, TraitRef}; |
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index 2e851d3e0..87f10e9d5 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs | |||
@@ -41,7 +41,7 @@ use crate::{db::HirDatabase, display::HirDisplay, utils::generics}; | |||
41 | 41 | ||
42 | pub use autoderef::autoderef; | 42 | pub use autoderef::autoderef; |
43 | pub use builder::TyBuilder; | 43 | pub use builder::TyBuilder; |
44 | pub use chalk_ext::{ProjectionTyExt, TyExt}; | 44 | pub use chalk_ext::*; |
45 | pub use infer::{could_unify, InferenceResult}; | 45 | pub use infer::{could_unify, InferenceResult}; |
46 | pub use lower::{ | 46 | pub use lower::{ |
47 | associated_type_shorthand_candidates, callable_item_sig, CallableDefId, ImplTraitLoweringMode, | 47 | associated_type_shorthand_candidates, callable_item_sig, CallableDefId, ImplTraitLoweringMode, |
@@ -107,22 +107,18 @@ pub fn make_only_type_binders<T>(num_vars: usize, value: T) -> Binders<T> { | |||
107 | ) | 107 | ) |
108 | } | 108 | } |
109 | 109 | ||
110 | impl TraitRef { | 110 | // FIXME: get rid of this |
111 | pub fn hir_trait_id(&self) -> TraitId { | 111 | pub fn make_canonical<T>( |
112 | from_chalk_trait_id(self.trait_id) | 112 | value: T, |
113 | } | 113 | kinds: impl IntoIterator<Item = TyVariableKind>, |
114 | } | 114 | ) -> Canonical<T> { |
115 | 115 | let kinds = kinds.into_iter().map(|tk| { | |
116 | impl<T> Canonical<T> { | 116 | chalk_ir::CanonicalVarKind::new( |
117 | pub fn new(value: T, kinds: impl IntoIterator<Item = TyVariableKind>) -> Self { | 117 | chalk_ir::VariableKind::Ty(tk), |
118 | let kinds = kinds.into_iter().map(|tk| { | 118 | chalk_ir::UniverseIndex::ROOT, |
119 | chalk_ir::CanonicalVarKind::new( | 119 | ) |
120 | chalk_ir::VariableKind::Ty(tk), | 120 | }); |
121 | chalk_ir::UniverseIndex::ROOT, | 121 | Canonical { value, binders: chalk_ir::CanonicalVarKinds::from_iter(&Interner, kinds) } |
122 | ) | ||
123 | }); | ||
124 | Self { value, binders: chalk_ir::CanonicalVarKinds::from_iter(&Interner, kinds) } | ||
125 | } | ||
126 | } | 122 | } |
127 | 123 | ||
128 | /// A function signature as seen by type inference: Several parameter types and | 124 | /// A function signature as seen by type inference: Several parameter types and |
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index 4ca6aa538..e6903e189 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs | |||
@@ -35,7 +35,7 @@ use crate::{ | |||
35 | AliasEq, AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, DynTy, FnPointer, FnSig, | 35 | AliasEq, AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, DynTy, FnPointer, FnSig, |
36 | FnSubst, ImplTraitId, OpaqueTy, PolyFnSig, ProjectionTy, QuantifiedWhereClause, | 36 | FnSubst, ImplTraitId, OpaqueTy, PolyFnSig, ProjectionTy, QuantifiedWhereClause, |
37 | QuantifiedWhereClauses, ReturnTypeImplTrait, ReturnTypeImplTraits, Substitution, | 37 | QuantifiedWhereClauses, ReturnTypeImplTrait, ReturnTypeImplTraits, Substitution, |
38 | TraitEnvironment, TraitRef, Ty, TyBuilder, TyKind, TypeWalk, WhereClause, | 38 | TraitEnvironment, TraitRef, TraitRefExt, Ty, TyBuilder, TyKind, TypeWalk, WhereClause, |
39 | }; | 39 | }; |
40 | 40 | ||
41 | #[derive(Debug)] | 41 | #[derive(Debug)] |
diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs index c601f2d53..7e09a1539 100644 --- a/crates/hir_ty/src/method_resolution.rs +++ b/crates/hir_ty/src/method_resolution.rs | |||
@@ -22,8 +22,8 @@ use crate::{ | |||
22 | static_lifetime, | 22 | static_lifetime, |
23 | utils::all_super_traits, | 23 | utils::all_super_traits, |
24 | AdtId, Canonical, CanonicalVarKinds, DebruijnIndex, FnPointer, FnSig, ForeignDefId, | 24 | AdtId, Canonical, CanonicalVarKinds, DebruijnIndex, FnPointer, FnSig, ForeignDefId, |
25 | InEnvironment, Interner, Scalar, Substitution, TraitEnvironment, Ty, TyBuilder, TyExt, TyKind, | 25 | InEnvironment, Interner, Scalar, Substitution, TraitEnvironment, TraitRefExt, Ty, TyBuilder, |
26 | TypeWalk, | 26 | TyExt, TyKind, TypeWalk, |
27 | }; | 27 | }; |
28 | 28 | ||
29 | /// This is used as a key for indexing impls. | 29 | /// This is used as a key for indexing impls. |
@@ -845,7 +845,7 @@ fn generic_implements_goal( | |||
845 | let obligation = trait_ref.cast(&Interner); | 845 | let obligation = trait_ref.cast(&Interner); |
846 | Canonical { | 846 | Canonical { |
847 | binders: CanonicalVarKinds::from_iter(&Interner, kinds), | 847 | binders: CanonicalVarKinds::from_iter(&Interner, kinds), |
848 | value: InEnvironment::new(env.env.clone(), obligation), | 848 | value: InEnvironment::new(&env.env, obligation), |
849 | } | 849 | } |
850 | } | 850 | } |
851 | 851 | ||
diff --git a/crates/hir_ty/src/traits.rs b/crates/hir_ty/src/traits.rs index 3374532c3..7d87741b8 100644 --- a/crates/hir_ty/src/traits.rs +++ b/crates/hir_ty/src/traits.rs | |||
@@ -9,7 +9,7 @@ use stdx::panic_context; | |||
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | db::HirDatabase, AliasEq, AliasTy, Canonical, DomainGoal, Guidance, HirDisplay, InEnvironment, | 11 | db::HirDatabase, AliasEq, AliasTy, Canonical, DomainGoal, Guidance, HirDisplay, InEnvironment, |
12 | Solution, Ty, TyKind, WhereClause, | 12 | Solution, TraitRefExt, Ty, TyKind, WhereClause, |
13 | }; | 13 | }; |
14 | 14 | ||
15 | use self::chalk::{from_chalk, Interner, ToChalk}; | 15 | use self::chalk::{from_chalk, Interner, ToChalk}; |
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs index f03b92422..090f6492b 100644 --- a/crates/hir_ty/src/traits/chalk.rs +++ b/crates/hir_ty/src/traits/chalk.rs | |||
@@ -22,7 +22,7 @@ use crate::{ | |||
22 | to_assoc_type_id, to_chalk_trait_id, | 22 | to_assoc_type_id, to_chalk_trait_id, |
23 | utils::generics, | 23 | utils::generics, |
24 | AliasEq, AliasTy, BoundVar, CallableDefId, DebruijnIndex, FnDefId, ProjectionTy, Substitution, | 24 | AliasEq, AliasTy, BoundVar, CallableDefId, DebruijnIndex, FnDefId, ProjectionTy, Substitution, |
25 | TraitRef, Ty, TyBuilder, TyExt, TyKind, WhereClause, | 25 | TraitRef, TraitRefExt, Ty, TyBuilder, TyExt, TyKind, WhereClause, |
26 | }; | 26 | }; |
27 | use mapping::{ | 27 | use mapping::{ |
28 | convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsValue, | 28 | convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsValue, |
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index 84abd99b2..701359e6f 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs | |||
@@ -10,9 +10,9 @@ use base_db::salsa::InternKey; | |||
10 | use hir_def::{GenericDefId, TypeAliasId}; | 10 | use hir_def::{GenericDefId, TypeAliasId}; |
11 | 11 | ||
12 | use crate::{ | 12 | use crate::{ |
13 | chalk_ext::ProjectionTyExt, db::HirDatabase, static_lifetime, AliasTy, CallableDefId, | 13 | db::HirDatabase, static_lifetime, AliasTy, CallableDefId, Canonical, ConstrainedSubst, |
14 | Canonical, ConstrainedSubst, DomainGoal, FnPointer, GenericArg, InEnvironment, OpaqueTy, | 14 | DomainGoal, FnPointer, GenericArg, InEnvironment, OpaqueTy, ProjectionTy, ProjectionTyExt, |
15 | ProjectionTy, QuantifiedWhereClause, Substitution, TraitRef, Ty, TypeWalk, WhereClause, | 15 | QuantifiedWhereClause, Substitution, TraitRef, Ty, TypeWalk, WhereClause, |
16 | }; | 16 | }; |
17 | 17 | ||
18 | use super::interner::*; | 18 | use super::interner::*; |
@@ -509,7 +509,7 @@ pub(super) fn generic_predicate_to_inline_bound( | |||
509 | let (pred, binders) = pred.as_ref().into_value_and_skipped_binders(); | 509 | let (pred, binders) = pred.as_ref().into_value_and_skipped_binders(); |
510 | match pred { | 510 | match pred { |
511 | WhereClause::Implemented(trait_ref) => { | 511 | WhereClause::Implemented(trait_ref) => { |
512 | if trait_ref.self_type_parameter(&Interner) != &self_ty_shifted_in { | 512 | if trait_ref.self_type_parameter(&Interner) != self_ty_shifted_in { |
513 | // we can only convert predicates back to type bounds if they | 513 | // we can only convert predicates back to type bounds if they |
514 | // have the expected self type | 514 | // have the expected self type |
515 | return None; | 515 | return None; |
@@ -522,7 +522,7 @@ pub(super) fn generic_predicate_to_inline_bound( | |||
522 | Some(chalk_ir::Binders::new(binders, rust_ir::InlineBound::TraitBound(trait_bound))) | 522 | Some(chalk_ir::Binders::new(binders, rust_ir::InlineBound::TraitBound(trait_bound))) |
523 | } | 523 | } |
524 | WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => { | 524 | WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => { |
525 | if projection_ty.self_type_parameter(&Interner) != &self_ty_shifted_in { | 525 | if projection_ty.self_type_parameter(&Interner) != self_ty_shifted_in { |
526 | return None; | 526 | return None; |
527 | } | 527 | } |
528 | let trait_ = projection_ty.trait_(db); | 528 | let trait_ = projection_ty.trait_(db); |
diff --git a/crates/hir_ty/src/types.rs b/crates/hir_ty/src/types.rs index c25bc2d6a..89adad108 100644 --- a/crates/hir_ty/src/types.rs +++ b/crates/hir_ty/src/types.rs | |||
@@ -30,8 +30,8 @@ pub struct ProjectionTy { | |||
30 | } | 30 | } |
31 | 31 | ||
32 | impl ProjectionTy { | 32 | impl ProjectionTy { |
33 | pub fn self_type_parameter(&self, interner: &Interner) -> &Ty { | 33 | pub fn self_type_parameter(&self, interner: &Interner) -> Ty { |
34 | &self.substitution.interned()[0].assert_ty_ref(interner) | 34 | self.substitution.interned()[0].assert_ty_ref(interner).clone() |
35 | } | 35 | } |
36 | } | 36 | } |
37 | 37 | ||
@@ -282,7 +282,7 @@ impl GenericArg { | |||
282 | pub struct Substitution(SmallVec<[GenericArg; 2]>); | 282 | pub struct Substitution(SmallVec<[GenericArg; 2]>); |
283 | 283 | ||
284 | impl Substitution { | 284 | impl Substitution { |
285 | pub fn interned(&self) -> &[GenericArg] { | 285 | pub fn interned(&self) -> &SmallVec<[GenericArg; 2]> { |
286 | &self.0 | 286 | &self.0 |
287 | } | 287 | } |
288 | 288 | ||
@@ -413,8 +413,8 @@ pub struct TraitRef { | |||
413 | } | 413 | } |
414 | 414 | ||
415 | impl TraitRef { | 415 | impl TraitRef { |
416 | pub fn self_type_parameter(&self, interner: &Interner) -> &Ty { | 416 | pub fn self_type_parameter(&self, interner: &Interner) -> Ty { |
417 | &self.substitution.at(interner, 0).assert_ty_ref(interner) | 417 | self.substitution.at(interner, 0).assert_ty_ref(interner).clone() |
418 | } | 418 | } |
419 | } | 419 | } |
420 | 420 | ||
@@ -470,8 +470,8 @@ pub struct InEnvironment<T> { | |||
470 | } | 470 | } |
471 | 471 | ||
472 | impl<T> InEnvironment<T> { | 472 | impl<T> InEnvironment<T> { |
473 | pub fn new(environment: chalk_ir::Environment<Interner>, value: T) -> InEnvironment<T> { | 473 | pub fn new(environment: &chalk_ir::Environment<Interner>, value: T) -> InEnvironment<T> { |
474 | InEnvironment { environment, goal: value } | 474 | InEnvironment { environment: environment.clone(), goal: value } |
475 | } | 475 | } |
476 | } | 476 | } |
477 | 477 | ||
diff --git a/crates/hir_ty/src/utils.rs b/crates/hir_ty/src/utils.rs index 0a424f607..8d5d5cd73 100644 --- a/crates/hir_ty/src/utils.rs +++ b/crates/hir_ty/src/utils.rs | |||
@@ -16,7 +16,9 @@ use hir_def::{ | |||
16 | }; | 16 | }; |
17 | use hir_expand::name::{name, Name}; | 17 | use hir_expand::name::{name, Name}; |
18 | 18 | ||
19 | use crate::{db::HirDatabase, Interner, Substitution, TraitRef, TyKind, TypeWalk, WhereClause}; | 19 | use crate::{ |
20 | db::HirDatabase, Interner, Substitution, TraitRef, TraitRefExt, TyKind, TypeWalk, WhereClause, | ||
21 | }; | ||
20 | 22 | ||
21 | fn direct_super_traits(db: &dyn DefDatabase, trait_: TraitId) -> Vec<TraitId> { | 23 | fn direct_super_traits(db: &dyn DefDatabase, trait_: TraitId) -> Vec<TraitId> { |
22 | let resolver = trait_.resolver(db); | 24 | let resolver = trait_.resolver(db); |