aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-04-07 19:51:36 +0100
committerGitHub <[email protected]>2021-04-07 19:51:36 +0100
commit3191a93185b34c6deebca2aad0584d2840ad6d43 (patch)
tree1fad465381a5b9a9d0b77dbf68a246db1835f511 /crates
parent6379839c8203b6fbc9af947997a7f73a36ef15a2 (diff)
parentdc116f7ce2192433c9491441a11d294e7d294fbf (diff)
Merge #8409
8409: Various remaining fixes for Chalk IR move r=flodiebold a=flodiebold CC #8313 Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/hir/src/lib.rs9
-rw-r--r--crates/hir_ty/src/chalk_ext.rs14
-rw-r--r--crates/hir_ty/src/display.rs46
-rw-r--r--crates/hir_ty/src/infer.rs2
-rw-r--r--crates/hir_ty/src/infer/coerce.rs2
-rw-r--r--crates/hir_ty/src/infer/pat.rs2
-rw-r--r--crates/hir_ty/src/infer/path.rs3
-rw-r--r--crates/hir_ty/src/lib.rs30
-rw-r--r--crates/hir_ty/src/lower.rs2
-rw-r--r--crates/hir_ty/src/method_resolution.rs6
-rw-r--r--crates/hir_ty/src/traits.rs2
-rw-r--r--crates/hir_ty/src/traits/chalk.rs2
-rw-r--r--crates/hir_ty/src/traits/chalk/mapping.rs10
-rw-r--r--crates/hir_ty/src/types.rs14
-rw-r--r--crates/hir_ty/src/utils.rs4
15 files changed, 78 insertions, 70 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 13aaa408a..0afc06906 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -59,7 +59,8 @@ use hir_ty::{
59 traits::FnTrait, 59 traits::FnTrait,
60 AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, CanonicalVarKinds, Cast, 60 AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, CanonicalVarKinds, Cast,
61 DebruijnIndex, InEnvironment, Interner, QuantifiedWhereClause, Scalar, Solution, Substitution, 61 DebruijnIndex, InEnvironment, Interner, QuantifiedWhereClause, Scalar, Solution, Substitution,
62 TraitEnvironment, Ty, TyBuilder, TyDefId, TyExt, TyKind, TyVariableKind, WhereClause, 62 TraitEnvironment, TraitRefExt, Ty, TyBuilder, TyDefId, TyExt, TyKind, TyVariableKind,
63 WhereClause,
63}; 64};
64use itertools::Itertools; 65use itertools::Itertools;
65use rustc_hash::FxHashSet; 66use rustc_hash::FxHashSet;
@@ -1790,7 +1791,7 @@ impl Type {
1790 .build(); 1791 .build();
1791 1792
1792 let goal = Canonical { 1793 let goal = Canonical {
1793 value: hir_ty::InEnvironment::new(self.env.env.clone(), trait_ref.cast(&Interner)), 1794 value: hir_ty::InEnvironment::new(&self.env.env, trait_ref.cast(&Interner)),
1794 binders: CanonicalVarKinds::empty(&Interner), 1795 binders: CanonicalVarKinds::empty(&Interner),
1795 }; 1796 };
1796 1797
@@ -1807,9 +1808,9 @@ impl Type {
1807 .push(self.ty.clone()) 1808 .push(self.ty.clone())
1808 .fill(args.iter().map(|t| t.ty.clone())) 1809 .fill(args.iter().map(|t| t.ty.clone()))
1809 .build(); 1810 .build();
1810 let goal = Canonical::new( 1811 let goal = hir_ty::make_canonical(
1811 InEnvironment::new( 1812 InEnvironment::new(
1812 self.env.env.clone(), 1813 &self.env.env,
1813 AliasEq { 1814 AliasEq {
1814 alias: AliasTy::Projection(projection), 1815 alias: AliasTy::Projection(projection),
1815 ty: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)) 1816 ty: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0))
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
297pub trait TraitRefExt {
298 fn hir_trait_id(&self) -> TraitId;
299}
300
301impl 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
30pub struct HirFormatter<'a> { 30pub 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
795impl TraitRef { 795fn 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
817impl HirDisplay for TraitRef { 815impl 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::{
11use hir_expand::name::Name; 11use hir_expand::name::Name;
12 12
13use crate::{ 13use 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
17use super::{ExprOrPatId, InferenceContext, TraitRef}; 18use 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
42pub use autoderef::autoderef; 42pub use autoderef::autoderef;
43pub use builder::TyBuilder; 43pub use builder::TyBuilder;
44pub use chalk_ext::{ProjectionTyExt, TyExt}; 44pub use chalk_ext::*;
45pub use infer::{could_unify, InferenceResult}; 45pub use infer::{could_unify, InferenceResult};
46pub use lower::{ 46pub 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
110impl TraitRef { 110// FIXME: get rid of this
111 pub fn hir_trait_id(&self) -> TraitId { 111pub 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| {
116impl<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
10use crate::{ 10use 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
15use self::chalk::{from_chalk, Interner, ToChalk}; 15use 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};
27use mapping::{ 27use 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;
10use hir_def::{GenericDefId, TypeAliasId}; 10use hir_def::{GenericDefId, TypeAliasId};
11 11
12use crate::{ 12use 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
18use super::interner::*; 18use 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
32impl ProjectionTy { 32impl 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 {
282pub struct Substitution(SmallVec<[GenericArg; 2]>); 282pub struct Substitution(SmallVec<[GenericArg; 2]>);
283 283
284impl Substitution { 284impl 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
415impl TraitRef { 415impl 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
472impl<T> InEnvironment<T> { 472impl<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};
17use hir_expand::name::{name, Name}; 17use hir_expand::name::{name, Name};
18 18
19use crate::{db::HirDatabase, Interner, Substitution, TraitRef, TyKind, TypeWalk, WhereClause}; 19use crate::{
20 db::HirDatabase, Interner, Substitution, TraitRef, TraitRefExt, TyKind, TypeWalk, WhereClause,
21};
20 22
21fn direct_super_traits(db: &dyn DefDatabase, trait_: TraitId) -> Vec<TraitId> { 23fn direct_super_traits(db: &dyn DefDatabase, trait_: TraitId) -> Vec<TraitId> {
22 let resolver = trait_.resolver(db); 24 let resolver = trait_.resolver(db);