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 <lnicola@dend.ro>
This commit is contained in:
bors[bot] 2021-04-05 15:47:09 +00:00 committed by GitHub
commit 013cc7dd8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 26 deletions

View File

@ -251,7 +251,7 @@ impl HirDisplay for ProjectionTy {
} }
let trait_ = f.db.trait_data(self.trait_(f.db)); 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.db,
f.max_size, f.max_size,
f.omit_verbose_types, f.omit_verbose_types,
@ -592,20 +592,21 @@ impl HirDisplay for Ty {
} }
TypeParamProvenance::ArgumentImplTrait => { TypeParamProvenance::ArgumentImplTrait => {
let substs = generics.type_params_subst(f.db); let substs = generics.type_params_subst(f.db);
let bounds = f let bounds =
.db f.db.generic_predicates(id.parent)
.generic_predicates(id.parent) .into_iter()
.into_iter() .map(|pred| pred.clone().subst(&substs))
.map(|pred| pred.clone().subst(&substs)) .filter(|wc| match &wc.skip_binders() {
.filter(|wc| match &wc.skip_binders() { WhereClause::Implemented(tr) => {
WhereClause::Implemented(tr) => tr.self_type_parameter() == self, tr.self_type_parameter(&Interner) == self
WhereClause::AliasEq(AliasEq { }
alias: AliasTy::Projection(proj), WhereClause::AliasEq(AliasEq {
ty: _, alias: AliasTy::Projection(proj),
}) => proj.self_type_parameter() == self, ty: _,
_ => false, }) => proj.self_type_parameter(&Interner) == self,
}) _ => false,
.collect::<Vec<_>>(); })
.collect::<Vec<_>>();
write_bounds_like_dyn_trait_with_prefix("impl", &bounds, f)?; write_bounds_like_dyn_trait_with_prefix("impl", &bounds, f)?;
} }
} }
@ -780,7 +781,7 @@ impl TraitRef {
return write!(f, "{}", TYPE_HINT_TRUNCATION); return write!(f, "{}", TYPE_HINT_TRUNCATION);
} }
self.self_type_parameter().hir_fmt(f)?; self.self_type_parameter(&Interner).hir_fmt(f)?;
if use_as { if use_as {
write!(f, " as ")?; write!(f, " as ")?;
} else { } else {

View File

@ -78,8 +78,8 @@ impl ProjectionTy {
} }
} }
pub fn self_type_parameter(&self) -> &Ty { pub fn self_type_parameter(&self, interner: &Interner) -> &Ty {
&self.substitution.interned()[0].assert_ty_ref(&Interner) &self.substitution.interned()[0].assert_ty_ref(interner)
} }
fn trait_(&self, db: &dyn HirDatabase) -> TraitId { fn trait_(&self, db: &dyn HirDatabase) -> TraitId {
@ -165,8 +165,8 @@ impl<T: TypeWalk> Binders<T> {
} }
impl TraitRef { impl TraitRef {
pub fn self_type_parameter(&self) -> &Ty { pub fn self_type_parameter(&self, interner: &Interner) -> &Ty {
&self.substitution.at(&Interner, 0).assert_ty_ref(&Interner) &self.substitution.at(interner, 0).assert_ty_ref(interner)
} }
pub fn hir_trait_id(&self) -> TraitId { pub fn hir_trait_id(&self) -> TraitId {
@ -473,11 +473,13 @@ impl Ty {
.into_iter() .into_iter()
.map(|pred| pred.clone().subst(&substs)) .map(|pred| pred.clone().subst(&substs))
.filter(|wc| match &wc.skip_binders() { .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 { WhereClause::AliasEq(AliasEq {
alias: AliasTy::Projection(proj), alias: AliasTy::Projection(proj),
ty: _, ty: _,
}) => proj.self_type_parameter() == self, }) => proj.self_type_parameter(&Interner) == self,
_ => false, _ => false,
}) })
.collect_vec(); .collect_vec();

View File

@ -941,7 +941,8 @@ pub(crate) fn trait_environment_query(
for pred in resolver.where_predicates_in_scope() { for pred in resolver.where_predicates_in_scope() {
for pred in ctx.lower_where_predicate(pred, false) { for pred in ctx.lower_where_predicate(pred, false) {
if let WhereClause::Implemented(tr) = &pred.skip_binders() { 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> = let program_clause: chalk_ir::ProgramClause<Interner> =
pred.clone().to_chalk(db).cast(&Interner); pred.clone().to_chalk(db).cast(&Interner);

View File

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

View File

@ -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); let self_ty_shifted_in = self_ty.clone().shift_bound_vars(DebruijnIndex::ONE);
match &pred.value { match &pred.value {
WhereClause::Implemented(trait_ref) => { 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 // we can only convert predicates back to type bounds if they
// have the expected self type // have the expected self type
return None; return None;
@ -552,7 +552,7 @@ pub(super) fn generic_predicate_to_inline_bound(
Some(make_binders(rust_ir::InlineBound::TraitBound(trait_bound), pred.num_binders)) Some(make_binders(rust_ir::InlineBound::TraitBound(trait_bound), pred.num_binders))
} }
WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => { 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; return None;
} }
let trait_ = projection_ty.trait_(db); let trait_ = projection_ty.trait_(db);