aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_ty/src/display.rs33
-rw-r--r--crates/hir_ty/src/lib.rs14
-rw-r--r--crates/hir_ty/src/lower.rs3
-rw-r--r--crates/hir_ty/src/traits.rs2
-rw-r--r--crates/hir_ty/src/traits/chalk/mapping.rs4
5 files changed, 30 insertions, 26 deletions
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs
index 5ff70c893..1108e5a10 100644
--- a/crates/hir_ty/src/display.rs
+++ b/crates/hir_ty/src/display.rs
@@ -251,7 +251,7 @@ impl HirDisplay for ProjectionTy {
251 } 251 }
252 252
253 let trait_ = f.db.trait_data(self.trait_(f.db)); 253 let trait_ = f.db.trait_data(self.trait_(f.db));
254 let first_parameter = self.self_type_parameter().into_displayable( 254 let first_parameter = self.self_type_parameter(&Interner).into_displayable(
255 f.db, 255 f.db,
256 f.max_size, 256 f.max_size,
257 f.omit_verbose_types, 257 f.omit_verbose_types,
@@ -592,20 +592,21 @@ impl HirDisplay for Ty {
592 } 592 }
593 TypeParamProvenance::ArgumentImplTrait => { 593 TypeParamProvenance::ArgumentImplTrait => {
594 let substs = generics.type_params_subst(f.db); 594 let substs = generics.type_params_subst(f.db);
595 let bounds = f 595 let bounds =
596 .db 596 f.db.generic_predicates(id.parent)
597 .generic_predicates(id.parent) 597 .into_iter()
598 .into_iter() 598 .map(|pred| pred.clone().subst(&substs))
599 .map(|pred| pred.clone().subst(&substs)) 599 .filter(|wc| match &wc.skip_binders() {
600 .filter(|wc| match &wc.skip_binders() { 600 WhereClause::Implemented(tr) => {
601 WhereClause::Implemented(tr) => tr.self_type_parameter() == self, 601 tr.self_type_parameter(&Interner) == self
602 WhereClause::AliasEq(AliasEq { 602 }
603 alias: AliasTy::Projection(proj), 603 WhereClause::AliasEq(AliasEq {
604 ty: _, 604 alias: AliasTy::Projection(proj),
605 }) => proj.self_type_parameter() == self, 605 ty: _,
606 _ => false, 606 }) => proj.self_type_parameter(&Interner) == self,
607 }) 607 _ => false,
608 .collect::<Vec<_>>(); 608 })
609 .collect::<Vec<_>>();
609 write_bounds_like_dyn_trait_with_prefix("impl", &bounds, f)?; 610 write_bounds_like_dyn_trait_with_prefix("impl", &bounds, f)?;
610 } 611 }
611 } 612 }
@@ -780,7 +781,7 @@ impl TraitRef {
780 return write!(f, "{}", TYPE_HINT_TRUNCATION); 781 return write!(f, "{}", TYPE_HINT_TRUNCATION);
781 } 782 }
782 783
783 self.self_type_parameter().hir_fmt(f)?; 784 self.self_type_parameter(&Interner).hir_fmt(f)?;
784 if use_as { 785 if use_as {
785 write!(f, " as ")?; 786 write!(f, " as ")?;
786 } else { 787 } else {
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index d1513df1f..adfdcaa37 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -78,8 +78,8 @@ impl ProjectionTy {
78 } 78 }
79 } 79 }
80 80
81 pub fn self_type_parameter(&self) -> &Ty { 81 pub fn self_type_parameter(&self, interner: &Interner) -> &Ty {
82 &self.substitution.interned()[0].assert_ty_ref(&Interner) 82 &self.substitution.interned()[0].assert_ty_ref(interner)
83 } 83 }
84 84
85 fn trait_(&self, db: &dyn HirDatabase) -> TraitId { 85 fn trait_(&self, db: &dyn HirDatabase) -> TraitId {
@@ -165,8 +165,8 @@ impl<T: TypeWalk> Binders<T> {
165} 165}
166 166
167impl TraitRef { 167impl TraitRef {
168 pub fn self_type_parameter(&self) -> &Ty { 168 pub fn self_type_parameter(&self, interner: &Interner) -> &Ty {
169 &self.substitution.at(&Interner, 0).assert_ty_ref(&Interner) 169 &self.substitution.at(interner, 0).assert_ty_ref(interner)
170 } 170 }
171 171
172 pub fn hir_trait_id(&self) -> TraitId { 172 pub fn hir_trait_id(&self) -> TraitId {
@@ -473,11 +473,13 @@ impl Ty {
473 .into_iter() 473 .into_iter()
474 .map(|pred| pred.clone().subst(&substs)) 474 .map(|pred| pred.clone().subst(&substs))
475 .filter(|wc| match &wc.skip_binders() { 475 .filter(|wc| match &wc.skip_binders() {
476 WhereClause::Implemented(tr) => tr.self_type_parameter() == self, 476 WhereClause::Implemented(tr) => {
477 tr.self_type_parameter(&Interner) == self
478 }
477 WhereClause::AliasEq(AliasEq { 479 WhereClause::AliasEq(AliasEq {
478 alias: AliasTy::Projection(proj), 480 alias: AliasTy::Projection(proj),
479 ty: _, 481 ty: _,
480 }) => proj.self_type_parameter() == self, 482 }) => proj.self_type_parameter(&Interner) == self,
481 _ => false, 483 _ => false,
482 }) 484 })
483 .collect_vec(); 485 .collect_vec();
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index ba48be4ad..e9e4e69ad 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -941,7 +941,8 @@ pub(crate) fn trait_environment_query(
941 for pred in resolver.where_predicates_in_scope() { 941 for pred in resolver.where_predicates_in_scope() {
942 for pred in ctx.lower_where_predicate(pred, false) { 942 for pred in ctx.lower_where_predicate(pred, false) {
943 if let WhereClause::Implemented(tr) = &pred.skip_binders() { 943 if let WhereClause::Implemented(tr) = &pred.skip_binders() {
944 traits_in_scope.push((tr.self_type_parameter().clone(), tr.hir_trait_id())); 944 traits_in_scope
945 .push((tr.self_type_parameter(&Interner).clone(), tr.hir_trait_id()));
945 } 946 }
946 let program_clause: chalk_ir::ProgramClause<Interner> = 947 let program_clause: chalk_ir::ProgramClause<Interner> =
947 pred.clone().to_chalk(db).cast(&Interner); 948 pred.clone().to_chalk(db).cast(&Interner);
diff --git a/crates/hir_ty/src/traits.rs b/crates/hir_ty/src/traits.rs
index 66d600bfc..c8883485c 100644
--- a/crates/hir_ty/src/traits.rs
+++ b/crates/hir_ty/src/traits.rs
@@ -89,7 +89,7 @@ pub(crate) fn trait_solve_query(
89 .. 89 ..
90 })) = &goal.value.goal 90 })) = &goal.value.goal
91 { 91 {
92 if let TyKind::BoundVar(_) = projection_ty.self_type_parameter().kind(&Interner) { 92 if let TyKind::BoundVar(_) = projection_ty.self_type_parameter(&Interner).kind(&Interner) {
93 // Hack: don't ask Chalk to normalize with an unknown self type, it'll say that's impossible 93 // Hack: don't ask Chalk to normalize with an unknown self type, it'll say that's impossible
94 return Some(Solution::Ambig(Guidance::Unknown)); 94 return Some(Solution::Ambig(Guidance::Unknown));
95 } 95 }
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs
index 59aaa5560..67e88ebf4 100644
--- a/crates/hir_ty/src/traits/chalk/mapping.rs
+++ b/crates/hir_ty/src/traits/chalk/mapping.rs
@@ -539,7 +539,7 @@ pub(super) fn generic_predicate_to_inline_bound(
539 let self_ty_shifted_in = self_ty.clone().shift_bound_vars(DebruijnIndex::ONE); 539 let self_ty_shifted_in = self_ty.clone().shift_bound_vars(DebruijnIndex::ONE);
540 match &pred.value { 540 match &pred.value {
541 WhereClause::Implemented(trait_ref) => { 541 WhereClause::Implemented(trait_ref) => {
542 if trait_ref.self_type_parameter() != &self_ty_shifted_in { 542 if trait_ref.self_type_parameter(&Interner) != &self_ty_shifted_in {
543 // we can only convert predicates back to type bounds if they 543 // we can only convert predicates back to type bounds if they
544 // have the expected self type 544 // have the expected self type
545 return None; 545 return None;
@@ -552,7 +552,7 @@ pub(super) fn generic_predicate_to_inline_bound(
552 Some(make_binders(rust_ir::InlineBound::TraitBound(trait_bound), pred.num_binders)) 552 Some(make_binders(rust_ir::InlineBound::TraitBound(trait_bound), pred.num_binders))
553 } 553 }
554 WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => { 554 WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => {
555 if projection_ty.self_type_parameter() != &self_ty_shifted_in { 555 if projection_ty.self_type_parameter(&Interner) != &self_ty_shifted_in {
556 return None; 556 return None;
557 } 557 }
558 let trait_ = projection_ty.trait_(db); 558 let trait_ = projection_ty.trait_(db);