Skip to content

Pass interner to ProjectionTy::self_type_parameter and TraitRef::self_type_parameter #8344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions crates/hir_ty/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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() == self,
_ => false,
})
.collect::<Vec<_>>();
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::<Vec<_>>();
write_bounds_like_dyn_trait_with_prefix("impl", &bounds, f)?;
}
}
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 8 additions & 6 deletions crates/hir_ty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -165,8 +165,8 @@ impl<T: TypeWalk> Binders<T> {
}

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 {
Expand Down Expand Up @@ -473,11 +473,13 @@ 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: _,
}) => proj.self_type_parameter() == self,
}) => proj.self_type_parameter(&Interner) == self,
_ => false,
})
.collect_vec();
Expand Down
3 changes: 2 additions & 1 deletion crates/hir_ty/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Interner> =
pred.clone().to_chalk(db).cast(&Interner);
Expand Down
2 changes: 1 addition & 1 deletion crates/hir_ty/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
4 changes: 2 additions & 2 deletions crates/hir_ty/src/traits/chalk/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down