Skip to content

Commit 013cc7d

Browse files
bors[bot]lnicola
andauthored
Merge #8344
8344: Pass interner to `ProjectionTy::self_type_parameter` and `TraitRef::self_type_parameter` r=flodiebold a=lnicola CC #8313 changelog skip Co-authored-by: Laurențiu Nicola <[email protected]>
2 parents fab1c06 + d7546d8 commit 013cc7d

File tree

5 files changed

+30
-26
lines changed

5 files changed

+30
-26
lines changed

crates/hir_ty/src/display.rs

+17-16
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ impl HirDisplay for ProjectionTy {
251251
}
252252

253253
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(
255255
f.db,
256256
f.max_size,
257257
f.omit_verbose_types,
@@ -592,20 +592,21 @@ impl HirDisplay for Ty {
592592
}
593593
TypeParamProvenance::ArgumentImplTrait => {
594594
let substs = generics.type_params_subst(f.db);
595-
let bounds = f
596-
.db
597-
.generic_predicates(id.parent)
598-
.into_iter()
599-
.map(|pred| pred.clone().subst(&substs))
600-
.filter(|wc| match &wc.skip_binders() {
601-
WhereClause::Implemented(tr) => tr.self_type_parameter() == self,
602-
WhereClause::AliasEq(AliasEq {
603-
alias: AliasTy::Projection(proj),
604-
ty: _,
605-
}) => proj.self_type_parameter() == self,
606-
_ => false,
607-
})
608-
.collect::<Vec<_>>();
595+
let bounds =
596+
f.db.generic_predicates(id.parent)
597+
.into_iter()
598+
.map(|pred| pred.clone().subst(&substs))
599+
.filter(|wc| match &wc.skip_binders() {
600+
WhereClause::Implemented(tr) => {
601+
tr.self_type_parameter(&Interner) == self
602+
}
603+
WhereClause::AliasEq(AliasEq {
604+
alias: AliasTy::Projection(proj),
605+
ty: _,
606+
}) => proj.self_type_parameter(&Interner) == self,
607+
_ => false,
608+
})
609+
.collect::<Vec<_>>();
609610
write_bounds_like_dyn_trait_with_prefix("impl", &bounds, f)?;
610611
}
611612
}
@@ -780,7 +781,7 @@ impl TraitRef {
780781
return write!(f, "{}", TYPE_HINT_TRUNCATION);
781782
}
782783

783-
self.self_type_parameter().hir_fmt(f)?;
784+
self.self_type_parameter(&Interner).hir_fmt(f)?;
784785
if use_as {
785786
write!(f, " as ")?;
786787
} else {

crates/hir_ty/src/lib.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ impl ProjectionTy {
7878
}
7979
}
8080

81-
pub fn self_type_parameter(&self) -> &Ty {
82-
&self.substitution.interned()[0].assert_ty_ref(&Interner)
81+
pub fn self_type_parameter(&self, interner: &Interner) -> &Ty {
82+
&self.substitution.interned()[0].assert_ty_ref(interner)
8383
}
8484

8585
fn trait_(&self, db: &dyn HirDatabase) -> TraitId {
@@ -165,8 +165,8 @@ impl<T: TypeWalk> Binders<T> {
165165
}
166166

167167
impl TraitRef {
168-
pub fn self_type_parameter(&self) -> &Ty {
169-
&self.substitution.at(&Interner, 0).assert_ty_ref(&Interner)
168+
pub fn self_type_parameter(&self, interner: &Interner) -> &Ty {
169+
&self.substitution.at(interner, 0).assert_ty_ref(interner)
170170
}
171171

172172
pub fn hir_trait_id(&self) -> TraitId {
@@ -473,11 +473,13 @@ impl Ty {
473473
.into_iter()
474474
.map(|pred| pred.clone().subst(&substs))
475475
.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+
}
477479
WhereClause::AliasEq(AliasEq {
478480
alias: AliasTy::Projection(proj),
479481
ty: _,
480-
}) => proj.self_type_parameter() == self,
482+
}) => proj.self_type_parameter(&Interner) == self,
481483
_ => false,
482484
})
483485
.collect_vec();

crates/hir_ty/src/lower.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,8 @@ pub(crate) fn trait_environment_query(
941941
for pred in resolver.where_predicates_in_scope() {
942942
for pred in ctx.lower_where_predicate(pred, false) {
943943
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()));
945946
}
946947
let program_clause: chalk_ir::ProgramClause<Interner> =
947948
pred.clone().to_chalk(db).cast(&Interner);

crates/hir_ty/src/traits.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub(crate) fn trait_solve_query(
8989
..
9090
})) = &goal.value.goal
9191
{
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) {
9393
// Hack: don't ask Chalk to normalize with an unknown self type, it'll say that's impossible
9494
return Some(Solution::Ambig(Guidance::Unknown));
9595
}

crates/hir_ty/src/traits/chalk/mapping.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ pub(super) fn generic_predicate_to_inline_bound(
539539
let self_ty_shifted_in = self_ty.clone().shift_bound_vars(DebruijnIndex::ONE);
540540
match &pred.value {
541541
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 {
543543
// we can only convert predicates back to type bounds if they
544544
// have the expected self type
545545
return None;
@@ -552,7 +552,7 @@ pub(super) fn generic_predicate_to_inline_bound(
552552
Some(make_binders(rust_ir::InlineBound::TraitBound(trait_bound), pred.num_binders))
553553
}
554554
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 {
556556
return None;
557557
}
558558
let trait_ = projection_ty.trait_(db);

0 commit comments

Comments
 (0)