From aefcbf275804f558ab18e83bfc8869187713b4ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Mon, 5 Apr 2021 17:37:24 +0300 Subject: Pass interner to ProjectionTy::self_type_parameter --- crates/hir_ty/src/display.rs | 4 ++-- crates/hir_ty/src/lib.rs | 6 +++--- crates/hir_ty/src/traits.rs | 2 +- crates/hir_ty/src/traits/chalk/mapping.rs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) (limited to 'crates/hir_ty/src') diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index 5ff70c893..965476a05 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -251,7 +251,7 @@ impl HirDisplay for ProjectionTy { } let trait_ = f.db.trait_data(self.trait_(f.db)); - let first_parameter = self.self_type_parameter().into_displayable( + let first_parameter = self.self_type_parameter(&Interner).into_displayable( f.db, f.max_size, f.omit_verbose_types, @@ -602,7 +602,7 @@ impl HirDisplay for Ty { WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(proj), ty: _, - }) => proj.self_type_parameter() == self, + }) => proj.self_type_parameter(&Interner) == self, _ => false, }) .collect::>(); diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index d1513df1f..80dd7aaca 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs @@ -78,8 +78,8 @@ impl ProjectionTy { } } - pub fn self_type_parameter(&self) -> &Ty { - &self.substitution.interned()[0].assert_ty_ref(&Interner) + pub fn self_type_parameter(&self, interner: &Interner) -> &Ty { + &self.substitution.interned()[0].assert_ty_ref(interner) } fn trait_(&self, db: &dyn HirDatabase) -> TraitId { @@ -477,7 +477,7 @@ impl Ty { WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(proj), ty: _, - }) => proj.self_type_parameter() == self, + }) => proj.self_type_parameter(&Interner) == self, _ => false, }) .collect_vec(); 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( .. })) = &goal.value.goal { - if let TyKind::BoundVar(_) = projection_ty.self_type_parameter().kind(&Interner) { + if let TyKind::BoundVar(_) = projection_ty.self_type_parameter(&Interner).kind(&Interner) { // Hack: don't ask Chalk to normalize with an unknown self type, it'll say that's impossible return Some(Solution::Ambig(Guidance::Unknown)); } diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index 59aaa5560..240f9d456 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs @@ -552,7 +552,7 @@ pub(super) fn generic_predicate_to_inline_bound( Some(make_binders(rust_ir::InlineBound::TraitBound(trait_bound), pred.num_binders)) } WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => { - if projection_ty.self_type_parameter() != &self_ty_shifted_in { + if projection_ty.self_type_parameter(&Interner) != &self_ty_shifted_in { return None; } let trait_ = projection_ty.trait_(db); -- cgit v1.2.3 From d7546d8c2323adff53c8170c528e82a8131681c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Mon, 5 Apr 2021 17:38:37 +0300 Subject: Pass interner to TraitRef::self_type_parameter --- crates/hir_ty/src/display.rs | 31 ++++++++++++++++--------------- crates/hir_ty/src/lib.rs | 8 +++++--- crates/hir_ty/src/lower.rs | 3 ++- crates/hir_ty/src/traits/chalk/mapping.rs | 2 +- 4 files changed, 24 insertions(+), 20 deletions(-) (limited to 'crates/hir_ty/src') diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index 965476a05..1108e5a10 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -592,20 +592,21 @@ impl HirDisplay for Ty { } TypeParamProvenance::ArgumentImplTrait => { let substs = generics.type_params_subst(f.db); - let bounds = f - .db - .generic_predicates(id.parent) - .into_iter() - .map(|pred| pred.clone().subst(&substs)) - .filter(|wc| match &wc.skip_binders() { - WhereClause::Implemented(tr) => tr.self_type_parameter() == self, - WhereClause::AliasEq(AliasEq { - alias: AliasTy::Projection(proj), - ty: _, - }) => proj.self_type_parameter(&Interner) == self, - _ => false, - }) - .collect::>(); + let bounds = + f.db.generic_predicates(id.parent) + .into_iter() + .map(|pred| pred.clone().subst(&substs)) + .filter(|wc| match &wc.skip_binders() { + WhereClause::Implemented(tr) => { + tr.self_type_parameter(&Interner) == self + } + WhereClause::AliasEq(AliasEq { + alias: AliasTy::Projection(proj), + ty: _, + }) => proj.self_type_parameter(&Interner) == self, + _ => false, + }) + .collect::>(); write_bounds_like_dyn_trait_with_prefix("impl", &bounds, f)?; } } @@ -780,7 +781,7 @@ impl TraitRef { return write!(f, "{}", TYPE_HINT_TRUNCATION); } - self.self_type_parameter().hir_fmt(f)?; + self.self_type_parameter(&Interner).hir_fmt(f)?; if use_as { write!(f, " as ")?; } else { diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index 80dd7aaca..adfdcaa37 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs @@ -165,8 +165,8 @@ impl Binders { } impl TraitRef { - pub fn self_type_parameter(&self) -> &Ty { - &self.substitution.at(&Interner, 0).assert_ty_ref(&Interner) + pub fn self_type_parameter(&self, interner: &Interner) -> &Ty { + &self.substitution.at(interner, 0).assert_ty_ref(interner) } pub fn hir_trait_id(&self) -> TraitId { @@ -473,7 +473,9 @@ impl Ty { .into_iter() .map(|pred| pred.clone().subst(&substs)) .filter(|wc| match &wc.skip_binders() { - WhereClause::Implemented(tr) => tr.self_type_parameter() == self, + WhereClause::Implemented(tr) => { + tr.self_type_parameter(&Interner) == self + } WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(proj), ty: _, 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( for pred in resolver.where_predicates_in_scope() { for pred in ctx.lower_where_predicate(pred, false) { if let WhereClause::Implemented(tr) = &pred.skip_binders() { - traits_in_scope.push((tr.self_type_parameter().clone(), tr.hir_trait_id())); + traits_in_scope + .push((tr.self_type_parameter(&Interner).clone(), tr.hir_trait_id())); } let program_clause: chalk_ir::ProgramClause = pred.clone().to_chalk(db).cast(&Interner); diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index 240f9d456..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( let self_ty_shifted_in = self_ty.clone().shift_bound_vars(DebruijnIndex::ONE); match &pred.value { WhereClause::Implemented(trait_ref) => { - if trait_ref.self_type_parameter() != &self_ty_shifted_in { + if trait_ref.self_type_parameter(&Interner) != &self_ty_shifted_in { // we can only convert predicates back to type bounds if they // have the expected self type return None; -- cgit v1.2.3